I’m looking for a way to unit test all the DTOs I’m sending back over my WCF interfaces. I want to avoid run-time errors like the following:
System.Runtime.Serialization.InvalidDataContractException
No set method for property 'Bar' in type 'Foo'.
For example in the following I would want the unit test to catch the above exception.
[DataContract]
public class Foo
{
[DataMember]
public decimal Bar { get { return 0; } }
}
There is a useful helper in this SO article that’ll help you to test serialization deserialization using the NetDataContractSerlializer. You could call this helper from your unit tests.
Has anyone created a DataContract testing tool?