예제 #1
0
 [Test] public void RunRestoresContextWhenCarrierIsNotNull()
 {
     _sut.Run();
     Mockery.Assert(
         _contextCarrier.ActivityOf(x => x.Restore())
         < _runnable.ActivityOf(x => x.Run()));
 }
예제 #2
0
        [Test] public void ExecuteCopiesContextBeforeExecutesRunnable()
        {
            var cc = SetupContextCarrier();

            _sut.Execute(_runnable);

            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _runnable.ActivityOf(x => x.Run()));
            _sut.AssertWasCalled(x => x.Protected <Action <IRunnable> >("DoExecute")(Arg <IRunnable> .Is.NotNull));
        }
예제 #3
0
        [Test] public void SubmitCopiesContextBeforeExecutesAction()
        {
            IContextCarrier cc     = SetupContextCarrier();
            var             future = _sut.Submit(_action, TestData <T> .One);

            Assert.IsTrue(future.IsDone);
            Assert.That(future.GetResult(), Is.EqualTo(TestData <T> .One));

            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _action.ActivityOf(x => x()));
        }
예제 #4
0
        [Test] public void InvokeAnyCopiesContextBeforeExecuteCallable([Values(true, false)] bool isTimed)
        {
            var cc = SetupContextCarrier();

            _callable.Stub(x => x.Call()).Return(TestData <T> .Four);
            var result = isTimed ?
                         _sut.InvokeAny(Delays.Small, _callable) :
                         _sut.InvokeAny(_callable);

            Assert.That(result, Is.EqualTo(TestData <T> .Four));
            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _callable.ActivityOf(x => x.Call()));
        }
예제 #5
0
        [Test] public void SubmitCopiesContextBeforeExecutesCallable()
        {
            IContextCarrier cc = SetupContextCarrier();

            _callable.Stub(x => x.Call()).Return(TestData <T> .Two);
            var future = _sut.Submit(_callable);

            Assert.IsTrue(future.IsDone);
            Assert.That(future.GetResult(), Is.EqualTo(TestData <T> .Two));

            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _callable.ActivityOf(x => x.Call()));
        }
예제 #6
0
        [Test] public void InvokeAllOrFailCopiesContextBeforeExecuteCallable([Values(true, false)] bool isTimed)
        {
            var cc = SetupContextCarrier();

            _callable.Stub(x => x.Call()).Return(TestData <T> .Four);
            var futures = isTimed ?
                          _sut.InvokeAllOrFail(Delays.Small, _callable) :
                          _sut.InvokeAllOrFail(_callable);

            foreach (IFuture <T> future in futures)
            {
                Assert.That(future.GetResult(), Is.EqualTo(TestData <T> .Four));
            }
            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _callable.ActivityOf(x => x.Call()));
        }
        private void AssertAny(IFoo foo)
        {
            Assert.IsTrue(foo.ActivityOf(f => f.Foo(1)) ||
                          foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything)));

            Mockery.Assert(foo.ActivityOf(f => f.Foo(1))
                           .Or(foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything))));

            Mockery.Assert(foo.ActivityOf(f => f.Foo(1)) |
                           foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything)));

            (foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything)) |
             foo.ActivityOf(f => f.Foo(1))).AssertOccured();

            // C# 2.0 syntax
            Mockery.Assert(Mockery.ActivityOf(foo, delegate(IFoo f) { f.Foo(1); }) |
                           Mockery.ActivityOf(foo, delegate(IFoo f) { f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything); }));
        }
        [Test] public void AddRangeAddAllElementsInTraversalOrder()
        {
            T[] testData = TestData <T> .MakeTestArray(5);

            _sut.Stub(x => x.Add(Arg <T> .Is.Anything));
            Assert.That(_sut.AddRange(testData), Is.True);
            Activities last = null;

            foreach (T data in testData)
            {
                T   element = data;
                var call    = _sut.ActivityOf(x => x.Add(element));
                if (last != null)
                {
                    Mockery.Assert(last < call);
                }
                last = call;
            }
        }
        [Test] public void Or_failed_when_non_of_the_methods_is_called()
        {
            var foo = MockRepository.GenerateMock <IFoo>();

            Assert.IsFalse(foo.ActivityOf(f => f.Foo(1)) ||
                           foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything)));

            Assert.Throws <ExpectationViolationException>(
                () => Mockery.Assert(foo.ActivityOf(f => f.Foo(1))
                                     .Or(foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything)))));

            Assert.Throws <ExpectationViolationException>(
                () => Mockery.Assert(foo.ActivityOf(f => f.Foo(1)) |
                                     foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything))));

            Assert.Throws <ExpectationViolationException>(
                () => (foo.ActivityOf(f => f.Foo(1)) |
                       foo.ActivityOf(f => f.Foo(Arg <int> .Is.Equal(1), Arg <int> .Is.Anything))).AssertOccured());
        }
예제 #10
0
        [Test] public void InvokeAllOrFailCopiesContextWhenNewTaskForCallableWasOverriden([Values(true, false)] bool isTimed)
        {
            var cc             = SetupContextCarrier();
            var runnableFuture = MockRepository.GenerateMock <IRunnableFuture <T> >();

            _callable.Stub(x => x.Call()).Return(TestData <T> .Four);
            _sut.Stub(x => x.NewTaskFor(Arg <ICallable <T> > .Is.NotNull)).Return(runnableFuture);
            runnableFuture.Stub(x => x.Run()).Do(new Action(() => _callable.Call()));

            if (isTimed)
            {
                _sut.InvokeAllOrFail(Delays.Small, _callable, _callable);
            }
            else
            {
                _sut.InvokeAllOrFail(_callable, _callable);
            }
            runnableFuture.AssertWasCalled(x => x.Run());
            Mockery.Assert(cc.ActivityOf(x => x.Restore()).First < _callable.ActivityOf(x => x.Call()).First);
        }
예제 #11
0
        private void CheckOneOf(IFoo foo, bool succeed)
        {
            var expect = Mockery.ExactOneOf(
                foo.ActivityOf(f => f.Foo(1), m => m.Repeat.Once()),
                foo.ActivityOf(f => f.Foo(1, 2), m => m.Repeat.Once()),
                foo.ActivityOf(f => f.Foo(1, 2, 3), m => m.Repeat.Once())
                );

            if (succeed)
            {
                Assert.IsTrue(expect);
                Mockery.Assert(expect);
            }
            else
            {
                Assert.IsFalse(expect);
                Assert.Throws <ExpectationViolationException>(
                    () => Mockery.Assert(expect));
            }
        }
예제 #12
0
        public void BeforeAfterExecuteAreCalledWhenExecutingTask()
        {
            var runnable = MockRepository.GenerateStub <IRunnable>();
            var es       = Mockery.GeneratePartialMock <ThreadPoolExecutor>(1, 1, Delays.Long, new SynchronousQueue <IRunnable>());

            ExecutorService = es;
            try
            {
                es.Execute(runnable);
                Thread.Sleep(Delays.Short);
                Mockery.Assert(
                    es.ActivityOf(e => e.AfterExecute(runnable, null))
                    > runnable.ActivityOf(r => r.Run())
                    > es.ActivityOf(e => e.BeforeExecute(Arg <Thread> .Is.NotNull, Arg <IRunnable> .Is.Equal(runnable))));
            }
            finally // workaround a bug in RhinoMocks.
            {
                es.Shutdown();
                Thread.Sleep(Delays.Short);
            }
            JoinPool(es);
            ThreadManager.JoinAndVerify();
        }