【问题标题】:Unit tests to catch InvalidDataContractException in WCF在 WCF 中捕获 InvalidDataContractException 的单元测试
【发布时间】:2012-04-03 13:31:05
【问题描述】:

我正在寻找一种方法来对通过 WCF 接口发回的所有 DTO 进行单元测试。我想避免如下运行时错误:

System.Runtime.Serialization.InvalidDataContractException 
No set method for property 'Bar' in type 'Foo'.

例如,在下面我希望单元测试能够捕获上述异常。

[DataContract]
public class Foo
{
    [DataMember]
    public decimal Bar { get { return 0; } }
}

【问题讨论】:

标签: c# wcf unit-testing serialization


【解决方案1】:

这篇 SO 文章中有一个有用的帮助程序,可以帮助您使用 NetDataContractSerlializer 测试序列化反序列化。你可以从你的单元测试中调用这个助手。

Has anyone created a DataContract testing tool?

【讨论】:

  • 这就是我要找的。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-02
  • 1970-01-01
  • 2011-09-10
相关资源
最近更新 更多