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); }
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."); }
public void ShouldWorkWithConventionCtorInterceptor() { ServiceLocatorStub sl = CreateDefaultContainer(); var logger = new MyLogger(); var convFactory = new ConversationFactoryStub(delegate(string id) { IConversation result = new NoOpConversationStub(id); return(result); }); sl.AddInstance(logger); sl.AddInstance <IConversationFactory>(convFactory); sl.AddService <IConversationCreationInterceptorConvention <SamplePresenter>, LogInterceptorConvention <SamplePresenter> >(); var presenter = new SamplePresenter(); presenter.GetProduct(Guid.NewGuid()); logger.Messages .Should() .Have.SameSequenceAs(new[] { LogInterceptor.ConversationStarting, LogInterceptor.ConversationStarted }); }
public void UsingABadBoyContainerWithoutConversationFactoryShouldThrow() { var sl = CreateDefaultContainer(); sl.AddInstance(new NoopConversationalMarker()); var presenter = new SamplePresenter(); Assert.Throws <ActivationException>(() => presenter.GetProduct(Guid.NewGuid())); }
public void ShouldWorkWithNoopMarker() { var sl = CreateDefaultContainer(); sl.AddInstance(new NoopConversationalMarker { Noop = true }); var presenter = new SamplePresenter(); Assert.DoesNotThrow(() => presenter.GetProduct(Guid.NewGuid())); }
public void ShouldUnbindOnEndException() { ServiceLocatorStub sl = CreateDefaultContainer(); var convFactory = new ConversationFactoryStub(delegate(string id) { IConversation result = new ExceptionOnFlushConversationStub(id); result.OnException += ((sender, args) => args.ReThrow = false); return(result); }); sl.AddInstance <IConversationFactory>(convFactory); var presenter = new SamplePresenter(); presenter.GetProduct(Guid.NewGuid()); Assert.That(CurrentConversationContainer.BindedConversationCount, Is.EqualTo(1), "One conversation should be binded."); presenter.AcceptAll(); Assert.That(CurrentConversationContainer.BindedConversationCount, Is.EqualTo(0), "Don't unbind the conversation with exception catch by custom event handler"); }