public void HasReached_GenerationNumberLowerThanCondition_False()
        {
            var repository = new MockRepository();
            var ga = repository.StrictMock<IGeneticAlgorithm>();

            using (repository.Ordered())
            {
                ga.Expect(g => g.GenerationsNumber).Return(1);
                ga.Expect(g => g.GenerationsNumber).Return(2);
                ga.Expect(g => g.GenerationsNumber).Return(3);
                ga.Expect(g => g.GenerationsNumber).Return(4);
                ga.Expect(g => g.GenerationsNumber).Return(5);
                ga.Expect(g => g.GenerationsNumber).Return(6);
                ga.Expect(g => g.GenerationsNumber).Return(7);
                ga.Expect(g => g.GenerationsNumber).Return(8);
                ga.Expect(g => g.GenerationsNumber).Return(0);
            }
            repository.ReplayAll();

            var target = new GenerationNumberTermination(10);
            Assert.IsFalse(target.HasReached(ga));

            for (int i = 0; i < 8; i++)
            {
                Assert.IsFalse(target.HasReached(ga));
            }

        }
        public void testArrayWithfunction()
        {
            string classname = "TestClassName";
            string json = @"{@class:'" + classname+ @"',
             id:'123',
            objectListPropA:null,
            intListPropB:    _a_([3, 4, 5])  }";
            var mocks = new MockRepository();
            var theMock = mocks.StrictMock<JsonExploreListener>();
            RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
            Console.WriteLine("***testArrayWithfunction json: " + json);

            using (mocks.Ordered())
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("@class", classname, true);
                theMock.JsonLeaf("id", "123", true);
                theMock.JsonLeaf("objectListPropA", null, false);
                theMock.JsonStartFunction("_a_", json.IndexOf("("), "intListPropB" );
                theMock.JsonStartArray(null, json.IndexOf("["));
                theMock.JsonLeaf(null, "3", false);
                theMock.JsonLeaf(null, "4", false);
                theMock.JsonLeaf(null, "5", false);
                theMock.JsonEndArray(json.IndexOf("]"));
                theMock.JsonEndFunction(json.IndexOf(")"));
                theMock.JsonEndObject(json.IndexOf("}"));
            }
            theMock.Replay();

            JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
            jsonExplorerImpl.explore(json, theMock);

            //todo - verify expectations
        }
		public void WillInitializeAllModuleLoadersOnStart()
		{

			MockRepository mocks = new MockRepository();
			IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
			IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
			IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
			IShellView stubShell = mocks.Stub<IShellView>();
			DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
				stubShell, new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });

			using (mocks.Record())
			{
				//we may have order dependnecies, let us verify
				//that it does this in order
				using (mocks.Ordered())
				{
					mockLoader1.Initialize(context, stubShell);
					mockLoader2.Initialize(context, stubShell);
					mockLoader3.Initialize(context, stubShell);
				}

				//force context to ignore these calls
				Expect.Call(context.GetShellAsForm()).Return(null).Repeat.Once();
				Expect.Call(delegate { context.RunForm(null); }).Repeat.Once();
			}

			using (mocks.Playback())
			{
				context.Start();
			}
		}
        public void Complete_Doesnt_Save_Task_If_No_Change()
        {
            var mockery = new MockRepository();

            var projectId = 3;
            var storyId = 4;
            var id = 5;
            var completed = true;
            var description = "Doin work";
            var task = new Task { Description = description, Id = id, ParentStoryId = storyId, ProjectId = projectId, Complete = true };

            var storyService = mockery.StrictMock<IStoryService>();

            using (mockery.Record())
            using (mockery.Ordered()) {
                Expect.Call(storyService.GetTask(projectId, storyId, id)).Return(task);
            }

            using (mockery.Playback()) {
                var controller = new TaskController(storyService);
                var result = controller.Complete(id, storyId, projectId, completed);
                var viewResult = result as PartialViewResult;
                Assert.NotNull(viewResult);
                Assert.AreEqual("TaskDetails", viewResult.ViewName);
                Assert.IsInstanceOf<TaskViewModel>(viewResult.Model);
                Assert.AreEqual(task, (viewResult.Model as TaskViewModel).Task);
            }
        }
        public void When_application_context_is_started_it_will_initialized_all_the_module_loader()
		{

            MockRepository mocks = new MockRepository();
            IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
            IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
            IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
            IApplicationShell stubShell = mocks.Stub<IApplicationShell>();
            DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
                stubShell, 
				mocks.DynamicMock<ILayoutRegistry>(),
				new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });

            //we may have order dependnecies, let us verify
            //that it does this in order
            using (mocks.Record())
            using (mocks.Ordered())
            {
                mockLoader1.Initialize(context, stubShell);
                mockLoader2.Initialize(context, stubShell);
                mockLoader3.Initialize(context, stubShell);
            }

            using (mocks.Playback())
            {
                context.Start();
            }
        }
        public void ShouldIgnoreArgumentsOnGenericCallWhenTypeIsStruct()
        {
            // setup
            MockRepository mocks = new MockRepository();
            ISomeService m_SomeServiceMock = mocks.StrictMock<ISomeService>();
            SomeClient sut = new SomeClient(m_SomeServiceMock);

            using (mocks.Ordered())
            {
                Expect.Call(delegate
                {
                    m_SomeServiceMock.DoSomething<string>(null, null);
                });
                LastCall.IgnoreArguments();

                Expect.Call(delegate
                {
                    m_SomeServiceMock.DoSomething<DateTime>(null, default(DateTime));  // can't use null here, because it's a value type!
                });
                LastCall.IgnoreArguments();

            }
            mocks.ReplayAll();

            // test
            sut.DoSomething();

            // verification
            mocks.VerifyAll();

            // cleanup
            m_SomeServiceMock = null;
            sut = null;
        }
        public void FiltersOnParseAndFormat()
        {
            MockRepository mocks = new MockRepository();
            IFormatter underlyingFormatter = mocks.StrictMock<IFormatter>();
            TestFilteringFormatter formatter = (TestFilteringFormatter) mocks.PartialMock(typeof (TestFilteringFormatter), underlyingFormatter);

            string inputText = "inputText";
            string filteredInputText = "filteredInputText";
            object outputValue = new object();
            object filteredOutputValue = new object();

            using(mocks.Ordered())
            {
                Expect.Call(formatter.DoFilterValueToParse(inputText)).Return(filteredInputText);
                Expect.Call(underlyingFormatter.Parse(filteredInputText)).Return(outputValue);

                Expect.Call(formatter.DoFilterValueToFormat(outputValue)).Return(filteredOutputValue);
                Expect.Call(underlyingFormatter.Format(filteredOutputValue)).Return(inputText);
            }
            mocks.ReplayAll();

            Assert.AreSame(outputValue, formatter.Parse(inputText));
            Assert.AreEqual(inputText, formatter.Format(outputValue));

            mocks.VerifyAll();
        }
        public void AddComment()
        {
            var mockery = new MockRepository();
            var storyService = mockery.StrictMock<IStoryService>();

            var storyId = 1;
            var projectId = 3;
            var comment = "comment";

            var story = new Story();

            using (mockery.Record())
            using (mockery.Ordered()) {
                storyService.AddComment(projectId, storyId, comment);
                Expect.Call(storyService.GetStory(projectId, storyId)).Return(story);
            }

            using(mockery.Playback()){
                var controller = new StoriesController(storyService);
                var result = controller.AddComment(projectId, storyId, comment);

                var partialResult = result as PartialViewResult;
                Assert.NotNull(partialResult);
                var model = partialResult.Model as StoryRowViewModel;
                Assert.NotNull(model);
                Assert.AreEqual(story, model.Story);
            }
        }
