mercredi 16 décembre 2015

why Nunit does not load configuration file of the web service I test?

I'm trying to test a web service that return FaultException here the method That I should test:

public string MigrateAccountToAD(string _SourceId, ADConnector.AccountAD _Contact)
{
    if (!string.IsNullOrWhiteSpace(_SourceId))
    {
        //to stuff
    }
    else
    {
        throw new FaultException(new FaultReason(string.Format(ConfigurationManager.AppSettings["stringNullOrEmpty"], "SourceId")), new FaultCode("MigrateAccountToAD failed"));
    }
}

when I debug I can see that the ConfigurationManager.AppSettings["stringNullOrEmpty"] is null, that mean that it cannot access this file.

the test I run

[Test]       
public void ExpectAnException()
{ 
    string _sourceID = "111";
    AccountAD Adconnector = new AccountAD();
    Mock<IIDMgtDataLayer> _mockDataAccess = new Mock<IIDMgtDataLayer>();

     var _business = new Migration.Business.BusinessLayer(_mockDataAccess.Object);
     var ex = Assert.Throws<FaultException>(() => _business.MigrateAccountToAD("", Adconnector));
     Assert.IsTrue(ex.Message.Contains("Provided SourceId could not be null or empty"));
}

What I'm missing ?

Aucun commentaire:

Enregistrer un commentaire