public void ThrowsExpectationExceptionIfExpecatationViolationInBackgroundWhileWaitingForAGivenState()
        {
            IStates threads = mockery.States("threads");

            var blitzer = new Blitzer(5);
            var count = new AtomicInt(5);
            var mock = mockery.NewInstanceOfRole<ISpeaker>();

            Expect.Once.On(mock).Message("Goodbye").Then(threads.Is("finished"));
            OnNewThread(() => blitzer.Blitz(() => {
                                                if (count.Decrement() == 0) mock.Goodbye();
                                                else
                                                    mock.Hello();
                                            }));

            try
            {
                synchronizer.WaitUntil(threads.Is("finished"));
                Assert.Fail("shold have thrown expectation error when unexpected invocation in background");
            }
            catch (ExpectationException e)
            {
                Assert.That(e.Message, NUnit.Framework.Is.StringContaining("Hello()"));
            }
        }
        public void ByDefaultShouldNotAllowInvocationsFromMultipleThreads()
        {
            mockery = new Mockery();
            var blitzer = new Blitzer(16);
            var numberOfconcurrentExceptions = new AtomicInt(0);
            var mock = mockery.NewInstanceOfRole<ISpeaker>();
            Expect.Exactly(blitzer.TotalActionCount()).On(mock).Message("Hello");
            blitzer.Blitz(() => {
                              try
                              {
                                  mock.Hello();
                              }
                              catch (ConcurrentModificationException)
                              {
                                  numberOfconcurrentExceptions.Increment();
                              }
                          });

            Assert.AreEqual(numberOfconcurrentExceptions.Value, 16, "should intercept invocation from non test thread");
        }
        public void CanWaitUntilStateMachineIsInAGivenState()
        {
            IStates threads = mockery.States("threads");

            var blitzer = new Blitzer(5);
            var count = new AtomicInt(5);
            var mock = mockery.NewInstanceOfRole<ISpeaker>();
            Expect.Exactly(blitzer.TotalActionCount()).On(mock).Message("Hello");
            Expect.Once.On(mock).Message("Goodbye").Then(threads.Is("finished"));
            OnNewThread(() => blitzer.Blitz(() => {
                                                mock.Hello();
                                                if (count.Decrement() == 0) mock.Goodbye();
                                            }));

            synchronizer.WaitUntil(threads.Is("finished"));
            mockery.VerifyAllExpectationsHaveBeenMet();
        }