Jezz Santos - 114 - Mar 30, 2014

Automating integration tests, and test environments.
My ServiceStack web service does quite a bit of start-up stuff that persists data to a data store, which I am blowing away every test.

Is it possible to automate the recycling of the AppHost?, without recycling the IIS/IISEXPRESS that it is running within?

In other words, can I do something programmatic that forces the AppHost to call Init() again?

Just calling AppHost.init() fails of course.

Stephen Brannan:

This is just a guess but it looks like you can set ServiceStackHost.Instance to null and then call Init to reset ServiceStack from within your app host since the setter on Instance is protected.

You should just need to call appHost.Dispose(); you’d normally do this on TearDown of the test fixture, e.g: https://github.com/ServiceStack/ServiceStack/wiki/Testing#test-setup

Jezz Santos:

Thanks Mythz,
Just one wrinkle, my integration tests are calling the web services over the wire.

Ideally, I’d like a solution that can be invoked remotely (say from a testing client to a test endpoint on the web service itself), which is called from the testing framework (in a separate process).

This seems to work as a REST method:

        public ResetWebRoleResponse Get(ResetWebRole request)
        {
            // Clear existing instance
            if (ServiceStackHost.Instance != null)
            {
                ServiceStackHost.Instance.Dispose();
            }

            // Initialize a new instance
            new AppHost().Init();

            this.Response.StatusCode = (int)HttpStatusCode.OK;
            this.Response.End();

            return null;
        }

ok cool, yeah that should work as well.

Jezz Santos:

Awesome, thanks for the affirmation.