예제 #1
0
        public void Setup()
        {
            _mocks = new MockRepository();

            _mockTabbedMenu = _mocks.PartialMock <TabbedMenu>();

            _mockNavigationCommand1 = _mocks.PartialMock <NavigationCommand>();
            _mocks.Replay(_mockNavigationCommand1);

            _mockNavigationCommand2 = _mocks.PartialMock <NavigationCommand>();
            _mocks.Replay(_mockNavigationCommand2);

            _mainMenuTab              = new MainMenuTab();
            _mainMenuTab.ItemID       = "MainMenuTab";
            _mainMenuTab.Command.Type = CommandType.None;
            _mainMenuTab.OwnerControl = _mockTabbedMenu;

            _mockSubMenuTab1 = CreateSubMenuTab("SubMenuTab1", _mockNavigationCommand1);
            _mainMenuTab.SubMenuTabs.Add(_mockSubMenuTab1);

            _mockSubMenuTab2 = CreateSubMenuTab("SubMenuTab2", _mockNavigationCommand2);
            _mainMenuTab.SubMenuTabs.Add(_mockSubMenuTab2);

            _mocks.BackToRecord(_mockSubMenuTab1);
            _mocks.BackToRecord(_mockSubMenuTab2);
            _mocks.BackToRecord(_mockNavigationCommand1);
            _mocks.BackToRecord(_mockNavigationCommand2);
        }
예제 #2
0
        public void T001_SavingShouldNotInvalidateOtherCachedSingleObjects()
        {
            m_objMockRepository.BackToRecord(m_objIApplication);
            m_objMockRepository.BackToRecord(m_objIMetricBroker);
            long    lOtherID         = 200;
            DataSet objDSOtherMetric = new DataSet();

            using (m_objMockRepository.Ordered())
            {
                Rhino.Mocks.Expect.Call(m_objIApplication.IMetricBroker).Return(m_objIMetricBroker);
                Rhino.Mocks.Expect.Call(m_objIMetricBroker.FetchMetric(lOtherID)).Return(objDSOtherMetric);
            }
            m_objMockRepository.ReplayAll();

            IMetric objOtherMetric = Metric.GetByID(m_objIApplication, lOtherID);

            m_objMockRepository.VerifyAll();

            m_objMockRepository.BackToRecord(m_objIApplication);
            m_objMockRepository.BackToRecord(m_objIMetricBroker);

            m_objMockRepository.ReplayAll();
            //missing expectations here.

            //cause a stack overflow error

            Assert.Throws <ExpectationViolationException>("IApplicationSession.get_IMetricBroker(); Expected #0, Actual #1.",
                                                          () =>
            {
                IMetric objMetric = m_objIMetric.Numerator;
            });
        }
예제 #3
0
        private void CheckDelegation(string methodName, params Expression[] expressions)
        {
            var visitorMock = MockRepository.StrictMock <RelinqExpressionVisitor>();

            MethodInfo methodToBeCalled = visitorMock.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(methodToBeCalled, Is.Not.Null);

            foreach (Expression expression in expressions)
            {
                MockRepository.BackToRecord(visitorMock);
                Expect.Call(visitorMock.Visit(expression)).CallOriginalMethod(OriginalCallOptions.CreateExpectation);

                MethodInfo methodToBeCalledWithoutGenericParameters;
                if (methodToBeCalled.ContainsGenericParameters)
                {
                    methodToBeCalledWithoutGenericParameters = methodToBeCalled.MakeGenericMethod(expression.GetType().GetGenericArguments());
                }
                else
                {
                    methodToBeCalledWithoutGenericParameters = methodToBeCalled;
                }

                Expect.Call(methodToBeCalledWithoutGenericParameters.Invoke(visitorMock, new object[] { expression })).Return(expression);

                MockRepository.Replay(visitorMock);

                object result = visitorMock.Visit(expression);
                Assert.That(result, Is.SameAs(expression));
                MockRepository.Verify(visitorMock);
            }
        }