示例#9
0
 /// <summary>
 /// Defines ordered expectations
 /// </summary>
 /// <param name="methodCallsDescribingExpectations">A delegate describing the expectations</param>
 /// <returns>an IMockVerifier</returns>
 public IMockVerifier ExpectingInSameOrder(Proc methodCallsDescribingExpectations)
 {
     using (_mocks.Ordered())
     {
         methodCallsDescribingExpectations();
     }
     _mocks.ReplayAll();
     return(this);
 }
        public void Cross_ParentsWithDiffLength_Cross()
        {
            var target = new CutAndSpliceCrossover();
            var chromosome1 = MockRepository.GenerateStub<ChromosomeBase>(4);
            chromosome1.ReplaceGenes(0, new Gene[]
            {
                new Gene(1),
                new Gene(2),
                new Gene(3),
                new Gene(4),
            });
            chromosome1.Expect(c => c.CreateNew()).Return(MockRepository.GenerateStub<ChromosomeBase>(4));

            var chromosome2 = MockRepository.GenerateStub<ChromosomeBase>(5);
            chromosome2.ReplaceGenes(0, new Gene[]
            {
                new Gene(5),
                new Gene(6),
                new Gene(7),
                new Gene(8),
                new Gene(9),
            });
            chromosome2.Expect(c => c.CreateNew()).Return(MockRepository.GenerateStub<ChromosomeBase>(5));

            var repository = new MockRepository();
            var rnd = repository.StrictMock<IRandomization>();

            using (repository.Ordered())
            {
                rnd.Expect(r => r.GetInt(1, 4)).Return(2);
                rnd.Expect(r => r.GetInt(1, 5)).Return(2);
            }

            repository.ReplayAll();

            RandomizationProvider.Current = rnd;

            var actual = target.Cross(new List<IChromosome>() { chromosome1, chromosome2 });

            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual(5, actual[0].Length);
            Assert.AreEqual(4, actual[1].Length);

            Assert.AreEqual(1, actual[0].GetGene(0).Value);
            Assert.AreEqual(2, actual[0].GetGene(1).Value);
            Assert.AreEqual(3, actual[0].GetGene(2).Value);
            Assert.AreEqual(8, actual[0].GetGene(3).Value);
            Assert.AreEqual(9, actual[0].GetGene(4).Value);

            Assert.AreEqual(5, actual[1].GetGene(0).Value);
            Assert.AreEqual(6, actual[1].GetGene(1).Value);
            Assert.AreEqual(7, actual[1].GetGene(2).Value);
            Assert.AreEqual(4, actual[1].GetGene(3).Value);
        }
 public static void testJsonStructure(string json, JsonExpectationBlock expectation, string testname)
 {
     RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
     System.Console.WriteLine("test: " +  testname + "testing json=" + json);
     var mocks = new MockRepository();
     JsonExploreListener theMock = mocks.StrictMock<JsonExploreListener>();
     using (mocks.Ordered())
     {
         expectation(theMock, json);
     }
     theMock.Replay();
     (new JSONExplorerImpl()).explore(json, theMock);
     theMock.VerifyAllExpectations();
 }
        public void HasReached_GenerationNumberGreaterOrEqualThanCondition_True()
        {
            var repository = new MockRepository ();
            var ga = repository.StrictMock<IGeneticAlgorithm> ();

            using (repository.Ordered()) {
                ga.Expect (g => g.GenerationsNumber).Return (10);
                ga.Expect (g => g.GenerationsNumber).Return (11);
            }
            repository.ReplayAll ();

            var target = new GenerationNumberTermination (10);
            Assert.IsTrue (target.HasReached (ga));
            Assert.IsTrue (target.HasReached (ga));
        }
        public void HasReached_TimeLowerThanMaxTime_False()
        {
            var repository = new MockRepository ();
            var ga = repository.StrictMock<IGeneticAlgorithm> ();

            using (repository.Ordered()) {
                ga.Expect (g => g.TimeEvolving).Return (TimeSpan.FromSeconds(0.1));
                ga.Expect (g => g.TimeEvolving).Return (TimeSpan.FromSeconds(0.9));
            }
            repository.ReplayAll ();

            var target = new TimeEvolvingTermination (TimeSpan.FromSeconds(1));
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
        }
        public void HasReached_BestChromosomeHasLowerFitness_False()
        {
            var repository = new MockRepository ();
            var ga = repository.StrictMock<IGeneticAlgorithm> ();

            using (repository.Ordered()) {
                ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub() { Fitness = 0.4});
                ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub() { Fitness = 0.499});
            }
            repository.ReplayAll ();

            var target = new FitnessThresholdTermination (0.5);
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
        }
