这看起来很简单,但我似乎无法让它工作。我想对控制器的分配操作进行单元测试。它需要一个 IEnumerable(Of Integer) 来表示要分配的所有对象的 ID。
这是我编写的代码,Do 语句出现错误(我从 Ayende 的博客中复制了代码http://ayende.com/blog/3397/rhino-mocks-3-5-a-feature -为无缝做而感到自豪)。
<Test()> _
Public Sub Assign_Post_Should_Assign_All_Audits_Provided()
Dim auditsToAssign As IEnumerable(Of HvacAudit) = HvacAuditsGenerator.GenerateAudits() _
.Unassigned()
Dim auditIDs As IEnumerable(Of Integer) = auditsToAssign.Select(Function(audit, index) audit.HvacAuditID)
Dim hvacAuditRepo As IHvacAuditRepository = MockRepository.GenerateMock(Of IHvacAuditRepository)()
hvacAuditRepo.Stub(Sub(repo) repo.GetAuditByID(1)) _
.Do(Function(invocation) invocation.ReturnValue = auditsToAssign.Single(Function(audit) audit.HvacAuditID = invocation.Arguments(0)))
Dim controller As New HvacAuditController(hvacAuditRepo)
Dim r As ViewResult = controller.Assign(auditIDs).AssertViewRendered()
r.AssertAssignedAuditCount(auditsToAssign.Count)
auditsToAssign.AssertAreAssigned()
hvacAuditRepo.AssertWasCalled(Sub(h) h.SaveChanges())
End Sub