Rhino Mocks Exception Expect #1 Actual #0 : Need help?

You're telling the mock framework to stub the MockedMethod class on the provider object, but you never inject the provider into the mainClass object to be used. It's not clear to me what you are trying to accomplish but if you want the mocked method to be called then it has to be called on the object on which the stub was set up.

You're telling the mock framework to stub the MockedMethod class on the provider object, but you never inject the provider into the mainClass object to be used. It's not clear to me what you are trying to accomplish but if you want the mocked method to be called then it has to be called on the object on which the stub was set up. If you define MockThis as below, I think you will find that it will work.

Public MockClass MockThis(IMockInterface provider) { return provider.MockMethod(); } The bottom line is that you get the exception because the method was never called on the provider, only on the mainClass object. EDIT: Example public class ClassUnderTest { private ProviderClass provider { get; set; } public ClassUnderTest( ProviderClass provider ) { this. Provider = provider; } public int DoOperation() { return this.Provider.

ProviderOperation(); } } public class ProviderClass { private int value = 42; public ProviderClass() { } public virtual int ProviderOperation() { return this. Value; } } TestMethod public void DoOperationTest() { ProviderClass mockProvider = MockRepository.GenerateMock(); mockProvider. Expect( mp => mp.

ProviderOperation() ). Return( -1 ); ClassUnderTest target = new ClassUnderTest( mockProvider ); int expectedValue = -1; int value = target.DoOperation(); Assert. AreEqual( expectedValue, value ); mockProvider.

VerifyAllExpectations(); } Normally the ProviderClass object would return 42 from the ProviderOperation method, but we've mocked it out and told it to return -1. When the ClassUnderTest DoOperation method is called, the mock provider object's ProviderOperation method is invoked and returns the mocked value of -1. Hope this helps.

I'm just trying to create a junk class to learn how to mock. Basically I created the class to have a method that would be called within a method and return something. – Programmin Tool Dec 15 '08 at 22:01 The mocked object is a specific object, though.

The code you are testing will need to use the mocked object directly in order for the stubbed/mocked methods to be invoked. – tvanfosson Dec 15 '08 at 22:02 In all honesty, I could use the second example if it would work. Right now I'm just an idiot child trying to put an airplane together with a box of parts.

– Programmin Tool Dec 15 '08 at 22:03 Ok so first test example was bad as you noted. Stub wasn't what I needed. However, I did have the second example that still didn't work.

– Programmin Tool Dec 15 '08 at 22:13 Answered one question, only brought on more. – Programmin Tool Dec 15 '08 at 22:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions