views:

17

answers:

1

I'm trying to test validation that I've setup for my wcf service. What's the best way to do it?

[ServiceContract]
[ValidationBehavior]
public interface IXmlSchemaService
{

    [OperationContract(Action = "SubmitSchema")]
    [return: MessageParameter(Name = "SubmitSchemaReturn")]
    [FaultContract(typeof(ValidationFault))]
    JobData SubmitSchema([XmlStringValidator] string xmlString);
}

XmlStringValidator is a custom validator I've created. Ideally I want something like:

XmlSchemaService service = new XmlSchemaService();
service.SubmitSchema();

But in this case, validation isn't called.

A: 

By definition, this sort of test is an integration test, not a unit test. The VAB validation will only take place if the service operation is invoked via the WCF pipeline.

While you could perhaps force your calls through the WCF pipeline without creating a client proxy, wouldn't it make more sense to test this from a client proxy in order to ensure that the client is seeing exactly the fault you wish to publish from your service when the validation fails?

Nicole Calinoiu