Ejemplo n.º 1
0
        public void IntialDiscoTest()
        {
            IEventRaiser onAuth;

            IQ   sentIq       = null;
            IqCB sentCallback = null;

            mocks.BackToRecordAll();
            using (mocks.Record())
            {
                Expect.Call(stream.Server).Return(jid);
                stream.OnAuthenticate += null;
                onAuth = LastCall.IgnoreArguments().GetEventRaiser();

                Expect.Call(stream.Document).Return(doc);
                SetupTrackerBeginIq(
                    delegate(IQ arg0, IqCB arg1, object arg2)
                {
                    // Grab the iq and callback so this part of
                    // the code can finish. Call the callback later.
                    sentIq       = arg0;
                    sentCallback = arg1;

                    string id         = arg0.GetAttribute("id");
                    string original   = arg0.OuterXml.Replace(" ", "");
                    string comparison = GetInfoXml(id).Replace(" ", "");
                    return(original == comparison);
                });

                Expect.Call(stream.Document).Return(doc);
                SetupTrackerBeginIq(
                    delegate(IQ arg0, IqCB arg1, object arg2)
                {
                    string id       = arg0.GetAttribute("id");
                    string original = arg0.OuterXml;
                    return(original.Replace(" ", "") ==
                           GetItemsForServiceXml(id).Replace(" ", ""));
                });
            }

            using (mocks.Playback())
            {
                DiscoManager newDm = new DiscoManager();
                newDm.Stream = stream;

                onAuth.Raise(new object[] { null });

                if (sentIq != null)
                {
                    string id = sentIq.GetAttribute("id");
                    if (sentCallback != null)
                    {
                        sentCallback(null, CreateDiscoInfoResponse(id), newDm.Root);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void CurrentStepIndex()
        {
            SetupWizardConfiguration(0);
            Assert.AreEqual(0, helper.CurrentStepIndex);

            repository.BackToRecordAll();
            SetupWizardConfiguration(1);
            Assert.AreEqual(1, helper.CurrentStepIndex);

            repository.BackToRecordAll();
            SetupWizardConfiguration(2);
            Assert.AreEqual(2, helper.CurrentStepIndex);
        }
Ejemplo n.º 3
0
        public void UpdatingWhileFileIsGrowing()
        {
            MockRepository rep = new MockRepository();
            IFileSystem    fs  = rep.CreateMock <IFileSystem>();
            MyFileStream   stm = rep.CreateMock <MyFileStream>(rep);

            Expect.Call(fs.OpenFile("test")).Return(stm);

            DateTime time1 = new DateTime(2000, 1, 1);
            long     size1 = 100;

            Expect.Call(stm.Length).Repeat.Any().Return(size1);
            Expect.Call(stm.LastWriteTime).Repeat.Any().Return(time1);
            Expect.Call(stm.IsDeleted).Repeat.Any().Return(false);

            rep.ReplayAll();

            using (SimpleFileMedia media = new SimpleFileMedia(fs, SimpleFileMedia.CreateConnectionParamsFromFileName("test")))
            {
                Assert.AreEqual(time1, media.LastModified);
                Assert.AreEqual(size1, media.Size);
                Assert.AreEqual(size1, media.DataStream.Length);

                rep.VerifyAll();

                rep.BackToRecordAll();

                DateTime time2 = new DateTime(2000, 2, 2);
                long     size2 = 200;
                Expect.Call(stm.Length).Repeat.Any().Return(size2);
                Expect.Call(stm.LastWriteTime).Repeat.Any().Return(time2);
                Expect.Call(stm.IsDeleted).Repeat.Any().Return(false);

                rep.ReplayAll();

                media.Update();

                Assert.AreEqual(time2, media.LastModified);
                Assert.AreEqual(size2, media.Size);

                rep.VerifyAll();

                rep.BackToRecordAll();
                stm.Dispose();
                LastCall.On(stm).Repeat.AtLeastOnce();
                rep.ReplayAll();
            }

            rep.VerifyAll();
        }
Ejemplo n.º 4
0
        public void MessageIsNotReadBecauseItEndsAtTheBeginningOfTheRange_Backward()
        {
            MockRepository repo = new MockRepository();

            // reading from position 11 with range 6-15
            //   _msg1_msg2_msg3
            //    |    |    |   |
            //    1    6    11  15
            // range begins at pos 6. msg1_ ends at pos 6 (its past-the-end position = 6). msg1_ shouldn't be read.

            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"msg", ReOptions.None));

            repo.VerifyAll();

            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(11, TextAccessDirection.Backward)).Return(it);
            Expect.Call(it.PositionToCharIndex(11)).Return(11);
            Expect.Call(it.CharIndexToPosition(6)).Return((long)6);
            Expect.Call(it.CurrentBuffer).Return("_msg1_msg2_msg3");
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(6, 15), 11, MessagesParserDirection.Backward);
            repo.VerifyAll();
            Assert.IsFalse(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            Expect.Call(it.CharIndexToPosition(11)).Return((long)11);
            Expect.Call(it.CharIndexToPosition(1)).Return((long)1);
            repo.ReplayAll();
            var capt = new TextMessageCapture();

            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("msg", capt.MessageHeader);
            Assert.AreEqual("2_", capt.MessageBody);
            Assert.AreEqual(6L, capt.BeginPosition);
            Assert.AreEqual(11L, capt.EndPosition);
            Assert.IsTrue(capt.IsLastMessage);
            Assert.IsFalse(target.CurrentMessageIsEmpty);

            repo.BackToRecordAll();
            repo.ReplayAll();
            Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
        }
Ejemplo n.º 5
0
        public void BeginSplittingSession_NestedSessionsAreNotAllowed()
        {
            MockRepository repo = new MockRepository();


            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"111", ReOptions.None));

            repo.VerifyAll();


            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(0, TextAccessDirection.Forward)).Return(it);
            Expect.Call(it.PositionToCharIndex(0)).Return(0);
            Expect.Call(it.CurrentBuffer).Return("00 111 222");
            Expect.Call(it.CharIndexToPosition(3)).Return((long)3);
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(0, 100), 0, MessagesParserDirection.Forward);
            repo.VerifyAll();
            Assert.IsFalse(target.CurrentMessageIsEmpty);

            Assert.Throws <InvalidOperationException>(() =>
            {
                target.BeginSplittingSession(new Range(0, 200), 0, MessagesParserDirection.Forward);
            });
        }
