Beispiel #1
0
        public void ShouldSupportsExplicitMethodsInclusionOfPrivateMethod()
        {
            var sl = CreateDefaultContainer();

            var startedCalled = false;
            var convFactory   = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                result.Started      += ((s, a) => startedCalled = true);
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);


            var scm = new SamplePresenter();

            scm.GetType().GetMethod("GetProductInternal", BindingFlags.Instance | BindingFlags.NonPublic)
            .Invoke(scm, null);

            Assert.That(startedCalled, "An explicit method inclusion of a private member don't start the conversation.");

            Assert.That(CurrentConversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");
        }
Beispiel #2
0
        public void ShouldWorkWithServiceCtorInterceptor()
        {
            ServiceLocatorStub sl = CreateDefaultContainer();
            var logger            = new MyLogger();

            var convFactory = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);
            sl.AddService <ILogInterceptor, LogInterceptor>();
            sl.AddInstance(logger);

            var presenter = new SamplePresenterWithServiceInterception();

            presenter.GetProduct(Guid.NewGuid());

            logger.Messages
            .Should().Have
            .SameSequenceAs(new[]
            {
                LogInterceptor.ConversationStarting,
                LogInterceptor.ConversationStarted
            });
        }
Beispiel #3
0
        public void TwoInstancesShouldStartDifferentsConversations()
        {
            var sl = CreateDefaultContainer();

            int startedCalledTimes = 0;
            var convFactory        = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                result.Started      += (s, a) => startedCalledTimes++;
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);

            var presenter = new SamplePresenter();

            presenter.GetProduct(Guid.NewGuid());
            presenter.GetProduct(Guid.NewGuid());

            var presenter2 = new SamplePresenter();

            presenter2.GetProduct(Guid.NewGuid());

            startedCalledTimes.Should().Be.EqualTo(2);
        }
Beispiel #4
0
        public void ShouldSupportsImplicitMethodsInclusion()
        {
            ServiceLocatorStub sl = CreateDefaultContainer();

            bool resumedCalled = false;
            bool startedCalled = false;
            var  convFactory   = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                result.Resumed      += ((s, a) => resumedCalled = true);
                result.Started      += ((s, a) => startedCalled = true);
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);

            var conversationContainer = CurrentConversationContainer;

            var presenter = new SamplePresenter();

            presenter.GetProduct(Guid.NewGuid());
            Assert.That(startedCalled, "An implicit method inclusion don't start the conversation.");
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");
            resumedCalled = false;
            startedCalled = false;

            presenter.GetProduct(Guid.NewGuid());
            Assert.That(resumedCalled, "An implicit method inclusion don't resume the conversation.");
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");
            resumedCalled = false;

            presenter.DoSomethingNoPersistent();
            Assert.That(!resumedCalled, "An explicit method exclusion resume the conversation; shouldn't");
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");

            string value = presenter.PropertyOutConversation;

            Assert.That(!resumedCalled, "An explicit method exclusion resume the conversation; shouldn't");
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");

            value = presenter.PropertyInConversation;
            Assert.That(resumedCalled, "An implicit method inclusion don't resume the conversation.");
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");
            resumedCalled = false;

            presenter.AcceptAll();
            Assert.That(resumedCalled, "An explicit method inclusion should resume the conversation");
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(0),
                        "Should have NO active conversation because the method AcceptAll end the conversation.");
        }
Beispiel #5
0
        public void ShouldSupportsDefaultEndMode()
        {
            ServiceLocatorStub sl = CreateDefaultContainer();
            bool endedCalled      = false;
            var  convFactory      = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                result.Ended        += ((s, a) => endedCalled = true);
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);
            var presenter = new SamplePresenterWithDefaultModeEnd();

            presenter.GetProduct(Guid.NewGuid());
            endedCalled.Should().Be.True();

            Assert.That(CurrentConversationContainer.BindedConversationCount, Is.EqualTo(0),
                        "Don't unbind the conversation after end. The Adapter are changing the conversation AutoUnbindAfterEndConversation");
        }
Beispiel #6
0
        public void PrivateMethodsShouldNotBeImplicitlyIncluded()
        {
            var sl = CreateDefaultContainer();

            int startedCalledTimes = 0;
            var convFactory        = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                result.Started      += (s, a) => startedCalledTimes++;
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);

            var presenter = new SamplePresenter();

            //DoSomethingNoPersistent() calls to a private method that is not explicit included
            presenter.DoSomethingNoPersistent();

            Assert.That(startedCalledTimes, Is.EqualTo(0),
                        "The conversation should not be started.");
        }
Beispiel #7
0
        public void ShouldSupportNestedConversationalMethods()
        {
            var sl = CreateDefaultContainer();

            int startedCalledTimes = 0;
            int resumedTimes       = 0;
            int pausedTimes        = 0;
            var convFactory        = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new NoOpConversationStub(id);
                result.Started      += (s, a) => startedCalledTimes++;
                result.Resumed      += (s, a) => resumedTimes++;
                result.Paused       += (s, a) => pausedTimes++;
                return(result);
            });

            sl.AddInstance <IConversationFactory>(convFactory);

            var conversationContainer = CurrentConversationContainer;

            var presenter = new SamplePresenter();

            presenter.GetProductWithNestedMethod();

            Assert.That(startedCalledTimes, Is.EqualTo(1),
                        "The conversation should be started once in the former conversational method.");

            Assert.That(resumedTimes, Is.EqualTo(0),
                        "The conversation should not be resumed because the second conversational method is nested.");

            Assert.That(pausedTimes, Is.EqualTo(1),
                        "The conversation should be paused once because the second conversational method is nested.");

            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Should have one active conversation because the default mode is continue.");
        }