示例#15
0
        public void SetResultSelectsCorrectResult()
        {
            MockRepository mocks = new MockRepository();
            TestUserControl uc = new TestUserControl();
            Result theResult = (Result)mocks.CreateMock(typeof(Result));

            using (mocks.Ordered())
            {
                theResult.Navigate(uc);
            }
            mocks.ReplayAll();

            uc.Results.Add("theResult", theResult);
            uc.SetResult("theResult");
            mocks.VerifyAll();
        }
        public void HasReached_StagnantButNotReachTheGenerationsNumber_False()
        {

			var target = new FitnessStagnationTermination(4);
			var repository = new MockRepository ();
			var ga = repository.StrictMock<IGeneticAlgorithm> ();

			using (repository.Ordered()) {
				ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub () { Fitness = 0.1 } );
				ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub () { Fitness = 0.1 } );
				ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub () { Fitness = 0.1 } );
			}
			repository.ReplayAll ();

			Assert.IsFalse(target.HasReached(ga));
			Assert.IsFalse(target.HasReached(ga));
			Assert.IsFalse(target.HasReached(ga));
		}
        public void it_records_the_event_AFTER_asking_the_timeline_for_the_date_and_time_of_the_last_event()
        {
            var mocks = new MockRepository();

            var timeline = mocks.StrictMock<IEventTimeline>();
            
            using (mocks.Ordered())
            {
                Expect.Call(timeline.GetLastEventDateAndTime()).Return(DateTime.Parse("19-Nov-1976"));
                Expect.Call(() => timeline.RecordEvent(Arg<DateTime>.Is.Anything));
            }

            mocks.ReplayAll();

            TrickleRateLimiter rateLimiter = new TrickleRateLimiter(timeline);
            rateLimiter.CheckAndEnforceRateLimit(DateTime.UtcNow);
            
            mocks.VerifyAll();
        }
