Integration Test - initialise SiteContext object

Matthew Lee asked on August 20, 2014 02:01

I have written an integration test as below under Kentico v8.0.17

public class SubscriberControllerTest : IntegrationTests
    public void Setup()


    public void Should_Match_Value()
        var controller = new SubscriberController(newsletterSubscriptionRepository);
        controller.Request = new HttpRequestMessage();
        controller.Configuration = new HttpConfiguration();

        var response = controller.AddSubscriber(emailSubscriber);

        string value;
        response.TryGetContentValue<string>(out value);

        value.Should().Be("You have been successfully subscribed");

However, I got an object null reference error on this line.


When I looked into it, the underlying object SiteContext was not initialised. So, I put this in the Setup() function and the test could be run successfully.

SiteContext.CurrentSite = SiteInfoProvider.GetSiteInfo(1);

I am just wondering do I need to set up the SiteContext object like above or did I miss anything when setting up the integration test project?

   Please, sign in to be able to submit a new answer.