I have a set of tests in a test class, 2 of which contain a call to a method that accesses a database. The first test mocks the method call. The second test does not mock the method call ( I really want to access the database with this test).
I set up and verify my mock objects per test (i.e. not in the [SetUp ] method)
It is the second test that I am interested in here. If I run all the tests (i.e., in Nunit I select the test class node), the non-mocked method throws a TypeMock.VerifyException. If I select the individual test and run it, the non-mocked class executes as expected.
Is there a way to switch between mocked and non-mocked code for a method call?
I've tried
this._IsMockingOn=false;
if (this._IsMockingOn)
{
MockManager.Init();
Mock MockMyObject = MockManager.Mock(typeof(MyObject));
MockMyObject.ExpectAndReturn("MyMethod",MyReturn).Args(MyArg);
}
//Run tests
if(this._IsMockingOn)
{
MockManager.Verify();
}
This code appears in other tests with
this._IsMockingOn=true
;
I am using Nunit and TestDrive.NET.
TIA