예제 #4
0
        private void SetupWizardController(bool useCurrentRouteForRedirects)
        {
            helper.WizardController = repository.DynamicMock <IWizardController>();
            SetupResult.For(helper.WizardController.UseCurrentRouteForRedirects).Return(useCurrentRouteForRedirects);
            repository.Replay(helper.WizardController);

            if (useCurrentRouteForRedirects)
            {
                repository.BackToRecord(controllerContext, BackToRecordOptions.None);
                var routeMatch = new RouteMatch();
                routeMatch.AddNamed("manufacturer", "Ford");
                routeMatch.AddNamed("model", "Falcon");
                SetupResult.For(controllerContext.RouteMatch).Return(routeMatch);
                SetupResult.For(controllerContext.AreaName).Return("Cars");
                repository.Replay(controllerContext);

                var routingEngine = new RoutingEngine();
                routingEngine.Add(
                    new PatternRoute("/<area>/<manufacturer>/AddOptionsWizard/<model>/[action]")
                    .DefaultForController().Is("AddOptionsWizardController")
                    .DefaultForAction().Is("start"));
                helper.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), routingEngine);
                helper.CurrentUrl = new UrlInfo("Cars", "CarsController", "View", String.Empty, "rails");
                helper.UrlBuilder.UseExtensions = false;
            }
        }
예제 #5
0
        public void CanClearOnlyOriginalMethodCalls()
        {
            MockRepository mocks = new MockRepository();
            AbstractClass abstractClass = mocks.StrictMock<AbstractClass>();
            Expect.Call(abstractClass.Add(0)).CallOriginalMethod(OriginalCallOptions.NoExpectation);
            mocks.BackToRecord(abstractClass, BackToRecordOptions.OriginalMethodsToCall);
            mocks.ReplayAll();

            abstractClass.Add(5);
        }
예제 #6
0
        public void CacheOnlyItemsOfMethodThatReturnsCollection()
        {
            MethodInfo method = new EnumerableResultMethod(cacheResultTarget.ReturnsItems).Method;
            object     expectedReturnValue = new object[] { "one", "two", "three" };

            mocks.Record();

            ExpectAttributeRetrieval(method);
            ExpectCacheKeyGeneration(method, 5, expectedReturnValue);
            ExpectCallToProceed(new object[] { "one", "two", "three" });
            ExpectCacheInstanceRetrieval("items", itemCache);

            mocks.ReplayAll();

            // return value should be added to result cache and each item to item cache
            object returnValue = advice.Invoke(mockInvocation);

            Assert.AreEqual(expectedReturnValue, returnValue);
            Assert.AreEqual(0, resultCache.Count);
            Assert.AreEqual(3, itemCache.Count);

            mocks.Verify(mockInvocation);

            mocks.BackToRecord(mockInvocation);

            ExpectAttributeRetrieval(method);
            ExpectCallToProceed(new object[] { "one", "two", "three" });
            ExpectCacheKeyGeneration(method, 5, expectedReturnValue);

            mocks.Replay(mockInvocation);

            object newReturnValue = advice.Invoke(mockInvocation);

            Assert.AreEqual(expectedReturnValue, newReturnValue);
            Assert.AreEqual(0, resultCache.Count);
            Assert.AreEqual(3, itemCache.Count);
            Assert.AreEqual("two", itemCache.Get("two"));
            Assert.AreNotSame(returnValue, newReturnValue);

            mocks.VerifyAll();
        }
예제 #7
0
        public void CanClearOnlyOriginalMethodCalls()
        {
            MockRepository mocks = new MockRepository();
            AbstractClass abstractClass = mocks.StrictMock<AbstractClass>();
            Expect.Call(abstractClass.Add(0)).CallOriginalMethod(OriginalCallOptions.NoExpectation);
            mocks.BackToRecord(abstractClass, BackToRecordOptions.OriginalMethodsToCall);
            mocks.ReplayAll();

            Assert.Throws<ExpectationViolationException>(
                "AbstractClass.Add(5); Expected #0, Actual #1.",
                () => abstractClass.Add(5));
        }
