Firstly, thanks for an amazing Mocking framework. I especially love
the type safety given using lambdas and the AAA syntax.

My only problem has been with trying to do a partial mock.
Many times I am testing for a specific method call on an interface,
and I pretty much just want the rest of the methods on the interface
to return something useful. So my first thought was to try to create a
partial mock for a class that implements the interface and then just
'override' the specific method of the interface using Rhino Mocks.
Not matter what I tried I couldn't get this to work. Any Suggestions?

I also need to test the scenario where I need to check that one method
on a class is using/calling another method on the class. I tried to
use Partial mocks for this, but couldn't get that to work either. Is
there something that I'm doing wrong?

Here is a simple code sample. Please could you show me how to get the
last test working. Thanks.
Here it goes:

public class MyClass
    {
        public virtual string MethodA()
        {
            return "Hello World";
        }

        public virtual string MethodB()
        {
            return string.Format("'{0}'", MethodA());
        }
    }

    [TestFixture]
    public class TestExample
    {

        [Test]
        public void Test_MethodA_ShouldReturnHelloWorld()
        {
            //---------------Set up test pack-------------------
            MyClass myClass = new MyClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string returnedString = myClass.MethodA();
            //---------------Test Result -----------------------
            const string expected = "Hello World";
            Assert.AreEqual(expected, returnedString);
        }

        [Test]
        public void Test_MethodB_ShouldReturnQuotedHelloWorld()
        {
            //---------------Set up test pack-------------------
            MyClass myClass = new MyClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string returnedString = myClass.MethodB();
            //---------------Test Result -----------------------
            const string expected = "'Hello World'";
            Assert.AreEqual(expected, returnedString);
        }

        [Test]
        public void Test_MethodB_ShouldUseMethodA()
        {
            //---------------Set up test pack-------------------
            const string otherReturnValue = "Hello Universe";
            MyClass myClass = new MockRepository().PartialMock<MyClass>
();
            myClass.Stub(t => t.MethodA()).Return
(otherReturnValue).Repeat.Any();
            myClass.Stub(t => t.MethodB()).CallOriginalMethod
(OriginalCallOptions.NoExpectation);
            //---------------Assert Precondition----------------
            Assert.AreEqual(otherReturnValue, myClass.MethodA());
            //---------------Execute Test ----------------------
            string returnedString = myClass.MethodB();
            //---------------Test Result -----------------------
            string expected = string.Format("'{0}'",
otherReturnValue);
            Assert.AreEqual(expected, returnedString);
        }
    }

Any Ideas?

Thanks
-Mark Whitfeld

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to