<TestFixture()> _
Public Class AddAuditPresenterTest
Dim mocks As MockRepository
Dim Dao As IAuditDao
Dim View As IAddAuditView
<SetUp()> Public Sub SetUp()
mocks = New MockRepository()
Dao = mocks.CreateMock(Of IAuditDao)()
View = mocks.CreateMock(Of IAddAuditView)()
End Sub
<Test()> Public Sub AddNewAudit()
Dim p As New AddAuditPresenter(View, Dao)
Dim a As New Audit
Dim s As New Section
a.Sections.Add(s)
s.FromAudit = a
'Using mocks.Record
Expect.Call(Dao.SaveOrUpdate(a)).Return(a)
' End Using
'Using mocks.Playback
mocks.ReplayAll()
p.Initview()
Dim newAudit As Audit = p.AddAudit(TestGlobals.DepartmentId)
Assert.IsNotNull(a)
'End Using
End Sub
End Class
it fails with this error:
Starting the MbUnit Test Execution
Exploring AuditMaker.UnitTests, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=885d1150065cd4b3
MbUnit 1.0.2700.29885 Addin
Found 1 tests
AddAuditPresenter: AddAudit
[failure] AddAuditPresenterTest.SetUp.AddNewAudit
TestCase 'AddAuditPresenterTest.SetUp.AddNewAudit'
failed: IDao`2.SaveOrUpdate(UniSA.Flc.AuditMaker.Core.Domain.Audit);
Expected #0, Actual #1.
IDao`2.SaveOrUpdate(UniSA.Flc.AuditMaker.Core.Domain.Audit); Expected
#1, Actual #0.
Rhino.Mocks.Exceptions.ExpectationViolationException
Message: IDao`2.SaveOrUpdate(UniSA.Flc.AuditMaker.Core.Domain.Audit);
Expected #0, Actual #1.
IDao`2.SaveOrUpdate(UniSA.Flc.AuditMaker.Core.Domain.Audit); Expected
#1, Actual #0.
Source: Rhino.Mocks
StackTrace:
at
Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.DoGetRecordedExpectation(IInvocation
invocation, Object proxy, MethodInfo method, Object[] args)
at
Rhino.Mocks.MethodRecorders.MethodRecorderBase.GetRecordedExpectation(IInvocation
invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation
invocation, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation
invocation, MethodInfo method, Object[] args)
at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation,
Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation
invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at IAuditDaoProxye65fd9806bd5404280b0f0edf57766a8.SaveOrUpdate(Audit
entity)
D:\Visual Studio Projects\2007\AuditMaker\Main\Source\Code\AuditMaker
\AuditMaker.Presenters\AddAuditPresenter.vb(38,0): at
UniSA.Flc.AuditMaker.Presenters.AddAuditPresenter.AddAudit(Int32
departmentId)
D:\Visual Studio Projects\2007\AuditMaker\Main\Source\Code\AuditMaker
\UnitTests\Presenters\AddAuditPresenterTest.vb(63,0): at
AuditMaker.UnitTests.AddAuditPresenterTest.AddNewAudit()
I don't understand why it says it says it found an unexpected
"IDao`2.SaveOrUpdate", and also it didn't find a "IDao`2.SaveOrUpdate"
that it was expecting.
I usually use the Using/End Using code, but it also fails with the old-
fashioned syntax as shown above.
-dave
The problem was caused by the expected method returning a different
result.
Adding the IgnoreArguments() method on the end of the Expect.Call
solved this.
Next time what I would like is a bit more detail as to why an expected
method wasn't matched.. If it were possible to indicate that the
arguments didn't match that would be a lot more useful.
thanks,
-dave
-dave
________________________________
Interesting, but (having run into the same issue as David a few times)
for the beginning, it would probably suffice to just indicate that
(and which) argument instance(s) differ.
Fabian