2010-07-06 4 views
0

안녕하세요 저는 실행시 유창한 Nhibernate에 대한 단위 테스트를 작성하고 있습니다. isloation 테스트가 통과하지만 여러 테스트를 실행할 때. 또는 'System.Int32'유형의 '1'이면서 'System.Int32'유형의 '2'를 가져오고 'System.Int32'유형의 'Id'가 필요합니다.Fluent Nhibernate System.ApplicationException : 'Id'에 대해 'System.Int32'유형의 '1'이 필요하지만 'System.Int32'유형의 '2'가 있습니다.

[TextFixture] 공공 무효 Can_Correctly_Map_Entity() {

new PersistenceSpecification<UserProfile>(Session) 
     .CheckProperty(c => c.Id, 1) 
     .CheckProperty(c => c.UserName, "user") 
     .CheckProperty(c => c.Address1, "Address1") 
     .CheckProperty(c => c.Address2, "Address2") 

}

여기 Fluent Nhibernate System.ApplicationException : For property 'Id' expected '1' of type 'System.Int32' but got '2' of type 'System.Int32'을 이해하는 것 같다 솔루션을 얻었으나, 설명으로 이것을 사용하는 방법 임 확실하지가

답변

0

모호 너는 기억 속에 시험하고 있니? y 데이터베이스 또는 실제 데이터베이스? 나는 매핑을 테스트하기 위해서만이 테스트를 격리 할 수 ​​있도록 메모리 내 데이터베이스를 사용하여 매핑을 테스트 할 것을 제안합니다. 메모리 내 데이터베이스를 사용하는 경우 FluentConfiguration을 [TestInitialize] (MSTest) 또는 [SetUp] (NUnit) 메서드에 배치하면 매번 처음부터 db가 만들어집니다.

[TestInitialize] 
public void PersistenceSpecificationTest() 
{ 
    var cfg = Fluently.Configure() 
     .Database(SQLiteConfiguration.Standard.InMemory().UseReflectionOptimizer()) 
     .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserProfile>()) 
     .BuildConfiguration(); 

    _session = cfg.BuildSessionFactory().OpenSession(); 
    new SchemaExport(cfg).Execute(false, true, false, _session.Connection, null); 
} 

그런 다음 테스트가 잘 실행할 때마다 작동합니다 : 예를 들면 다음과 같습니다의 당신은 System.Data.SQLite DLL과 함께,이 시나리오에서 SQLite는을 사용해야합니다

[TestMethod] 
pulic void CanMapUserProfile() 
{ 
    new PersistenceSpecification<UserProfile>(_session)  
     .CheckProperty(c => c.Id, 1)  
     .CheckProperty(c => c.UserName, "user")  
     .CheckProperty(c => c.Address1, "Address1")  
     .CheckProperty(c => c.Address2, "Address2") 
} 

을, 여기에서 찾으실 수 있습니다 : http://sqlite.phxsoftware.com/

희망이 있습니다.