Ejemplo n.º 6
0
        public void BeginSplittingSession_TextIteratorMustBeCleanedUpInCaseOfException()
        {
            MockRepository repo = new MockRepository();


            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"111", ReOptions.None));

            repo.VerifyAll();


            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(0, TextAccessDirection.Forward)).Return(it);
            Expect.Call(it.PositionToCharIndex(0)).Return(0);
            Expect.Call(it.CurrentBuffer).Throw(new System.Security.SecurityException());
            it.Dispose(); Expect.On(it);
            repo.ReplayAll();
            try
            {
                target.BeginSplittingSession(new Range(0, 100), 0, MessagesParserDirection.Forward);
                Assert.IsTrue(false, "We must never get here because of an exception in prev call");
            }
            catch (System.Security.SecurityException)
            {
            }
            repo.VerifyAll();
            Assert.IsTrue(target.CurrentMessageIsEmpty);
        }
Ejemplo n.º 7
0
        public void CanUseBackToRecordOnMethodsThatCallToCallOriginalMethod()
        {
            MockRepository repository = new MockRepository();
            TestClass      mock       = repository.StrictMock <TestClass>();

            mock.Method();
            LastCall.CallOriginalMethod
                (OriginalCallOptions.NoExpectation);

            repository.ReplayAll();
            mock.Method();
            repository.VerifyAll();

            repository.BackToRecordAll();

            mock.Method();
            LastCall.Throw(new ApplicationException());

            repository.ReplayAll();

            try
            {
                mock.Method();
                Assert.False(true);
            }
            catch
            {
            }
            repository.VerifyAll();
        }
        public void ParentMembers()
        {
            _mockRepository.BackToRecordAll();

            var r1 = new ClassContextBuilder(new MixinConfigurationBuilder(null), typeof(object));
            var r2 = new MixinConfiguration();
            var r3 = _mockRepository.StrictMock <IDisposable> ();

            using (_mockRepository.Ordered())
            {
                _parentBuilderMock.Expect(mock => mock.ForClass <object> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.ForClass <string>()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.BuildConfiguration()).Return(r2);
                _parentBuilderMock.Expect(mock => mock.EnterScope()).Return(r3);
            }

            _mockRepository.ReplayAll();

            Assert.That(_classBuilder.ForClass <object> (), Is.SameAs(r1));
            Assert.That(_classBuilder.ForClass <string> (), Is.SameAs(r1));
            Assert.That(_classBuilder.BuildConfiguration(), Is.SameAs(r2));
            Assert.That(_classBuilder.EnterScope(), Is.SameAs(r3));

            _mockRepository.VerifyAll();
        }
