0

我有一个使用 Rhino Mocks 测试的方法。当我自己测试这个方法时,它通过了,但是当测试多个方法时,它失败了。我认为这是因为我没有正确地破坏某些东西。下面是我创建我的 ObjectFactory 的设置代码。

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

这是其中一个单元测试的示例。

    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));

其他测试类似,只是改变返回值来影响逻辑路径。如果我一次运行它们,它们都会通过,但如果我一次运行它们,它们都会失败。

4

0 回答 0