When I run this test:
[TestMethod, VerifyMocks]
public void TestMethod1()
{
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(global::System.Configuration.ConfigurationManager.ConnectionStrings["test"], null);
}
Assert.IsNull(global::System.Configuration.ConfigurationManager.ConnectionStrings["test"]);
}
I get this error:
Test method TestProject1.UnitTest3.TestMethod1 threw exception: TypeMock.TypeMockException:
*** Cannot return a value for ConnectionStringSettingsCollection.get_Item() because no value was set. use recorder.Return().
*** Note: Cannot mock types from mscorlib assembly..
However, this test:
[TestMethod, VerifyMocks]
public void TestMethod2()
{
global::System.Configuration.ConnectionStringSettingsCollection connectionStrings = RecorderManager.CreateMockedObject<global::System.Configuration.ConnectionStringSettingsCollection>(Constructor.Mocked, StrictFlags.AllMethods);
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(global::System.Configuration.ConfigurationManager.ConnectionStrings, connectionStrings);
recorder.ExpectAndReturn(connectionStrings["test"], null);
}
Assert.IsNull(global::System.Configuration.ConfigurationManager.ConnectionStrings["test"]);
}
it succedes.
What am I doing wrong?