Ejemplo n.º 9
0
        private MainMenuTab CreateMainMenuTab()
        {
            MainMenuTab mainMenuTab = CreateMainMenuTabWithoutCommand();

            mainMenuTab.Command = _mockNavigationCommand;
            _mocks.BackToRecordAll();

            return(mainMenuTab);
        }
        private WebMenuItem CreateWebMenuItem()
        {
            WebMenuItem menuItem = CreateWebMenuItemWithoutCommand();

            menuItem.Command = _mockCommand;
            _mocks.BackToRecordAll();

            return(menuItem);
        }
Ejemplo n.º 11
0
        public void StartBackwardReadingFromAlmostEndPosition()
        {
            MockRepository repo = new MockRepository();


            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None));

            repo.VerifyAll();


            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(99, TextAccessDirection.Backward)).Return(it);
            Expect.Call(it.PositionToCharIndex(99)).Return(28);
            Expect.Call(it.CurrentBuffer).Return(
                "123456 abc 283147948 abc 3498");
            // |      |  |          |  |   ||
            // 0      7  10         21 24  28\29  - char idx
            // 50     61 67         85 87  99\100 - position
            Expect.Call(it.CharIndexToPosition(21)).Return((long)85);
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(0, 100), 99, MessagesParserDirection.Backward);
            repo.VerifyAll();
            Assert.IsFalse(target.CurrentMessageIsEmpty);

            repo.BackToRecordAll();
            Expect.Call(it.CharIndexToPosition(7)).Return((long)61);
            Expect.Call(it.CharIndexToPosition(28)).Return((long)99);
            repo.ReplayAll();
            var capt = new TextMessageCapture();

            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.MessageHeader);
            Assert.AreEqual(" 349", capt.MessageBody);
            Assert.AreEqual(85L, capt.BeginPosition);
            Assert.AreEqual(99L, capt.EndPosition);
            Assert.IsTrue(capt.IsLastMessage);
            Assert.IsFalse(target.CurrentMessageIsEmpty);
        }
Ejemplo n.º 12
0
        public void HeaderRegexMatchesPartOfAMessage_Forward()
        {
            MockRepository repo = new MockRepository();

            var capt = new TextMessageCapture();

            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.AverageBufferLength).Return(100);
            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"ab(c)?", ReOptions.None), MessagesSplitterFlags.PreventBufferUnderflow);

            repo.VerifyAll();

            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(0, TextAccessDirection.Forward)).Return(it);
            Expect.Call(it.PositionToCharIndex(0)).Return(0);
            Expect.Call(it.CurrentBuffer).Return("ab");
            Expect.Call(it.Advance(0)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return("abc_");
                Expect.Call(it.CharIndexToPosition(0)).Return((long)0);
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(0, 10), 0, MessagesParserDirection.Forward);
            repo.VerifyAll();
            Assert.IsFalse(target.CurrentMessageIsEmpty);

            repo.BackToRecordAll();
            Expect.Call(it.Advance(3)).Return(false);
            Expect.Call(it.CharIndexToPosition(4)).Return((long)3);
            repo.ReplayAll();
            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.MessageHeader);
            Assert.AreEqual("_", capt.MessageBody);
            Assert.IsTrue(target.CurrentMessageIsEmpty);
        }
