ServiceStack - Check for WSDL changes in a unit test

Viewed 37

We want a unit test which fails if the WSDL hast changed.

Possible logic: Generate a new WSDL and compare that with the old one from the metadata page stored in a file next to the unit test.

Question: Is that possible? If yes, how can we generate the new wsdl in a unit test?

We use version 5.11

1 Answers

ServiceStack's SOAP Support only supports ASP.NET Framework hosts which precludes it from running in an integration test which are run in a HttpListener Self Host, but your mileage may vary and may work in your case.

Here's a quick integration test example which checks the WSDL for a SOAP compatible ServiceStack Service:

[DataContract]
public class Hello : IReturn<HelloResponse>
{
    [DataMember]
    public string Name { get; set; }
}

[DataContract]
public class HelloResponse
{
    [DataMember]
    public string Result { get; set; }
}

class MyServices : Service
{
    public object Any(Hello request) => 
        new HelloResponse { Result = $"Hello, {request.Name}!" };
}

public class AppHost : AppSelfHostBase
{
    public AppHost() : base("MyApp Tests", typeof(MyServices).Assembly) {}

    public override void Configure(Container container)
    {
        Plugins.Add(new SoapFormat());
    }
}

The integration test then just does a GET request to the /soap12 to retrieve its WSDL:

[TestFixture]
public class Tests
{
    const string BaseUrl = "http://localhost:20000/";
    ServiceStackHost appHost;

    [OneTimeSetUp]
    public void OneTimeSetUp() => appHost = new AppHost()
        .Init()
        .Start(BaseUrl);

    [OneTimeTearDown]
    public void OneTimeTearDown() => appHost.Dispose();

    [Test]
    public void Check_wsdl()
    {
        var wsdl = BaseUrl.CombineWith("soap12").GetJsonFromUrl();
        wsdl.Print();
    }
}

If the self-host doesn't work, you would need to test it against a running IIS/ASP.NET Host to fetch its WSDL.

Related