Search code examples
c#justmock

Mocking ConfigurationManager.AppSettings with JustMock


Following the directions at: http://www.telerik.com/help/justmock/advanced-usage-static-mocking.html

I'm unsuccessful in mocking ConfigurationManager.AppSettings. Here's the code I'm using...

[TestMethod]
public void my_test()
{
    // Arrange
    var appSettings = new NameValueCollection {
        { "test1", "one" }
    };

    Mock.Arrange(() => ConfigurationManager.AppSettings)
        .Returns(appSettings)
        .MustBeCalled();

    // Act
    var test1 = ConfigurationManager.AppSettings["test1"];

    // Assert
    Assert.AreEqual("one", test1);
}

This is the error I receive.

Assert.AreEqual failed. Expected:. Actual:<(null)>.

Is it possible to mock this object?

[edit] I'm also using the Trial.


Solution

  • source: http://www.telerik.com/community/forums/justmock/general-discussions/problems-mocking-the-configurationmanager-appsettings.aspx

    Official response is, this appears to be an issue with MSTest only.