Ejemplo n.º 13
0
        public void SetUp()
        {
            mocks   = new MockRepository();
            factory = (IPoolableObjectFactory)mocks.DynamicMock(typeof(IPoolableObjectFactory));
            Expect.Call(factory.MakeObject()).Return(new object()).Repeat.Any();

            mocks.ReplayAll();
            pool = new SimplePool(factory, 1);

            mocks.BackToRecordAll();
        }
Ejemplo n.º 14
0
        public void TearDown()
        {
            mocks.BackToRecordAll();

            using (mocks.Record())
            {
                session.Expect(s => s.Close()).Return(null).Repeat.Any();
            }
            using (mocks.Playback())
            {
                store.Dispose();
            }
        }
        public void SetupContext()
        {
            _factory    = _mocks.DynamicMock <IUnitOfWorkFactory>();
            _unitOfWork = _mocks.DynamicMock <IUnitOfWork>();
            _session    = _mocks.DynamicMock <ISession>();

            InstrumentUnitOfWork();

            _mocks.BackToRecordAll();
            SetupResult.For(_factory.Create()).Return(_unitOfWork);
            SetupResult.For(_factory.CurrentSession).Return(_session);
            _mocks.ReplayAll();
        }
Ejemplo n.º 16
0
        public void BackToRecordAll_EraseAllRecordedExpectations()
        {
            MockRepository repository = new MockRepository();
            TestedClass    mockObject = (TestedClass)repository.StrictMock(typeof(TestedClass));

            mockObject.AnyMethod();
            repository.BackToRecordAll();
            mockObject.AnyMethod();

            repository.ReplayAll();
            mockObject.AnyMethod();
            repository.VerifyAll();
        }
Ejemplo n.º 17
0
        public void BackToRecordAll_EraseAllRecordedExpectations()
        {
            MockRepository repository = new MockRepository();
            TestedClass mockObject = (TestedClass)repository.StrictMock(typeof(TestedClass));

            mockObject.AnyMethod();
            repository.BackToRecordAll();
            mockObject.AnyMethod();

            repository.ReplayAll();
            mockObject.AnyMethod();
            repository.VerifyAll();
        }
