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

[TestClass]
public class SubscriberControllerTest : IntegrationTests
{       
    [TestInitialize]
    public void Setup()
    {     

    }

    [TestMethod]
    public void Should_Match_Value()
    {
        SubscriberInfoProvider.EmailExists("email@address.com");
        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.

SubscriberInfoProvider.EmailExists("email@address.com");

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.