views:

16

answers:

1

I'm working on tests for my Fluent NHibernate mappings, and my question is - is it a good idea to test for id value if Id column is represented by identity in Sql Server? Since it changes after each insert, how can I possibly do it?

            new PersistenceSpecification<Product>(session)
               .CheckProperty(p => p.Id, 1)
               .CheckProperty(p => p.Name, "Awesome hat")
               .CheckProperty(p => p.Price, 9.90)
               .CheckList(p => p.StoresStockedIn, new List<Store>())
               .VerifyTheMappings();
+1  A: 

I don't think it adds any value to the test. The PersistenceSpecification does an insert then selects the object by identifier. If the identifier isn't generated then the test will fail. You can easily verify this by temporarily changing the mapping to assigned or removing the identity setting on the database column.

Jamie Ide