This is the code I'm using:
[TestMethod]
public
void
TestMethod1()
{
// Arrange
var appSettings =
new
NameValueCollection { {
"test1"
,
"one"
} };
Mock.Arrange(() => ConfigurationManager.AppSettings)
.Returns(appSettings)
.MustBeCalled();
// Act
var test1 = ConfigurationManager.AppSettings[
"test1"
];
// Assert
Assert.IsTrue(Mock.IsProfilerEnabled);
Assert.AreEqual(
"one"
, test1);
}
This is the error I receive:
Failed TestMethod1 JustMockTest Assert.AreEqual failed. Expected:<one>. Actual:<(null)>.
5 Answers, 1 is accepted
Thanks again for sending the issue. However, i found that it’s happening in MSTest only. I did the same test using NUnit and it passed. Therefore, it looks like MsTest is intercepting the ConfigruationManager.AppSettings for which JM can’t intercept it; as it has already fired the OnJITCompilationStarted event.
I have further attached my test project to let you have a look. Here i have used TestDrvien.Net RTM as runner.
Kind Regards,
Mehfuz
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

What is the recommended test tool to use for JustMock?
btw, so far I'm really liking JustMock. It has solved many problems we've had with our testing and has allowed us to drastically increase code coverage!
- j
Thanks again for the prompt reply. Honestly, there is no specific recommendation for JustMock but in terms of being light-weight and supporting wide variety of test runners I personally recommend NUnit with the Should library (available in NuGet). Following that, the second choice could be XUnit.
It's great to hear that you are enjoying the product.
Kind Regards,
Mehfuz
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Does this problem still exist with MSTest? Any fixes?
Thanks,
Murugesh.
Thanks again for contacting us.
However, as we have shown in the example its because of MSTest accessing the ConfigurationManger.AppSettings before JustMock thus raises the OnJITCompilationStarted event and prevents JM from intercepting it.
However, I tried the same test with VS2011 and it worked perfectly. The issue so far seems to be resolved in VS2011.
Kind Regards,
Mehfuz
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>