예제 #8
0
        /// <summary>
        /// Expect last (property) call as property setting, ignore the argument given
        /// </summary>
        /// <returns></returns>
        public IMethodOptions <T> SetPropertyAndIgnoreArgument()
        {
            bool isInReplayMode = repository.IsInReplayMode(proxy);

            if (isInReplayMode)
            {
                repository.BackToRecord(proxy, BackToRecordOptions.None);
            }
            expectation.ReturnValue = default(T);
            MethodInfo setter = PropertySetterFromMethod(expectation.Method);

            repository.Recorder.RemoveExpectation(expectation);
            setter.Invoke(proxy, new object[] { default(T) });
            IMethodOptions <T> methodOptions = repository.LastMethodCall <T>(proxy).IgnoreArguments();

            if (isInReplayMode)
            {
                repository.ReplayCore(proxy, true);
            }
            return(methodOptions);
        }
예제 #9
0
        public void CanClearOnlyPropertyBehavior()
        {
            MockRepository mocks = new MockRepository();
            IDemo mock = mocks.StrictMock<IDemo>();
            Expect.Call(mock.Prop).PropertyBehavior();

            mocks.BackToRecord(mock,BackToRecordOptions.PropertyBehavior);

            mocks.ReplayAll();

            string prop = mock.Prop;
        }
 public void UsingBackToRecordWithSetUpResult()
 {
     MockRepository mocks = new MockRepository();
     IDemo demo = (IDemo) mocks.StrictMock(typeof(IDemo));
     SetupResult.For(demo.Prop).Return("Here is 1 sample greeting");
     mocks.Replay(demo);
     Assert.Equal("Here is 1 sample greeting",demo.Prop);
     mocks.BackToRecord(demo);
     SetupResult.For(demo.Prop).Return("Here is another sample greeting");
     mocks.Replay(demo);
     Assert.Equal("Here is another sample greeting", demo.Prop);
     mocks.VerifyAll();
 }
예제 #11
0
        public void CanClearOnlyOriginalMethodCalls()
        {
            MockRepository mocks         = new MockRepository();
            AbstractClass  abstractClass = mocks.StrictMock <AbstractClass>();

            Expect.Call(abstractClass.Add(0)).CallOriginalMethod(OriginalCallOptions.NoExpectation);
            mocks.BackToRecord(abstractClass, BackToRecordOptions.OriginalMethodsToCall);
            mocks.ReplayAll();

            Assert.Throws <ExpectationViolationException>(
                "AbstractClass.Add(5); Expected #0, Actual #1.",
                () => abstractClass.Add(5));
        }
예제 #12
0
 public void CanMoveToRecordAndThenReplay()
 {
     MockRepository mocks = new MockRepository();
     IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo));
     Expect.Call(demo.Prop).Return("ayende");
     mocks.Replay(demo);
     Assert.AreEqual("ayende", demo.Prop);
     mocks.BackToRecord(demo);
     Expect.Call(demo.Prop).Return("rahien");
     mocks.Replay(demo);
     Assert.AreEqual("rahien", demo.Prop);
     mocks.VerifyAll();
 }
예제 #13
0
        public void CanMoveToRecordAndThenReplay()
        {
            MockRepository mocks = new MockRepository();
            IDemo          demo  = (IDemo)mocks.StrictMock(typeof(IDemo));

            Expect.Call(demo.Prop).Return("ayende");
            mocks.Replay(demo);
            Assert.Equal("ayende", demo.Prop);
            mocks.BackToRecord(demo);
            Expect.Call(demo.Prop).Return("rahien");
            mocks.Replay(demo);
            Assert.Equal("rahien", demo.Prop);
            mocks.VerifyAll();
        }
        public void UsingBackToRecordWithSetUpResult()
        {
            MockRepository mocks = new MockRepository();
            IDemo          demo  = (IDemo)mocks.StrictMock(typeof(IDemo));

            SetupResult.For(demo.Prop).Return("Here is 1 sample greeting");
            mocks.Replay(demo);
            Assert.Equal("Here is 1 sample greeting", demo.Prop);
            mocks.BackToRecord(demo);
            SetupResult.For(demo.Prop).Return("Here is another sample greeting");
            mocks.Replay(demo);
            Assert.Equal("Here is another sample greeting", demo.Prop);
            mocks.VerifyAll();
        }
