|
From: Joselito D. M. <joe...@gm...> - 2006-11-03 20:31:08
|
Hello,
I am not sure whether to report this as a bug or just a gotcha.
Here is the code to reproduce the issue I'm talking about.
This is the class under test:
public class ServiceDependentClass
{
IService service = null;
public ServiceDependentClass(IService service)
{
this.service = service;
}
public int callService()
{
for (int i = 0; i < 3; i++ )
{
try
{
Console.WriteLine("Calling method [" + i + "]");
int result = service.doSomething("someParameter");
}
catch (Exception)
{
}
}
return 0;
}
}
This is the IService interface:
public interface IService
{
int doSomething(string someParameter);
}
This is the NUnit test code:
[TestFixture]
public class NMock2BugTest
{
[Test]
public void TestBug()
{
Mockery mocks = new Mockery();
IService mockService = mocks.NewMock<IService>();
ServiceDependentClass classUnderTest = new
ServiceDependentClass(mockService);
Expect.Once.On(mockService)
.Method("doSomething")
.With("someParameter")
.Will(Return.Value(0));
classUnderTest.callService();
mocks.VerifyAllExpectationsHaveBeenMet();
}
}
The problem with this is that I was expecting this test to fail
because of the "Expect.Once" call and the class under test actually
calls the service.doSomething("someParameter") 3 times. Instead, the
test actually passes when using NUnit because the try-catch(Exception)
of the class under test that surrounds the service.doSomething() call
consumes the "NMock2.Internal.ExpectationException: unexpected
invocation of service.doSomething("someParameter")".
Is this truly a bug or is this just something that users need to be aware of?
Thank you,
Joen Moreno
|