Thanks for your reply. Unfortunatelly, that doesn't work.

Here is a simple example:

    public interface IInterface1
    {
        void MethodToCall();
        event EventHandler Event;
    }

    public interface IInterface2
    {
        bool Condition();
        event EventHandler Event;
    }

    internal class SUT
    {
        readonly IInterface1 _interface1;
        readonly IInterface2 _interface2;

        public SUT(IInterface1 interface1, IInterface2 interface2)
        {
            _interface1 = interface1;
            _interface2 = interface2;
            _interface2.Event += OnInterfaceEvent;
            _interface1.MethodToCall();
        }

        void OnInterfaceEvent(object sender, EventArgs e)
        {
            if(_interface2.Condition())
                _interface1.MethodToCall();
        }
    }

    public class RhinoMocksTest
    {
        [Fact]
        public void RemovingCallsFromMock()
        {
            IInterface1 interface1 =
MockRepository.GenerateMock<IInterface1>();
            IInterface2 interface2 =
MockRepository.GenerateMock<IInterface2>();

            SUT sut = new SUT(interface1, interface2);

            interface1.BackToRecord();
            interface1.Replay();

            interface2.Stub(x => x.Condition()).Return(false);
            interface2.Raise(x => x.Event += null, null,
EventArgs.Empty);

            interface1.AssertWasNotCalled(x => x.MethodToCall());
        }
    }

AssertWasNotCalled still fails.

On 29 Aug., 20:50, Ayende Rahien <[email protected]> wrote:
> BackToRecord()
>
> On Sat, Aug 29, 2009 at 7:50 PM, DHilgarth <[email protected]> wrote:
>
> > Hi!
>
> > I have the following problem:
>
> > I am passing a mock object mock1 to the ctor of my SUT.
> > In this ctor the SUT calls a method A on mock1.
>
> > Then I raise an event on another mock object mock2 the SUT subscribed
> > to.
> > In response to that event, the SUT should call the method A of mock1
> > again.
>
> > using mock1.AssertWasCalled will succeed, but regardless of whether
> > the SUT called method A in response to the event or not.
>
> > Furthermore, the SUT should call A only if a certain condition is
> > true. In the test that tests that A is NOT called if the condition is
> > false, I have the call to mock1.AssertWasNotCalled. This will always
> > fail, because of the call to A in the ctor of the SUT.
>
> > I would have to strip mock1 of all its method calls after the ctor of
> > the SUT ran... How can I do this?
>
> > Kind regards,
>
> > Daniel
>
>
--~--~---------~--~----~------------~-------~--~----~
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