예제 #15
0
        public void SetUp()
        {
            templateDir = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\Sneal.SqlMigration\Templates";

            mocks           = new MockRepository();
            templateManager = mocks.DynamicMock <ISqlTemplateManager>();

            SetupResult.For(templateManager.TemplateDirectory).Return(templateDir);
            mocks.Replay(templateManager);
            scriptBuilder = new SqlServerScriptBuilder(templateManager);
            mocks.BackToRecord(templateManager);

            db    = new DatabaseStub("DB");
            table = new TableStub(db, "Customer");
        }
예제 #16
0
        public void CanSpecifyClearOnlyEvents()
        {
            MockRepository mocks     = new MockRepository();
            IWithEvent     withEvent = mocks.StrictMock <IWithEvent>();
            bool           called    = false;

            withEvent.Load += delegate { called = true; };
            IEventRaiser raiser = LastCall.GetEventRaiser();

            mocks.BackToRecord(withEvent, BackToRecordOptions.EventSubscribers);

            raiser.Raise(this, EventArgs.Empty);

            Assert.False(called);
        }
예제 #17
0
        public void CanClearOnlyPropertyBehavior()
        {
            MockRepository mocks = new MockRepository();
            IDemo mock = mocks.StrictMock<IDemo>();
            Expect.Call(mock.Prop).PropertyBehavior();

            mocks.BackToRecord(mock,BackToRecordOptions.PropertyBehavior);

            mocks.ReplayAll();

            Assert.Throws<ExpectationViolationException>("IDemo.get_Prop(); Expected #0, Actual #1.", delegate
            {
                string prop = mock.Prop;
            });
        }
예제 #18
0
        public void CanClearOnlyPropertyBehavior()
        {
            MockRepository mocks = new MockRepository();
            IDemo          mock  = mocks.StrictMock <IDemo>();

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

            mocks.BackToRecord(mock, BackToRecordOptions.PropertyBehavior);

            mocks.ReplayAll();

            Assert.Throws <ExpectationViolationException>("IDemo.get_Prop(); Expected #0, Actual #1.", delegate
            {
                string prop = mock.Prop;
            });
        }
예제 #19
0
        public void CanMoveToRecordFromVerifiedWithoutClearingExpectations()
        {
            MockRepository mocks = new MockRepository();
            IDemo          mock  = mocks.StrictMock <IDemo>();

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mock.VoidNoArgs();
            mocks.VerifyAll();

            mocks.BackToRecord(mock, BackToRecordOptions.None);
            mock.VoidNoArgs();
            mocks.ReplayAll();

            mock.VoidNoArgs();
            mocks.VerifyAll();
        }
        public void BackToRecordOnADynamicMock()
        {
            MockRepository repository = new MockRepository();
            ITest          test       = (ITest)repository.DynamicMock(typeof(ITest));

            test.DoSomething(1);

            repository.BackToRecord(test);

            test.DoSomething(2);

            repository.ReplayAll();

            test.DoSomething(2);
            test.DoSomething(3);

            repository.VerifyAll();
        }
        public void BackToRecordOnADynamicMock()
        {
            MockRepository repository = new MockRepository();
            ITest test = (ITest)repository.DynamicMock(typeof(ITest));

            test.DoSomething(1);

            repository.BackToRecord(test);

            test.DoSomething(2);

            repository.ReplayAll();

            test.DoSomething(2);
            test.DoSomething(3);

            repository.VerifyAll();
        }
예제 #22
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);
        }
예제 #23
0
        public void CanMoveToRecordFromReplyWithoutClearingExpectations()
        {
            MockRepository mocks = new MockRepository();
            IDemo          mock  = mocks.StrictMock <IDemo>();

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mocks.BackToRecord(mock, BackToRecordOptions.None);

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mock.VoidNoArgs();

            Assert.Throws <ExpectationViolationException>(
                "IDemo.VoidNoArgs(); Expected #1, Actual #0.",
                () => mocks.VerifyAll());
        }
