Hi,

It seems that all the calls to the mock instance are synchronized.
This is a problem, at least for PartialMock. Here is the test case. I
would pass fine if we use new SyncExample instead of
mockery.PartialMock<SyncExample>().

        public class SyncExample
        {
            private int count = 0;

            [MethodImpl(MethodImplOptions.Synchronized)]
            public virtual bool Consume(int timeout)
            {
                while (count <= 0)
                {
                    if (!Monitor.Wait(this, timeout)) return false;
                }
                count--;
                return true;
            }

            [MethodImpl(MethodImplOptions.Synchronized)]
            public virtual void Produce()
            {
                int c = count++;
                if (c <= 0) Monitor.PulseAll(this);
            }
        }

        [Test]
        public void MockInstanceSyncTest()
        {
            MockRepository mockery = new MockRepository();
            var syncMock = mockery.PartialMock<SyncExample>();
            //var syncMock = new SyncExample();
            Thread t = new Thread(
                () =>
                    {
                        Thread.Sleep(100);
                        syncMock.Produce();
                    });
            t.Start();
            try
            {
                var result = syncMock.Consume(500);
                Assert.IsTrue(result);
            }
            finally
            {
                if(t.IsAlive) t.Abort();
            }

        }

Thanks,
Kenneth

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