title: Fluent Nhibernate Nunit Test Error
body: <p>I am trying to learn Nhibernate using fluent nhibernate mappings and i have created a small test app. Below is the code:</p>
  
  <p>UserClass:</p>
  
  <pre><code>public class User
  {
      public string UserName { get; set; }
      public string Password { get; set; }
      public string Role { get; set; }
      public string Email { get; set; }
      public DateTime JoinDate { get; set; }
  }
  </code></pre>
  
  <p>User Map Class:</p>
  
  <pre><code>public class UserMapping: ClassMap&lt;User&gt;
  {
      public UserMapping()
      {
          WithTable("UserT");
          Not.LazyLoad();
          Id(u =&gt; u.UserName);
          Map(u =&gt; u.Password);
          Map(u =&gt; u.Role);
          Map(u =&gt; u.Email);
          Map(u =&gt; u.JoinDate);
  
      }
  }
  </code></pre>
  
  <p>DAL User Class:</p>
  
  <pre><code>public class DALUser
  {
  
      public User GetUserByUserName(string userName)
      {
          ISessionFactory sessionFactory = Fluently.Configure()
              .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c =&gt; c.Server("ServerName").Database("DBName").TrustedConnection()))
                  .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;UserMapping&gt;()).BuildSessionFactory();
  
          ISession session = sessionFactory.OpenSession();
          return session.Get&lt;User&gt;(userName);
      }
  
  }
  </code></pre>
  
  <p>Nunit Test Class:</p>
  
  <pre><code>[TestFixture]
  public class UserTest
  {
      [Test]
      public void CanGetUserByUserName()
      {
          DALUser user1 = new DALUser();
          Assert.AreEqual("testUser", user1.GetUserByUserName("testUser").UserName);
      }
  
  }
  </code></pre>
  
  <p>When i try to run the test class i get the following error :Object reference not set to an instance of an object. 
  I have placed a breakpoint in the GetUserByUserName method and noticed that its returning a null user. But i am not able to figure out why this is happening. Can anyone help me?</p>