예제 #24
0
        private void CheckDelegation(string methodName, params Expression[] expressions)
        {
            var visitorMock = MockRepository.StrictMock <ExpressionTreeVisitor>();

            MethodInfo methodToBeCalled = visitorMock.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(methodToBeCalled, Is.Not.Null);

            foreach (Expression expression in expressions)
            {
                MockRepository.BackToRecord(visitorMock);
                Expect.Call(visitorMock.VisitExpression(expression)).CallOriginalMethod(OriginalCallOptions.CreateExpectation);
                Expect.Call(methodToBeCalled.Invoke(visitorMock, new object[] { expression })).Return(expression);

                MockRepository.Replay(visitorMock);

                object result = visitorMock.VisitExpression(expression);
                Assert.That(result, Is.SameAs(expression));
                MockRepository.Verify(visitorMock);
            }
        }
예제 #25
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);
        }
예제 #26
0
        public void MessageIsReadBecauseItEndsRightAfterTheBeginningOfTheRange_Backward()
        {
            MockRepository repo = new MockRepository();

            // reading from position 11 with range 5-15
            //   _msg1_msg2_msg3
            //    |   |     |   |
            //    1   5     11  15
            // range begins at pos 5. msg1_ ends at pos 6 (its past-the-end position = 6). msg1_ must 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(5, 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);             // in backward mode the first message that was read is "IsLastMessage"
            Assert.IsFalse(target.CurrentMessageIsEmpty);

            repo.BackToRecordAll();
            Expect.Call(it.Advance(9)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return("_msg1_");
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("msg", capt.MessageHeader);
            Assert.AreEqual("1_", capt.MessageBody);
            Assert.AreEqual(1L, capt.BeginPosition);
            Assert.AreEqual(6L, capt.EndPosition);
            Assert.IsFalse(capt.IsLastMessage);
            Assert.IsTrue(target.CurrentMessageIsEmpty);

            repo.BackToRecordAll();
            repo.ReplayAll();
            Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
        }
예제 #27
0
        public void Init_Upgrade()
        {
            string testDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());

            Directory.CreateDirectory(testDir);

            MockRepository mocks = new MockRepository();
            IHostV30       host  = mocks.DynamicMock <IHostV30>();

            Expect.Call(host.GetSettingValue(SettingName.PublicDirectory)).Return(testDir).Repeat.AtLeastOnce();

            Expect.Call(host.UpgradePageStatusToAcl(null, 'L')).IgnoreArguments().Repeat.Twice().Return(true);

            mocks.Replay(host);

            string file              = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Pages.cs");
            string categoriesFile    = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Categories.cs");
            string navPathsFile      = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "NavigationPaths.cs");
            string directory         = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Pages");
            string messagesDirectory = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Messages");

            Directory.CreateDirectory(directory);
            Directory.CreateDirectory(messagesDirectory);

            // Structure (Keywords and Description are new in v3)
            // Page Title
            // Username|DateTime[|Comment] --- Comment is optional
            // ##PAGE##
            // Content...

            File.WriteAllText(Path.Combine(directory, "Page1.cs"), "Title1\r\nSYSTEM|2008/10/30 20:20:20|Comment\r\n##PAGE##\r\nContent...");
            File.WriteAllText(Path.Combine(directory, "Page2.cs"), "Title2\r\nSYSTEM|2008/10/30 20:20:20\r\n##PAGE\r\nContent. [[Page.3]] [Page.3|Link to update].");
            File.WriteAllText(Path.Combine(directory, "Page.3.cs"), "Title3\r\nSYSTEM|2008/10/30 20:20:20|Comment\r\n##PAGE\r\nContent...");

            // ID|Username|Subject|DateTime|ParentID|Body
            File.WriteAllText(Path.Combine(messagesDirectory, "Page.3.cs"), "0|User|Hello|2008/10/30 21:21:21|-1|Blah\r\n");

            // Structure
            // [Namespace.]PageName|PageFile|Status|DateTime
            File.WriteAllText(file, "Page1|Page1.cs|NORMAL|2008/10/30 20:20:20\r\nPage2|Page2.cs|PUBLIC\r\nPage.3|Page.3.cs|LOCKED");

            File.WriteAllText(categoriesFile, "Cat1|Page.3\r\nCat.2|Page1|Page2\r\n");

            File.WriteAllText(navPathsFile, "Path1|Page1|Page.3\r\nPath2|Page2\r\n");

            PagesStorageProvider prov = new PagesStorageProvider();

            prov.Init(host, "");

            PageInfo[] pages = prov.GetPages(null);

            Assert.AreEqual(3, pages.Length, "Wrong page count");
            Assert.AreEqual("Page1", pages[0].FullName, "Wrong name");
            Assert.AreEqual("Page2", pages[1].FullName, "Wrong name");
            Assert.AreEqual("Page_3", pages[2].FullName, "Wrong name");
            //Assert.IsFalse(prov.GetContent(pages[1]).Content.Contains("Page.3"), "Content should not contain 'Page.3'");
            //Assert.IsTrue(prov.GetContent(pages[1]).Content.Contains("Page_3"), "Content should contain 'Page_3'");

            Message[] messages = prov.GetMessages(pages[2]);
            Assert.AreEqual(1, messages.Length, "Wrong message count");
            Assert.AreEqual("Hello", messages[0].Subject, "Wrong subject");

            CategoryInfo[] categories = prov.GetCategories(null);

            Assert.AreEqual(2, categories.Length, "Wrong category count");
            Assert.AreEqual("Cat1", categories[0].FullName, "Wrong name");
            Assert.AreEqual(1, categories[0].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page_3", categories[0].Pages[0], "Wrong page");
            Assert.AreEqual("Cat_2", categories[1].FullName, "Wrong name");
            Assert.AreEqual(2, categories[1].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page1", categories[1].Pages[0], "Wrong page");
            Assert.AreEqual("Page2", categories[1].Pages[1], "Wrong page");

            NavigationPath[] navPaths = prov.GetNavigationPaths(null);

            Assert.AreEqual(2, navPaths.Length, "Wrong nav path count");
            Assert.AreEqual("Path1", navPaths[0].FullName, "Wrong name");
            Assert.AreEqual(2, navPaths[0].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page1", navPaths[0].Pages[0], "Wrong page");
            Assert.AreEqual("Page_3", navPaths[0].Pages[1], "Wrong page");
            Assert.AreEqual(1, navPaths[1].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page2", navPaths[1].Pages[0], "Wrong page");

            mocks.Verify(host);

            // Simulate another startup - upgrade not needed anymore

            mocks.BackToRecord(host);
            Expect.Call(host.GetSettingValue(SettingName.PublicDirectory)).Return(testDir).Repeat.AtLeastOnce();
            Expect.Call(host.UpgradePageStatusToAcl(null, 'L')).IgnoreArguments().Repeat.Times(0).Return(false);

            mocks.Replay(host);

            prov = new PagesStorageProvider();
            prov.Init(host, "");

            mocks.Verify(host);

            Directory.Delete(testDir, true);
        }
예제 #28
0
        public void CanMoveToRecordFromReplyWithoutClearingExpectations()
        {
            MockRepository mocks = new MockRepository();
            IDemo mock = mocks.StrictMock<IDemo>();

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mocks.BackToRecord(mock, BackToRecordOptions.None);

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mock.VoidNoArgs();

            mocks.VerifyAll();
        }
예제 #29
0
        public void CanMoveToRecordFromReplyWithoutClearingExpectations()
        {
            MockRepository mocks = new MockRepository();
            IDemo mock = mocks.StrictMock<IDemo>();

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mocks.BackToRecord(mock, BackToRecordOptions.None);

            mock.VoidNoArgs();
            mocks.ReplayAll();

            mock.VoidNoArgs();

            string expectedMessage = "IDemo.VoidNoArgs(); Expected #1, Actual #0.";
            ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>(
                            () => mocks.VerifyAll());
            Assert.Equal(expectedMessage, ex.Message);
        }
예제 #30
0
        public void OneToOneRelationFromVirtualEndPointWithOldNull()
        {
            Order       order       = Order.NewObject();
            OrderTicket orderTicket = OrderTicket.NewObject();

            _mockRepository.BackToRecord(_extension);

            var orderEventReceiver       = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (order);
            var orderTicketEventReceiver = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (orderTicket);

            using (_mockRepository.Ordered())
            {
                _extension.RelationChanging(
                    TestableClientTransaction, order, GetEndPointDefinition(typeof(Order), "OrderTicket"), null, orderTicket);
                orderEventReceiver.RelationChanging(GetEndPointDefinition(typeof(Order), "OrderTicket"), null, orderTicket);

                _extension.RelationChanging(
                    TestableClientTransaction, orderTicket, GetEndPointDefinition(typeof(OrderTicket), "Order"), null, order);
                orderTicketEventReceiver.RelationChanging(GetEndPointDefinition(typeof(OrderTicket), "Order"), null, order);

                orderTicketEventReceiver.RelationChanged(GetEndPointDefinition(typeof(OrderTicket), "Order"), null, order);
                _extension.RelationChanged(TestableClientTransaction, orderTicket, GetEndPointDefinition(typeof(OrderTicket), "Order"), null, order);

                orderEventReceiver.RelationChanged(GetEndPointDefinition(typeof(Order), "OrderTicket"), null, orderTicket);
                _extension.RelationChanged(TestableClientTransaction, order, GetEndPointDefinition(typeof(Order), "OrderTicket"), null, orderTicket);
            }

            _mockRepository.ReplayAll();

            order.OrderTicket = orderTicket;

            _mockRepository.VerifyAll();
        }
예제 #31
0
        public void CanSpecifyClearOnlyEvents()
        {
            MockRepository mocks = new MockRepository();
            IWithEvent withEvent = mocks.StrictMock<IWithEvent>();
            bool called = false;
            withEvent.Load += delegate { called = true; };
            IEventRaiser raiser = LastCall.GetEventRaiser();
            mocks.BackToRecord(withEvent, BackToRecordOptions.EventSubscribers);

            raiser.Raise(this, EventArgs.Empty);

            Assert.IsFalse(called);
        }
예제 #32
0
        public void GetCurrentMessageAndMoveToNextOne_MainScenario_Backward()
        {
            MockRepository repo = new MockRepository();


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

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

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

            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length));
            Assert.AreEqual(" 3498", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength));
            Assert.AreEqual(85L, capt.BeginPosition);
            Assert.AreEqual(100L, capt.EndPosition);
            Assert.IsTrue(capt.IsLastMessage);
            Assert.IsFalse(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            Expect.Call(it.Advance(8)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return(
                    "11 abc 123456 abc 283147948 ");
                //  |  |  |       |  |         |
                //  0  3  6       14 17        27   - char idx
                //  20 33 50      61 67        85   - positions
                Expect.Call(it.CharIndexToPosition(3)).Return((long)33);
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length));
            Assert.AreEqual(" 283147948 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength));
            Assert.AreEqual(61L, capt.BeginPosition);
            Assert.AreEqual(85L, capt.EndPosition);
            Assert.IsFalse(capt.IsLastMessage);
            Assert.IsFalse(target.CurrentMessageIsEmpty);



            repo.BackToRecordAll();
            Expect.Call(it.Advance(14)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return(
                    "11 abc 123456 ");
                //  |  |  |       |
                //  0  3  6       13 - char idx
                //  20 33         61 - pos
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length));
            Assert.AreEqual(" 123456 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength));
            Assert.AreEqual(33L, capt.BeginPosition);
            Assert.AreEqual(61L, capt.EndPosition);
            Assert.IsFalse(capt.IsLastMessage);
            Assert.IsTrue(target.CurrentMessageIsEmpty);



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



            repo.BackToRecordAll();
            it.Dispose(); Expect.On(it);
            repo.ReplayAll();
            target.EndSplittingSession();
            repo.VerifyAll();
        }
예제 #33
0
        public void GetCurrentMessageAndMoveToNextOne_MainScenario_Forward()
        {
            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(0, TextAccessDirection.Forward)).Return(it);
            Expect.Call(it.PositionToCharIndex(0)).Return(0);
            Expect.Call(it.CurrentBuffer).Return(
                "123456 abc 283147948 abc 3498");
            // |      |  |          |  |   |
            // 0      7  10         21 24  28 - char idx
            // 0      8  16         45 56  67 - positions
            Expect.Call(it.CharIndexToPosition(7)).Return((long)8);
            repo.ReplayAll();
            target.BeginSplittingSession(new Range(0, 100), 0, MessagesParserDirection.Forward);
            repo.VerifyAll();
            Assert.IsFalse(target.CurrentMessageIsEmpty);


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

            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length));
            Assert.AreEqual(" 283147948 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength));
            Assert.AreEqual(8L, capt.BeginPosition);
            Assert.AreEqual(45L, capt.EndPosition);
            Assert.IsFalse(capt.IsLastMessage);
            Assert.IsFalse(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            Expect.Call(it.Advance(24)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return(
                    " 3498 abc 2626277");
                //  |     |  |
                //  0     6  9           - char idx
                //  56    72 81          - position
                Expect.Call(it.CharIndexToPosition(6)).Return((long)72);
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length));
            Assert.AreEqual(" 3498 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength));
            Assert.AreEqual(45L, capt.BeginPosition);
            Assert.AreEqual(72L, capt.EndPosition);
            Assert.IsFalse(capt.IsLastMessage);
            Assert.IsFalse(target.CurrentMessageIsEmpty);


            repo.BackToRecordAll();
            Expect.Call(it.Advance(9)).Repeat.Once().Do((Predicate <int>) delegate(int i)
            {
                repo.Verify(it);
                repo.BackToRecord(it);
                Expect.Call(it.CurrentBuffer).Return(
                    " 2626277");
                // |       |
                // 0       8 - char idx
                // 81      90  - position
                Expect.Call(it.CharIndexToPosition(8)).Return((long)90);
                repo.Replay(it);
                return(true);
            });
            repo.ReplayAll();
            Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt));
            repo.VerifyAll();
            Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length));
            Assert.AreEqual(" 2626277", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength));
            Assert.AreEqual(72L, capt.BeginPosition);
            Assert.AreEqual(90L, capt.EndPosition);
            Assert.IsTrue(capt.IsLastMessage);
            Assert.IsTrue(target.CurrentMessageIsEmpty);


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


            repo.BackToRecordAll();
            it.Dispose(); Expect.On(it);
            repo.ReplayAll();
            target.EndSplittingSession();
            repo.VerifyAll();
        }
예제 #34
0
        public void RollbackWithDomainObject()
        {
            _order1.DeliveryDate = DateTime.Now;
            _mockRepository.BackToRecord(_order1MockEventReceiver);
            _mockRepository.BackToRecord(_clientTransactionExtensionMock);

            using (_mockRepository.Ordered())
            {
                _clientTransactionExtensionMock.RollingBack(null, null);
                LastCall.Constraints(Is.Same(TestableClientTransaction), Property.Value("Count", 1) & List.IsIn(_order1));

                _clientTransactionMockEventReceiver.RollingBack(_order1);

                _order1MockEventReceiver.RollingBack(null, null);
                LastCall.Constraints(Is.Same(_order1), Is.NotNull());

                _order1MockEventReceiver.RolledBack(null, null);
                LastCall.Constraints(Is.Same(_order1), Is.NotNull());

                _clientTransactionMockEventReceiver.RolledBack(_order1);

                _clientTransactionExtensionMock.RolledBack(null, null);
                LastCall.Constraints(Is.Same(TestableClientTransaction), Property.Value("Count", 1) & List.IsIn(_order1));
            }

            _mockRepository.ReplayAll();

            TestableClientTransaction.Rollback();

            _mockRepository.VerifyAll();
        }