示例#18
0
        public void SetResultBubblesUpHierarchyUntilFirstMatch()
        {
            MockRepository mocks = new MockRepository();
            TestUserControl c1 = new TestUserControl();
            Control c11 = new Control(); c1.Controls.Add(c11);
            TestUserControl c111 = new TestUserControl(c11);
            Result theResult = (Result)mocks.CreateMock(typeof(Result));

            using (mocks.Ordered())
            {
                // context is the control, that contains matching Result
                theResult.Navigate(c1);
            }
            mocks.ReplayAll();

            c1.Results.Add("theResult", theResult);
            c111.SetResult("theResult");
            mocks.VerifyAll();
        }
        public void execute_is_called_after_authorize()
        {
            var mocks = new MockRepository();
            var actor = mocks.StrictMock<Actor>();
            var scenario = mocks.StrictMock<Scenario>();

            using (mocks.Ordered())
            {
                Rhino.Mocks.Expect
                    .Call(scenario.Authorize(actor))
                    .Return(true);

                scenario.Execute();
            }
            mocks.ReplayAll();

            UseCase.Execute(scenario, actor);

            mocks.VerifyAll();
        }
        public void InitWithProperties()
        {
            MockRepository mocks = new MockRepository();
            Log4NetLoggerFactoryAdapter.ILog4NetRuntime rt = mocks.StrictMock<Log4NetLoggerFactoryAdapter.ILog4NetRuntime>();

            string configFileName = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;

            using(mocks.Ordered())
            {
                rt.XmlConfiguratorConfigure();
                rt.XmlConfiguratorConfigure(configFileName);
                rt.XmlConfiguratorConfigureAndWatch(configFileName);
                rt.BasicConfiguratorConfigure();
                Expect.Call(rt.GetLogger("testLogger")).Return(mocks.DynamicMock<log4net.ILog>());
            }
            mocks.ReplayAll();

            Log4NetLoggerFactoryAdapter a;
            NameValueCollection props = new NameValueCollection();
            
            props["configType"] = "inLiNe";
            a = new TestLog4NetLoggerFactoryAdapter(props, rt);

            props["ConfigTYPE"] = "fiLe";
            props["CONFIGFILE"] = configFileName;
            a = new TestLog4NetLoggerFactoryAdapter(props, rt);

            props["ConfigTYPE"] = "fiLe-WATCH";
            props["CONFIGFILE"] = configFileName;
            a = new TestLog4NetLoggerFactoryAdapter(props, rt);

            props["ConfigTYPE"] = "external";
            a = new TestLog4NetLoggerFactoryAdapter(props, rt);

            props["ConfigTYPE"] = "any unknown";
            a = new TestLog4NetLoggerFactoryAdapter(props, rt);

            a.GetLogger("testLogger");

            mocks.VerifyAll();
        }
        public void SaveProjectAs_NewNameWithoutConflicts_AAA()
        {
            //Arrange
            MockRepository mocks = new MockRepository();
            IProjectView view = mocks.StrictMock<IProjectView>();
            IProjectRepository repository = mocks.StrictMock<IProjectRepository>();
            IProject prj = mocks.StrictMock<IProject>();

            //Component to test
            IProjectPresenter presenter = new ProjectPresenter(prj, repository, view);

            string question = "Mock ?";
            string answer = "Yes";
            string newProjectName = "RhinoMocks";

            //Not expected but its necessary for the implementation
            //We give the property behavior to prj.Name
            prj.Expect(p => p.Name).PropertyBehavior();

            using (mocks.Ordered())
            {
                view.Expect(v => v.Title).Return(prj.Name);
                view.Expect(v => v.Ask(question, answer)).Return(newProjectName);
                repository.Expect(r => r.GetProjectByName(newProjectName)).Return(null);

                view.Title = newProjectName;
                view.HasChanges = false;

                repository.SaveProject(prj);
            }
            //Act
            mocks.ReplayAll();
            bool isSave = presenter.SaveProjectAs();

            //Assert
            Assert.IsTrue(isSave);
            Assert.AreEqual(newProjectName, prj.Name);
            view.VerifyAllExpectations();
            repository.VerifyAllExpectations();
            prj.VerifyAllExpectations();
        }
