Fluent NHibernate 单元测试固定长度字符字段
我的单元测试失败了,我知道原因,但我不确定应该如何处理它。我有以下单元测试:
new PersistenceSpecification<OrderLine>(session)
.CheckProperty(x => x.Line, "1")
.VerifyTheMappings();
它失败并出现以下错误:
测试方法 CanCorrectlyMapOrderLine 引发异常: System.ApplicationException:对于属性“Line”,期望“System.String”类型的“1”,但得到“System.String”类型的“1”
这样做的原因是因为 x.Line 指向固定长度字符字段数据库(准确地说是 nchar(10)),当它插入数据时,它会用空格填充它。我应该在单元测试中指定末尾带有 9 个空格的“1”,还是应该在读入它时以某种方式修剪它?还有其他方法可以处理这个问题吗?
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 the 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终只是做了以下事情:
I ended up just doing the following with this: