This works for me:

            ITestInterface ti = MockRepository.GenerateMock<ITestInterface>();

            // Load the class that is being processed
            TestClass test = new TestClass();

            ti.Expect(a =>
a.Update(Arg<TestClass>.Matches(Rhino.Mocks.Constraints.Is.Matching<TestClass>(b
=> b.Status == "processing"))));
            // Update the status to indicate processing has begun
            test.Status = "processing";
            ti.Update(test);

            ti.AssertWasCalled(a =>
a.Update(Arg<TestClass>.Matches(Rhino.Mocks.Constraints.Is.Matching<TestClass>(b
=> b.Status == "processing"))));

            // Work gets done here ...

            ti.Expect(a =>
a.Update(Arg<TestClass>.Matches(Rhino.Mocks.Constraints.Is.Matching<TestClass>(b
=> b.Status == "processed"))));
            // Update the status to indicate processing is complete
            test.Status = "processed";
            ti.Update(test);


On Thu, May 7, 2009 at 7:49 PM, Tim Barcz <[email protected]> wrote:
>
> Create a second test object. There doesn't appear to be a need to have
> the two operations performed on the same object.
>
> Can I ask why you need a way around?  It seems your testing too much
> in your test.  Your friction with Rhino should be a good clue that
> your test design may be flawed.
>
> On 5/7/09, Brian J <[email protected]> wrote:
>>
>> I've run into an issue in the AssertWasCalled when there are multiple
>> calls using the same object.  Basically I'm doing some processing on a
>> class and during the processing I want to make sure that I hit certain
>> checkpoints in my unit tests. I do this by setting the status and
>> saving it.  I then continue the processing until the next checkpoint.
>>
>> Here's a sample of what I mean:
>>
>> [TestClass]
>> public class Class1 {
>>
>>     [TestMethod]
>>     public void MethodName() {
>>         ITestInterface ti = MockRepository.GenerateStub<ITestInterface>
>> ();
>>
>>         // Load the class that is being processed
>>         TestClass test = new TestClass();
>>
>>         // Update the status to indicate processing has begun
>>         test.Status = "processing";
>>         ti.Update(test);
>>
>>         // Work gets done here ...
>>
>>         // Update the status to indicate processing is complete
>>         test.Status = "processed";
>>         ti.Update(test);
>>
>>         // These are the assertions that are failing.
>>         ti.AssertWasCalled(a => a.Update(Arg<TestClass>.Matches(b =>
>> b.Status == "processing")));
>>         ti.AssertWasCalled(a => a.Update(Arg<TestClass>.Matches(b =>
>> b.Status == "processed")));
>>     }
>> }
>>
>> public interface ITestInterface {
>>     void Update(TestClass param);
>> }
>>
>> public class TestClass {
>>     public string Status { get; set; }
>> }
>>
>> It looks like what's happening is that rhino mocks is only saving a
>> reference of the parameters for each method call to Update.  When I
>> update the Status for the second call, it's also updating the object
>> that rhino mocks saved in the first call.  This makes the first
>> AssertWasCalled fail because it thinks there were no call with the
>> string "processing" and the second assert fail because it thinks there
>> were too many calls for "processed".
>>
>> Does anyone know a way around this?
>>
>> Thanks,
>> Brian
>>
>> >
>>
>
> --
> Sent from my mobile device
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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