最小起订量 - 使用 MockRepository.Verify() 与时间

Moq - Using MockRepository.Verify() With Times

我想看看是否可以在模拟 属性 的设置中指定一个 Times 枚举值,然后可以通过 MockRepository.Verify() 方法在我的 AAA 式测试的断言块。我当前的代码如下所示:

        // Arrange
        var repository = new MockRepository(MockBehavior.Default);

        var mockLogin = repository.Create<Login>();
        mockLogin.SetupProperty(d => d.LoginID, 1515254);

        var mockIApplicationEventLogService = repository.Create<IApplicationEventLogService>();
        mockIApplicationEventLogService.Setup(d => d.InsertApplicationEventLog(It.IsAny<ApplicationEventLog>())).Verifiable();

        var mockILoginResetFailedService = repository.Create<ILoginResetFailedService>();
        mockILoginResetFailedService.Setup(d => d.GetLoginResetFailedByLoginID(It.IsAny<int>())).Returns((LoginResetFailed)null);

        var mockApplicationEventLog = repository.Create<ApplicationEventLog>();
        mockApplicationEventLog.SetupAllProperties();

        var LoginWorkflowService = new LoginWorkflowService()
        {
            ApplicationEventLogService = mockIApplicationEventLogService.Object,
            ApplicationEventLog = mockApplicationEventLog.Object,
            LoginResetFailedService = mockILoginResetFailedService.Object
        };

        // Act 
        var result = LoginWorkflowService.CheckLoginResetFailuresLock(mockLogin.Object, It.IsAny<Guid>(), It.IsAny<SecurityPolicy_Aggregate>(), It.IsAny<string>(), It.IsAny<string>());

        // Assert
        result.Should().BeTrue();
        mockIApplicationEventLogService.Verify(d => d.InsertApplicationEventLog(It.IsAny<ApplicationEventLog>()), Times.Never);

我希望能够做的是在最后调用 repository.Verify(),但是使用我当前的代码,Verify() 调用将期望 InsertApplicationEventLog 在我期望的时候被调用它从未被调用过。我已经尝试将 Times.Never 传递到 mockIApplicationEventLogService 的设置方法中,但似乎没有方法覆盖它。如果我的存储库中有永远不应该调用的模拟,我是否仅限于单独的 Verify() 调用,或者是否有解决此问题的方法?

看来正如 Nkosi 所说,目前无法执行此操作。在以下 URL:

有一个请求

https://github.com/moq/moq4/issues/373