Ejemplo n.º 18
0
        public void BeginSplittingSession_WithStartPositionThatDoesntGetMappedToCharacterByTextAccess()
        {
            MockRepository repo = new MockRepository();


            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"111", ReOptions.None));

            repo.VerifyAll();


            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(90, TextAccessDirection.Forward)).Return(it);
            Expect.Call(it.PositionToCharIndex(90)).Throw(new ArgumentOutOfRangeException());
            it.Dispose(); Expect.On(it);
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(0, 100), 90, MessagesParserDirection.Forward);
            repo.VerifyAll();
            Assert.IsTrue(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            repo.ReplayAll();
            TextMessageCapture capt = new TextMessageCapture();

            Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.IsTrue(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            repo.ReplayAll();
            target.EndSplittingSession();
            repo.VerifyAll();
        }
        public void ExecutionPlay_AfterExecutionStarted()
        {
            _function.Execute(_wxeContext);
            _mockRepository.BackToRecordAll();
            _innerListenerMock.Expect(mock => mock.OnExecutionPlay(_wxeContext));
            _mockRepository.ReplayAll();

            var securityListener = CreateSecurityListener(_securityAdapterMock);

            securityListener.OnExecutionPlay(_wxeContext);

            _mockRepository.VerifyAll();
        }
        public void SetNull()
        {
            SampleClass expected    = new SampleClass();
            IFactory    mockFactory = _mocks.StrictMock <IFactory> ();
            DoubleCheckedLockingContainer <SampleClass> container =
                new DoubleCheckedLockingContainer <SampleClass> (delegate { return(mockFactory.Create()); });

            _mocks.ReplayAll();

            container.Value = null;

            _mocks.VerifyAll();

            _mocks.BackToRecordAll();
            Expect.Call(mockFactory.Create()).Return(expected);

            _mocks.ReplayAll();

            SampleClass actual = container.Value;

            _mocks.VerifyAll();
            Assert.That(actual, Is.SameAs(expected));
        }
Ejemplo n.º 21
0
        public void WrapControlWithParentContainer_ReplacesControl_WithPostRequest()
        {
            var             testPageHolder = new TestPageHolder(true, RequestMode.PostBack);
            ControlReplacer replacer       = new ControlReplacer(MemberCallerMock)
            {
                ID = "TheReplacer"
            };
            var controlToReplace = new ReplaceableControlMock();
            var controlToWrap    = new ReplaceableControlMock();

            MemberCallerMock.Stub(stub => stub.GetControlState(controlToReplace)).Return(ControlState.ChildrenInitialized);

            using (MockRepository.Ordered())
            {
                MemberCallerMock.Expect(mock => mock.SetCollectionReadOnly(testPageHolder.Page.Controls, null)).Return("error");
                MemberCallerMock.Expect(mock => mock.SetCollectionReadOnly(testPageHolder.Page.Controls, "error")).Return(null).WhenCalled(
                    invocation => Assert.That(
                        testPageHolder.Page.Controls,
                        Is.EqualTo(new Control[] { testPageHolder.OtherNamingContainer, testPageHolder.NamingContainer, replacer })));
                MemberCallerMock.Expect(mock => mock.InitRecursive(replacer, testPageHolder.Page));
            }

            Assert.That(replacer.Controls, Is.Empty);
            MockRepository.ReplayAll();

            testPageHolder.Page.Controls.Add(controlToReplace);
            replacer.ReplaceAndWrap(controlToReplace, controlToWrap, new StateLoadingStrategy());
            MockRepository.VerifyAll();
            Assert.That(
                testPageHolder.Page.Controls,
                Is.EqualTo(new Control[] { testPageHolder.OtherNamingContainer, testPageHolder.NamingContainer, replacer }));
            Assert.That(replacer.Controls, Is.Empty);

            MockRepository.BackToRecordAll();
            MemberCallerMock.Stub(stub => stub.SetControlState(controlToWrap, ControlState.Constructed));
            MockRepository.ReplayAll();

            replacer.LoadPostData(null, null);

            MockRepository.VerifyAll();

            Assert.That(
                testPageHolder.Page.Controls,
                Is.EqualTo(new Control[] { testPageHolder.OtherNamingContainer, testPageHolder.NamingContainer, replacer }));
            Assert.That(replacer.Controls, Is.EqualTo(new[] { controlToWrap }));
            Assert.That(controlToReplace.Replacer, Is.Null);
            Assert.That(controlToWrap.Replacer, Is.SameAs(replacer));
            Assert.That(replacer.WrappedControl, Is.SameAs(controlToWrap));
        }
Ejemplo n.º 22
0
        public void BeginSplittingSession_WithStartPositionOutOfRange()
        {
            MockRepository repo = new MockRepository();


            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"111", ReOptions.None));

            repo.VerifyAll();


            repo.BackToRecordAll();
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(0, 100), 110, MessagesParserDirection.Forward);
            repo.VerifyAll();
            Assert.IsTrue(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            repo.ReplayAll();
            TextMessageCapture capt = new TextMessageCapture();

            Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.IsTrue(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            repo.ReplayAll();
            target.EndSplittingSession();
            repo.VerifyAll();
        }
Ejemplo n.º 23
0
        public void SetupContext()
        {
            _factory    = _mocks.DynamicMock <IUnitOfWorkFactory>();
            _unitOfWork = _mocks.DynamicMock <IUnitOfWork>();
            _session    = _mocks.DynamicMock <ISession>();

            // brute force attack to set my own factory via reflection
            var fieldInfo = typeof(UnitOfWork).GetField("_unitOfWorkFactory", BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);

            fieldInfo.SetValue(null, _factory);

            _mocks.BackToRecordAll();
            SetupResult.For(_factory.Create()).Return(_unitOfWork);
            SetupResult.For(_factory.CurrentSession).Return(_session);
            _mocks.ReplayAll();
        }
Ejemplo n.º 24
0
        public void Test_ReEntryAfterThreadAbort()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep step1 = MockRepository.GenerateMock <WxeStep> ();

            step1.Expect(mock => mock.Execute(_context)).WhenCalled(invocation => Thread.CurrentThread.Abort()).Repeat.Once();
            function.Add(step1);

            WxeStep step2 = MockRepository.GenerateMock <WxeStep>();

            step2.Expect(mock => mock.Execute(_context));
            function.Add(step2);

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionPause(_context));
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }

            _mockRepository.VerifyAll();
            _mockRepository.BackToRecordAll();

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionStop(_context));
            }
            _mockRepository.ReplayAll();

            function.Execute(_context);

            _mockRepository.VerifyAll();
        }
