How would you test this scenario?
I've just started looking into NHibernate and having my first bash at TDD. So far I've really enjoyed it and have been using fluent-Nhibernate for my mapping of the classes.
However I seem to be hitting a dead end when it comes to using the VerifyTheMappings method on PersistenceSpecification.
Essentially I have two classes, Recipient and RecipientList. The RecipientList class has a mapping to the Recipient with a fluent "HasMany" relationship:
public class RecipientListMap : ClassMap
{
public RecipientListMap()
{
Id(x => x.ID);
Map(x => x.ApplicationID);
Map(x => x.Name);
Map(x => x.IsDeleted);
HasMany(x => x.Recipients).WithKeyColumn("RecipientListID").AsList().LazyLoad();
}
}
However when I use the following code in my test:
private IList _recipients = new List()
{
new Recipient { FirstName = "Joe", LastName = "Bloggs", Email = "
[email protected]", IsDeleted = false },
new Recipient { FirstName = "John", LastName = "Doe", Email = "
[email protected]", IsDeleted = false },
new Recipient { FirstName = "Jane", LastName = "Smith", Email = "
[email protected]", IsDeleted = false }
};
[Test]
public void Can_Add_RecipientList_To_Database()
{
new PersistenceSpecification(Session)
.CheckProperty(x => x.Name, "My List")
.CheckProperty(x => x.Columns, "My columns")
.CheckProperty(x => x.IsDeleted, false)
.CheckProperty(x => x.ApplicationID, Guid.NewGuid())
.CheckProperty(x => x.Recipients, _recipients)
.VerifyTheMappings();
}
The following error occurs:
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'
I can see that the error is because I am passing in a List and the list returned is a PersistentGenericBag, therefore throwing an error. I don't get how you are suppose test this though if you can't just pass in an IList?
Any help would be appreciated.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)