Ejemplo n.º 1
0
        public void Do3Fluent()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.StrictMock<IToggleModel>();

            var presenter = new ButtonPresenter(model);
            presenter.ConnectView(view);

            //IEventRaiser clicked = null;
            //view.Clicked += null;
            //clicked = LastCall.GetEventRaiser();

            IEventSubscriber subscriber = mockRepository.StrictMock<IEventSubscriber>();
            IWithEvents events = new WithEvents();
            // This doesn't create an expectation because no method is called on subscriber!!
            events.Blah += subscriber.Handler;
            subscriber.Handler(VisibilityState.Visible);

            With.Mocks(mockRepository)
                .Expecting(delegate
                           	{
                           		Expect.Call(model.ToggleVisibility);
                           		Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();
                           		Expect.Call(() => view.SetCheckedState(CheckedState.Checked));
                           	})
                .Verify(delegate
                            {
                                events.RaiseEvent(VisibilityState.Visible);
                                //clicked.Raise();
                            });
        }
        public void ConstructingConnectingHandling_WithRaisingTwoEvents_Works_Fluent()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.StrictMock<IToggleModel>();

            IEventRaiser clicked = null;
            IEventRaiser visibilityChanged = null;

            With.Mocks(mockRepository)
                .Expecting(delegate
                           	{
                           		visibilityChanged =
                           			Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments().GetEventRaiser();
                           		clicked = Expect.Call(() => view.Clicked += null).IgnoreArguments().GetEventRaiser();

                           		Expect.Call(model.ToggleVisibility);
                           		Expect.Call(() => view.SetCheckedState(CheckedState.Checked));
                           	});

            With.Mocks(mockRepository)
                .Verify(delegate
                            {
                                var presenter = new ButtonPresenter(model);
                                presenter.ConnectView(view);

                                clicked.Raise();
                                visibilityChanged.Raise(VisibilityState.Visible);
                            });
        }
Ejemplo n.º 3
0
        public void Do3Classic()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.StrictMock<IToggleModel>();

            model.VisibilityStateChanged += null;
            IEventRaiser visibilityChanged = LastCall.GetEventRaiser();

            view.Clicked += null;
            IEventRaiser clicked = LastCall.GetEventRaiser();

            var presenter = new ButtonPresenter(model);
            presenter.ConnectView(view);

            mockRepository.BackToRecordAll();
            //mockRepository.Playback();

            Expect.Call(model.ToggleVisibility);
            Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();
            Expect.Call(() => view.SetCheckedState(CheckedState.Checked));

            mockRepository.ReplayAll();

            clicked.Raise();
            visibilityChanged.Raise(VisibilityState.Visible);

            mockRepository.VerifyAll();
        }
        public void ConnectingView()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.Stub<IToggleModel>();

            var presenter = new ButtonPresenter(model);

            With.Mocks(mockRepository)
                .Expecting(delegate { Expect.Call(() => view.Clicked += null).IgnoreArguments(); })
                .Verify(delegate { presenter.ConnectView(view); });
        }
        public void RoundtripViewToModelToView_Hiding()
        {
            var view = new Mock<IButtonView>(MockBehavior.Strict);
            var model = new Mock<IToggleModel>(MockBehavior.Strict);

            var presenter = new ButtonPresenter(model.Object);
            presenter.ConnectView(view.Object);

            // Erwartungen definieren
            // User-Interaktion im View -> Änderung im Model muss erfolgen
            model.Setup(m => m.ToggleVisibility());
            // Model-Änderungs-Event -> View muss aktualisiert werden
            view.Setup(v => v.SetCheckedState(CheckedState.Unchecked));

            // Events auslösen
            view.Raise(m => m.Clicked += null);
            model.Raise(m => m.VisibilityStateChanged += null, VisibilityState.Invisible);

            // Erwartungen verifizieren
            model.VerifyAll();
            view.VerifyAll();
        }
        public void ConstructingConnectingHandlingWorks_Fluent2()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.DynamicMock<IButtonView>();
            var model = mockRepository.DynamicMock<IToggleModel>();

            IEventRaiser clicked = null;

            With.Mocks(mockRepository)
                .Expecting(delegate
                           	{
                           		Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();

                           		clicked = Expect.Call(() => view.Clicked += null).IgnoreArguments().GetEventRaiser();
                           		Expect.Call(model.ToggleVisibility);
                           	})
                .Verify(delegate
                            {
                                var presenter = new ButtonPresenter(model);
                                presenter.ConnectView(view);
                                clicked.Raise();
                            });
        }
Ejemplo n.º 7
0
        public void Do3Using()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.StrictMock<IToggleModel>();

            model.VisibilityStateChanged += null;
            IEventRaiser visibilityChanged = LastCall.GetEventRaiser();

            view.Clicked += null;
            IEventRaiser clicked = LastCall.GetEventRaiser();

            //IEventRaiser raiser = new EventRaiser((IMockedObject)view, "Clicked");
            //onCreateFeatureEventRaiser.Raise(_objectMock);

            var presenter = new ButtonPresenter(model);
            presenter.ConnectView(view);
            //mockRepository.BackToRecordAll();

            //productDetailView.Raise(view => view.EditClick += null).Raise(sender, EventArgs.Empty);

            view.BackToRecord();
            model.BackToRecord();

            using (mockRepository.Record())
            {
                var v = Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();

                Expect.Call(model.ToggleVisibility);
                //Expect.Call(() => view.SetCheckedState(CheckedState.Checked));
            }

            using (mockRepository.Playback())
            {
                //raiser.Raise();
                //view.Raise(v => v.Clicked += null);
                //model.Raise(m => m.VisibilityChanged += null).Raise(VisibilityState.Visible);
                clicked.Raise();
                //visibilityChanged.Raise(VisibilityState.Visible);
            }
        }
Ejemplo n.º 8
0
        public void Do3Fluent_A()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.DynamicMock<IToggleModel>();

            view.Clicked += null;
            IEventRaiser clicked = LastCall.GetEventRaiser();

            var presenter = new ButtonPresenter(model);
            presenter.ConnectView(view);

            clicked = Expect.Call(() => view.Clicked += null).IgnoreArguments().GetEventRaiser();

            view.BackToRecord();
            model.BackToRecord();

            With.Mocks(mockRepository)
                .Expecting(delegate
                           	{
                           		Expect.Call(model.ToggleVisibility);
                           		//Expect.Call(() => model.VisibilityChanged += null).IgnoreArguments();
                           		//Expect.Call(() => view.SetCheckedState(CheckedState.Checked));
                           	})
                .Verify(delegate
                            {
                                model.ToggleVisibility();
                                model.ToggleVisibility();
                                //events.RaiseEvent(VisibilityState.Visible);
                                clicked.Raise();
                            });
        }