Ejemplo n.º 25
0
        public void SubCommit_OfDeletedObject_DoesNotRaiseDeletedEvent()
        {
            using (_subTransaction.EnterDiscardingScope())
            {
                ClassWithAllDataTypes domainObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();

                MockRepository repository = new MockRepository();

                IClientTransactionExtension extensionMock = repository.StrictMock <IClientTransactionExtension>();
                extensionMock.Stub(stub => stub.Key).Return("Mock");
                extensionMock.Replay();
                _subTransaction.Extensions.Add(extensionMock);
                try
                {
                    extensionMock.BackToRecord();

                    extensionMock.ObjectDeleting(_subTransaction, domainObject);
                    extensionMock.ObjectDeleted(_subTransaction, domainObject);

                    repository.ReplayAll();
                    domainObject.Delete();
                    repository.VerifyAll();

                    repository.BackToRecordAll();
                    extensionMock.Committing(null, null, null);
                    LastCall.IgnoreArguments();
                    extensionMock.CommitValidate(null, null);
                    LastCall.IgnoreArguments();
                    extensionMock.Committed(null, null);
                    LastCall.IgnoreArguments();
                    repository.ReplayAll();

                    _subTransaction.Commit();
                    repository.VerifyAll();
                }
                finally
                {
                    _subTransaction.Extensions.Remove("Mock");
                }
            }
        }
Ejemplo n.º 26
0
        public void Execute_WithPostBack()
        {
            _pageExecutorMock.Stub(stub => stub.ExecutePage(_wxeContext, "~/ThePage", false));
            _mockRepository.ReplayAll();
            _pageStep.Execute(_wxeContext);
            _mockRepository.BackToRecordAll();

            _pageExecutorMock.Expect(mock => mock.ExecutePage(_wxeContext, "~/ThePage", true)).WhenCalled(
                invocation =>
            {
                Assert.That(_pageStep.PostBackCollection, Is.Null);
                Assert.That(_pageStep.IsReturningPostBack, Is.False);
            });

            _mockRepository.ReplayAll();

            _pageStep.Execute(_wxeContext);

            _mockRepository.VerifyAll();
            Assert.That(_pageStep.IsPostBack, Is.True);
        }
Ejemplo n.º 27
0
        public void SetUp()
        {
            _mockRepository = new MockRepository();
            WxeContextFactory wxeContextFactory = new WxeContextFactory();

            _context = wxeContextFactory.CreateContext(new TestFunction());
            _outerTransactionStrategyMock = _mockRepository.StrictMock <TransactionStrategyBase> ();
            _parentTransactionMock        = _mockRepository.StrictMock <ITransaction>();
            _childTransactionMock         = _mockRepository.StrictMock <ITransaction> ();
            _executionContextStub         = _mockRepository.Stub <IWxeFunctionExecutionContext> ();
            _executionListenerStub        = _mockRepository.Stub <IWxeFunctionExecutionListener> ();

            _executionContextStub.Stub(stub => stub.GetInParameters()).Return(new object[0]);
            _parentTransactionMock.Stub(stub => stub.CreateChild()).Return(_childTransactionMock);
            _childTransactionMock.Stub(stub => stub.EnsureCompatibility(Arg <IEnumerable> .Is.NotNull));
            _mockRepository.ReplayAll();

            _strategy = new ChildTransactionStrategy(true, _outerTransactionStrategyMock, _parentTransactionMock, _executionContextStub);

            _mockRepository.BackToRecordAll();
        }
