r3plica
r3plica

Reputation: 13367

nunit and web.config appSettings

I am really new to testing, but I have an existing project that I want to test. I have set up my test class like this:

[TestFixture]
public class PiiikProviderTest
{
    public IList<GroupRequestModel> _groups;
    public IPiiikProvider _pickProvider;

    [OneTimeSetUp]
    public void Setup()
    {
        var config = new PiiiCKConfig();
        var factory = new JsonFactory();
        var t = config.DocumentDbEnpointUrl;
        var settingProvider = new SettingProvider(config);

        _pickProvider = new PiiikProvider(settingProvider);
        _groups = factory.Groups();
    }

    [Test]
    public void ScoreShouldBe130()
    {

        // Assemble
        var products = new List<JObject>();
        var product = JObject.Parse("{'gtin': '8714574593609',    'model': 'EOS 6D',    'title': 'Canon EOS 6D Digital SLR Camera, HD 1080p, 20.2MP, GPS, 3\" LCD Screen, Body Only',    'shortTitle': 'Canon EOS 6D Black',    'image': 'http://piiick.blob.core.windows.net/images/Canon-EOS-6D-Black-8714574593609.png',    'weight': 'Heavy',    'size': 'Large',    'changableLens': 'Yes',    'action': 'No',    'sharing': 'Yes',    'mostlyManual': 'Yes',    'colour': 'Black',    'quality': 'Pro',    'type': 'DLSR',    'superzoom': 'No',    'video': 'HD',    'fastBurst': 'No',    'innovation': 'No',    'lowLight': 'Yes',    'brand': 'Canon',    'newestModels': 'No',    'focusTracking': 'No',    'wiFi': 'Yes',    'style': 'Traditional',    'categoryId': 1,    'id': '6cf8e9dd-4e7e-410e-b99e-c01005eb3f56'}");
        products.Add(product);

        // Act
        var response = _pickProvider.Score(_groups, products);
        var result = int.Parse(response[0].SelectToken("importance").ToString());

        // Asset
        Assert.That(result, Is.EqualTo(130));
    }

    [OneTimeTearDown]
    public void TearDown()
    {
        _groups = null;
        _pickProvider = null;
    }
}

The problem is, the config.DocumentDbEnpointUrl is always null. I have tried many things, first I referenced the Api project that actually contains the web.config file. That didn't work.

So I then added an existing item as a link to the test project and it still didn't work.

So then I created a new web.config file in the test project and copied the app settings across that that still did not work.

Does anyone know what I need to do?

Upvotes: 2

Views: 1575

Answers (1)

Nkosi
Nkosi

Reputation: 247088

You need to copy the appSettings from the web.config file into the app.config of the test project.

When running, the test project, it will get its configuration from its local configuration {app name}.config, which is what the app.config file will be transformed to when deployed/run

Upvotes: 3

Related Questions