示例#22
0
        public void ShouldCallEachRuleInOrderItWasAddedToRules()
        {
            var mocks = new MockRepository();

            var mockRule1 = mocks.DynamicMock<IRule>();
            var mockRule2 = mocks.DynamicMock<IRule>();
            var mockRule3 = mocks.DynamicMock<IRule>();

            using (mocks.Ordered())
            {
                Expect.Call(mockRule1.Evaluate(Dummy.PreviousResponse, Dummy.StateVariables, Dummy.ClientCapabilities)).Return(Result.Unsuccessful);
                Expect.Call(mockRule2.Evaluate(Dummy.PreviousResponse, Dummy.StateVariables, Dummy.ClientCapabilities)).Return(Result.Unsuccessful);
                Expect.Call(mockRule3.Evaluate(Dummy.PreviousResponse, Dummy.StateVariables, Dummy.ClientCapabilities)).Return(new Result(true, MockRepository.GenerateStub<IState>()));
            }
            mocks.ReplayAll();

            var rules = new Rules(mockRule1, mockRule2, mockRule3);
            rules.Evaluate(Dummy.PreviousResponse, Dummy.StateVariables, Dummy.ClientCapabilities);

            mocks.VerifyAll();
        }
        public void accept_a_visitor_with_no_interception_and_a_simpler_inner_builder()
        {
            var mocks = new MockRepository();

            var visitor = mocks.StrictMock<IBuildPlanVisitor>();
            var inner = mocks.StrictMock<IDependencySource>();

            var plan = new BuildPlan(typeof(IGateway), new ObjectInstance(new StubbedGateway()), inner, null);

            using (mocks.Ordered())
            {
                visitor.Instance(plan.PluginType, plan.Instance);
                visitor.InnerBuilder(inner);
            }

            mocks.ReplayAll();

            using (mocks.Playback())
            {
                plan.AcceptVisitor(visitor);
            }
        }
        public void SetupResultUsingOrdered()
        {
           MockRepository mocks = new MockRepository();
           IDemo demo = mocks.StrictMock<IDemo>();
           
           SetupResult.For(demo.Prop).Return("Ayende");

           using(mocks.Ordered())
           {
               demo.VoidNoArgs();
               LastCall.On(demo).Repeat.Twice();
           }
           mocks.ReplayAll();

           demo.VoidNoArgs();
           for (int i = 0; i < 30; i++)
           {
               Assert.AreEqual("Ayende",demo.Prop);      
           }
           demo.VoidNoArgs();

           mocks.VerifyAll();
        }
示例#25
0
            public void Then_Response_Flush_Is_Called_Before_And_After_The_Action()
            {
                var mocks = new MockRepository();
                var context = mocks.DynamicMock<HttpContextBase>();
                var response = mocks.DynamicMock<HttpResponseBase>();
                var action = mocks.DynamicMock<Action>();

                using(mocks.Record())
                {
                    SetupResult.For(context.Response).Return(response);
                    SetupResult.For(response.ContentEncoding).Return(Encoding.ASCII);
                    using(mocks.Ordered())
                    {
                        response.Flush();
                        action();
                        response.Flush();
                    }
                }
                using(mocks.Playback())
                {
                    new BlockRenderer(context).Capture(action);
                }
            }
 public void testArray()
 {
     string json = "{ propB:[1,2,3, \"abc\"]}";
     var mocks = new MockRepository();
     var theMock = mocks.StrictMock<JsonExploreListener>();
     RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
     Console.WriteLine("***testArray json: " + json);
     using (mocks.Ordered())
     {
         theMock.JsonStartObject(null, 0);
         theMock.JsonStartArray("propB", json.IndexOf("["));
         theMock.JsonLeaf(null, "1", false);
         theMock.JsonLeaf(null, "2", false);
         theMock.JsonLeaf(null, "3", false);
         theMock.JsonLeaf(null, "abc", true);
         theMock.JsonEndArray(json.LastIndexOf("]"));
         theMock.JsonEndObject(json.Length - 1);
     }
     theMock.Replay();
     JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
     jsonExplorerImpl.explore(json, theMock);
     theMock.VerifyAllExpectations();
 }
