Hi Readers,

I have some problems with BackToRecord
(BackToRecordOptions.Expectations) and Replay

At some point in my test I want to change the expextation but its
events.
I added a helloworld example at the bottom that demonstrates my
problem.
It fails at the unsubscribtion of the event but it has to do with the
BackToRecord and Replay.
Somehow this changes the behavior of my (Dynamic?) mock such that doas
not accept the
unsubscription


Hope you can help he out with this issue,
Thanks in advance,
Andre


using System;
using NUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Interfaces;

namespace UnitTests {
    [TestFixture]
    public class RhinoMockSandbox {

        public interface IMyInterface {
            int Foo();
            event EventHandler EVH;
        }

        public class UserOfInterface {
            private readonly IMyInterface i;
            public int Counter;
            public UserOfInterface(IMyInterface i) {
                this.i = i;
                i.EVH += OnEventBar;
            }
            public int Bar() {
                return i.Foo();
            }

            void OnEventBar(object sender, EventArgs a) {
                Counter++;
            }

            public void Dispose() {
                i.EVH -= OnEventBar;
            }
        }
        [Test]
        public void Test3() {
            IMyInterface stub =
MockRepository.GenerateStub<IMyInterface>();
            stub.Stub(x => x.Foo()).Return(1); //).Repeat.Once();
<--  I don't want to use counting b'se it it too brittle

            IEventRaiser raiser = stub.GetEventRaiser(x => x.EVH +=
null);
            UserOfInterface user = new UserOfInterface(stub);
            Assert.AreEqual(1, user.Bar());
            raiser.Raise(stub, EventArgs.Empty);
            Assert.AreEqual(1, user.Counter);

            stub.BackToRecord(BackToRecordOptions.Expectations);
            stub.Stub(x => x.Foo()).Return(2);
            stub.Replay();

            Assert.AreEqual(2, user.Bar());
            raiser.Raise(stub, EventArgs.Empty);
            Assert.AreEqual(2, user.Counter);

            user.Dispose(); // Breaks here on the describtion in the
rhino mock
        }
    }
}
-- 
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