Ejemplo n.º 28
0
        public void FirstTextBufferIsEmpty_Backward()
        {
            MockRepository repo = new MockRepository();

            var capt = new TextMessageCapture();

            int aveBufSize = 100;

            ITextAccess         ta = repo.CreateMock <ITextAccess>();
            ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>();

            Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3);
            Expect.Call(ta.AverageBufferLength).Return(aveBufSize);
            repo.ReplayAll();
            MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None), MessagesSplitterFlags.PreventBufferUnderflow);

            repo.VerifyAll();

            //        _abc
            //        ||  |
            // pos:  11|  15
            //         12
            repo.BackToRecordAll();
            Expect.Call(ta.OpenIterator(15, TextAccessDirection.Forward)).Return(it);
            Expect.Call(it.CurrentBuffer).Return("");
            Expect.Call(it.PositionToCharIndex(15)).Return(0);             // querying past-the end position is allowed
            Expect.Call(it.Advance(0)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return("_abc");
                Expect.Call(it.CharIndexToPosition(1)).Return((long)12);
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(10, 20), 15, MessagesParserDirection.Forward);
            repo.VerifyAll();
            Assert.IsFalse(target.CurrentMessageIsEmpty);
        }
Ejemplo n.º 29
0
        public void CanUseBackToRecordOnMethodsThatCallPropertyBehavior()
        {
            MockRepository repository = new MockRepository();
            TestClass mock = repository.StrictMock<TestClass>();

            Expect.Call(mock.Id).PropertyBehavior();

            repository.ReplayAll();
            mock.Id = 4;
            int d = mock.Id;
            Assert.Equal(4,d );
            repository.VerifyAll();

            repository.BackToRecordAll();

            Expect.Call(mock.Id).Return(5);

            repository.ReplayAll();

            Assert.Equal(5, mock.Id);

            repository.VerifyAll();
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Uses the given delegate to invoke the object, checking all the expectations previously set up,
        /// and then clearing them for continued testing.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="doSomething"></param>
        public void Go(MessageContext context, Action doSomething)
        {
            using (m.Record())
            {
                foreach (var t in messageTypes)
                {
                    GetType().GetMethod("PrepareBusGenericMethods", BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(t).Invoke(this, null);
                }

                SetupResult.For(bus.CurrentMessageContext).Return(context);

                foreach (var d in delegates)
                {
                    d.DynamicInvoke();
                }
            }

            using (m.Playback())
                doSomething();

            m.BackToRecordAll();

            delegates.Clear();
        }
Ejemplo n.º 31
0
        public void CanUseBackToRecordOnMethodsThatCallPropertyBehavior()
        {
            MockRepository repository = new MockRepository();
            TestClass      mock       = repository.StrictMock <TestClass>();

            Expect.Call(mock.Id).PropertyBehavior();

            repository.ReplayAll();
            mock.Id = 4;
            int d = mock.Id;

            Assert.Equal(4, d);
            repository.VerifyAll();

            repository.BackToRecordAll();

            Expect.Call(mock.Id).Return(5);

            repository.ReplayAll();

            Assert.Equal(5, mock.Id);

            repository.VerifyAll();
        }
Ejemplo n.º 32
0
        public void CanUseBackToRecordOnMethodsThatCallToCallOriginalMethod()
        {
            MockRepository repository = new MockRepository();
            TestClass mock = repository.StrictMock<TestClass>();

            mock.Method();
            LastCall.CallOriginalMethod
                (OriginalCallOptions.NoExpectation);

            repository.ReplayAll();
            mock.Method();
            repository.VerifyAll();

            repository.BackToRecordAll();

            mock.Method();
            LastCall.Throw(new ApplicationException());

            repository.ReplayAll();

            try
            {
                mock.Method();
                Assert.False(true);
            }
            catch
            {
            }
            repository.VerifyAll();
        }
Ejemplo n.º 33
0
 public void TearDown()
 {
     _mock.BackToRecordAll();
 }
Ejemplo n.º 34
0
 public void CanCallBackToRecordAllWhenRepositoryIsEmpty()
 {
     MockRepository mocks = new MockRepository();
     mocks.BackToRecordAll();
 }