code_junkie

How to test fluent-NHibernate's PersistenceSpecification.VerifyTheMappings with lists and relational objects?

Nov 12th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public class RecipientListMap : ClassMap<RecipientList>
  2. {
  3.  
  4. public RecipientListMap()
  5. {
  6. Id(x => x.ID);
  7. Map(x => x.ApplicationID);
  8. Map(x => x.Name);
  9. Map(x => x.IsDeleted);
  10. HasMany<Recipient>(x => x.Recipients).WithKeyColumn("RecipientListID").AsList().LazyLoad();
  11. }
  12.  
  13. }
  14.  
  15. private IList<Recipient> _recipients = new List<Recipient>()
  16. {
  17. new Recipient { FirstName = "Joe", LastName = "Bloggs", Email = "[email protected]", IsDeleted = false },
  18. new Recipient { FirstName = "John", LastName = "Doe", Email = "[email protected]", IsDeleted = false },
  19. new Recipient { FirstName = "Jane", LastName = "Smith", Email = "[email protected]", IsDeleted = false }
  20. };
  21.  
  22. [Test]
  23. public void Can_Add_RecipientList_To_Database()
  24. {
  25. new PersistenceSpecification<RecipientList>(Session)
  26. .CheckProperty(x => x.Name, "My List")
  27. .CheckProperty(x => x.Columns, "My columns")
  28. .CheckProperty(x => x.IsDeleted, false)
  29. .CheckProperty(x => x.ApplicationID, Guid.NewGuid())
  30. .CheckProperty(x => x.Recipients, _recipients)
  31. .VerifyTheMappings();
  32. }
  33.  
  34. failed: System.ApplicationException : Expected 'System.Collections.Generic.List`1[Project.Data.Domains.Recipients.Recipient]' but got 'NHibernate.Collection.Generic.PersistentGenericBag`1[Project.Data.Domains.Recipients.Recipient]' for Property 'Recipients'
Add Comment
Please, Sign In to add comment