示例#27
0
 public void MovingFundsUsingTransaction()
 {
     //Arrange
     var mocks = new MockRepository();
     IDatabaseMapper databaseMapper = mocks.StrictMock<IDatabaseMapper>();
     IBankAccount account1 = mocks.StrictMock<IBankAccount>();
     IBankAccount account2 = mocks.StrictMock<IBankAccount>();
     using (mocks.Ordered())
     {
         Expect.Call(databaseMapper.BeginTransaction()).Return(databaseMapper);
         using (mocks.Unordered())
         {
             account1.Withdraw(1000);
             account2.Deposit(1000);
         }
         databaseMapper.Dispose();
     }
     mocks.ReplayAll();
     //Act
     Bank bank = new Bank(databaseMapper);
     bank.TransferFunds(account1, account2, 1000);
     //Assert
     mocks.VerifyAll();
 }
        public void PublishThenClearTheDomainEvents()
        {
            var mockRepository = new MockRepository();
            var @event = new TestEvent();
            var eventHandler = mockRepository.DynamicMock<IEventHandler<TestEvent>>();
            var publisher = mockRepository.StrictMock<IDomainEventsPublisher>();
            var decorator = new DomainEventsPublisherEventHandler<TestEvent>(eventHandler, publisher);

            using (mockRepository.Record())
            using (mockRepository.Ordered())
            {
                eventHandler
                    .Expect(h => h.Handle(@event))
                    .Repeat.Once();

                publisher.Expect(p => p.Publish());
                publisher.Expect(p => p.Clear());
            }

            using (mockRepository.Playback())
                decorator.Handle(@event);

            mockRepository.VerifyAll();
        }
        public void accept_a_visitor_with_interception_and_a_visitable_inner()
        {
            var mocks = new MockRepository();

            var visitor = mocks.StrictMock<IBuildPlanVisitor>();
            var inner = mocks.StrictMultiMock<IDependencySource>(typeof(IBuildPlanVisitable));
            var interception = mocks.StrictMock<IInterceptionPlan>();

            var plan = new BuildPlan(typeof(IGateway), new ObjectInstance(new StubbedGateway()), inner, interception);

            using (mocks.Ordered())
            {
                visitor.Instance(plan.PluginType, plan.Instance);
                interception.AcceptVisitor(visitor);
                inner.As<IBuildPlanVisitable>().AcceptVisitor(visitor);
            }

            mocks.ReplayAll();

            using (mocks.Playback())
            {
                plan.AcceptVisitor(visitor);
            }
        }
        public void PublishThenClearTheDomainEvents()
        {
            var mockRepository = new MockRepository();
            var command = new TestCommand();
            var commandHandler = mockRepository.DynamicMock<ICommandHandler<TestCommand>>();
            var publisher = mockRepository.StrictMock<IDomainEventsPublisher>();
            var decorator = new DomainEventsPublisherCommandHandler<TestCommand>(commandHandler, publisher);

            using (mockRepository.Record())
            using (mockRepository.Ordered())
            {
                commandHandler
                    .Expect(h => h.Handle(command))
                    .Repeat.Once();

                publisher.Expect(p => p.Publish());
                publisher.Expect(p => p.Clear());
            }

            using (mockRepository.Playback())
                decorator.Handle(command);

            mockRepository.VerifyAll();
        }
示例#31
0
        public void Send_Multiple_Messages()
        {
            var mockery = new MockRepository();
            var subscriber = mockery.StrictMock<IObserver<string>>();

            var message = "test message";
            var message2 = "another test message";

            var watched = new Watched();

            using (mockery.Record())
            using (mockery.Ordered()) {
                subscriber.OnNext(message);
                subscriber.OnNext(message2);
            }

            using (mockery.Playback())
            using (var unsubscriber = watched.Subscribe(subscriber)) {
                watched.Send(message);
                watched.Send(message2);
            }
        }