我需要断言一个基WorkItem
被传递一次给一个方法,而一个派生SendEmailWorkItem
被传递一次。
repo = new Mock<IWorkItemRepository>();
repo.Setup(x => x.Add(It.IsAny<WorkItem>())).Verifiable();
repo.Setup(x => x.Add(It.Is<SendEmailWorkItem>(wi => wi.ResponsibleId == responsibleGuid))).Verifiable();
Moq 表示第一个期望发生两次,第二个期望发生 0 次。我知道发生这种情况是因为这些类型位于相同的继承层次结构中。(以下断言采用 MSpec 语法)
It should_add_new_claim_workitem = () => repo.Verify(x => x.Add(MockIt.IsAny<WorkItem>()), Times.Once());
It should_add_security_service_notification_workitem_with_same_responsible_as_new_claim = () => repo.Verify(x => x.Add(MockIt.Is<SendEmailWorkItem>(wi => wi.ResponsibleId == responsibleGuid)), Times.Once());
如何根据类型限制期望?