Fluent NHibernate Unit Testing fixed length character fields
I have a unit test that is failing and I know why but I'm not sure how I should be handling it. I have th开发者_开发技巧e following unit test:
new PersistenceSpecification<OrderLine>(session)
.CheckProperty(x => x.Line, "1")
.VerifyTheMappings();
It is failing with the following error:
Test method CanCorrectlyMapOrderLine threw exception: System.ApplicationException: For property 'Line' expected '1' of type 'System.String' but got '1 ' of type 'System.String'
The reason it's doing this is because x.Line points to a fixed length character field in the database (nchar(10) to be exact) and when it inserts the data it pads it with spaces. Should I be specifying "1" with 9 spaces at the end in my unit tests or should I be trimming this somehow when I read it in? Is there another way to handle this?
I ended up just doing the following with this:
new PersistenceSpecification<OrderLine>(session)
.CheckProperty(x => x.Line, "1".PadRight(10, ' '))
.VerifyTheMappings();
精彩评论