lundi 29 décembre 2014

RhinoMock in Specification.Machine, expectation violation expected 1, get 0

I have a problem with mocking my interface, I want to check if the method of my interface is call, so my interface/class looks like this:



IMyInterface
{
IMyInterface Method(string lel);
}

MyClass : MyInteface
{
public override IMyInterface Method(string lel)
{
//do something;
}
}

AnotherClass
{
private IMyInterface _instance;
public void AnotherMethod()
{
//do something with this instance of IMyInstance
}
}


and my test class looks like this:



[Subject(AnotherClass)]
abstract class AnotherClassTest : AnotherClass
{
protected static IMyInterface MyInterface;
Establish context = () =>
{
MyInterface = fake.an<IMyInterface>(); // MockRepository.GenerateStrictMock<IMyInterface>(); this also doesn't work properly.
MyInterface.Stub(x => x.Method("lel")).IgnoreArguments().Return(MyInterface);
}
}

[Subject(AnotherClass)]
class When_cos_tam_cos_tam : AnotherClassTest
{
Establish context = () =>
{
//MyInterface.Stub(x => x.Method("lel")).IgnoreArguments().Return(MyInterface);
}
Because of = () => sut.AnotherMethod();
It Should_cos_tam = () => MyInterface.AssertWasCalled(x => x.Method("lel"));
}


And I'm getting following error:



Rhino.Mocks.Exceptions.ExpectationViolationException' occurred in Rhino.Mocks.dll
IMyInterface.Method("lel")); Expected #1, Actual #0.

Aucun commentaire:

Enregistrer un commentaire