Rhino Mocks assert method is called once

268 views Asked by At

I have a method that I am testing using Rhino Mocks. When i test this method by itself, it passes, but when multiple methods are being tested, it fails. I assume this is because I am not destroying something correctly. Below is my setup code for creating my ObjectFactory.

public void Setup()
    {
        ObjectFactory.Initialize(x =>
        {
            x.For<ISecurityManager>().Use<SecurityManager>();
            x.For<IManager>().Use<Manager>();
            x.For<IWorkflowManager>().Use<WorkflowManager>();
        });
    }

Here is an example of one of the unit tests.

    var mockIWorkflowManager = MockRepository.GenerateMock<IWorkflowManager>();
    mockIWorkflowManager.Stub(d => d.SendCompletedEmailWithComments(Arg<WorkOrder>.Is.Anything, Arg<string>.Is.Anything));
    ObjectFactory.Inject(typeof(IWorkflowManager), mockIWorkflowManager);

    SubmitAction action = new SubmitAction();
    action.SendNotifyEmail("toUser", new WorkOrder(), "currentUser", new StepAction { Name = "with comments" });

    mockIWorkflowManager.AssertWasCalled(x => x.SendCompletedEmailWithComments(Arg<WorkOrder>.Is.Anything, Arg<string>.Matches(y => y == "toUser")));
    mockIWorkflowManager.AssertWasNotCalled(x => x.SendNotifyEmail(Arg<string>.Is.Anything, Arg<WorkOrder>.Is.Anything, Arg<string>.Is.Anything));

the other tests are similar, just changing return values to affect logic path. If I run them one at a time, they all pass, but if I run them all at once, they all fail.

0

There are 0 answers