public void ShouldDetectMissingBehaviorForRootContext()
        {
            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                RegisterStep.Create("Child", typeof(ChildBehaviorOfChildContext), "desc"),
            }, new List <RemoveStep>(), new List <ReplaceStep>());


            var ex = Assert.Throws <Exception>(() => builder.Build());

            Assert.AreEqual("Can't find any behaviors/connectors for the root context (NServiceBus.Core.Tests.Pipeline.PipelineModelBuilderTests+IParentContext)", ex.Message);
        }
        public void ShouldDetectConflictingStepRegistrations()
        {
            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                RegisterStep.Create("Root1", typeof(RootBehavior), "desc"),
                RegisterStep.Create("Root1", typeof(ChildBehaviorOfChildContextNotInheritedFromParentContext), "desc"),
            }, new List <RemoveStep>(), new List <ReplaceStep>());


            var ex = Assert.Throws <Exception>(() => builder.Build());

            Assert.AreEqual("Step registration with id 'Root1' is already registered for 'NServiceBus.Core.Tests.Pipeline.PipelineModelBuilderTests+RootBehavior'.", ex.Message);
        }
        public void ShouldDetectRegistrationsWithContextsNotReachableFromTheRootContext()
        {
            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                RegisterStep.Create("Root", typeof(RootBehavior), "desc"),
                RegisterStep.Create("ParentContextToChildContextConnector", typeof(ParentContextToChildContextConnector), "desc"),
                RegisterStep.Create("Child", typeof(ChildBehaviorOfChildContextNotInheritedFromParentContext), "desc")
            }, new List <RemoveStep>(), new List <ReplaceStep>());


            var model = builder.Build();

            Assert.AreEqual(2, model.Count);
        }
        public void ShouldDetectConflictingStageConnectors()
        {
            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                RegisterStep.Create("Root1", typeof(RootBehavior), "desc"),
                RegisterStep.Create("ParentContextToChildContextConnector", typeof(ParentContextToChildContextConnector), "desc"),
                RegisterStep.Create("ParentContextToChildContextNotInheritedFromParentContextConnector", typeof(ParentContextToChildContextNotInheritedFromParentContextConnector), "desc")
            }, new List <RemoveStep>(), new List <ReplaceStep>());


            var ex = Assert.Throws <Exception>(() => builder.Build());

            Assert.AreEqual("Multiple stage connectors found for stage 'NServiceBus.Core.Tests.Pipeline.PipelineModelBuilderTests+IParentContext'. Remove one of: 'NServiceBus.Core.Tests.Pipeline.PipelineModelBuilderTests+ParentContextToChildContextConnector', 'NServiceBus.Core.Tests.Pipeline.PipelineModelBuilderTests+ParentContextToChildContextNotInheritedFromParentContextConnector'", ex.Message);
        }
        public void ShouldOnlyAllowRemovalOfExistingRegistrations()
        {
            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                RegisterStep.Create("Root1", typeof(RootBehavior), "desc"),
            }, new List <RemoveStep>
            {
                new RemoveStep("DoesNotExist"),
            }, new List <ReplaceStep>());


            var ex = Assert.Throws <Exception>(() => builder.Build());

            Assert.AreEqual("You cannot remove step registration with id 'DoesNotExist', registration does not exist.", ex.Message);
        }
        public void ShouldHandleTheTerminator()
        {
            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                RegisterStep.Create("Root1", typeof(RootBehavior), "desc"),
                RegisterStep.Create("ParentContextToChildContextConnector", typeof(ParentContextToChildContextConnector), "desc"),
                RegisterStep.Create("Child", typeof(ChildBehaviorOfChildContextNotInheritedFromParentContext), "desc"),
                RegisterStep.Create("Terminator", typeof(Terminator), "desc")
            }, new List <RemoveStep>(), new List <ReplaceStep>());


            var model = builder.Build();

            Assert.AreEqual(3, model.Count);
        }
        public void ShouldDetectNonExistingInsertBeforeRegistrations()
        {
            var someBehaviorRegistration    = RegisterStep.Create("SomeBehaviorOfParentContext", typeof(SomeBehaviorOfParentContext), "desc");
            var anotherBehaviorRegistration = RegisterStep.Create("AnotherBehaviorOfParentContext", typeof(AnotherBehaviorOfParentContext), "desc");

            anotherBehaviorRegistration.InsertBefore("DoesNotExist");

            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                someBehaviorRegistration,
                anotherBehaviorRegistration,
            }, new List <RemoveStep>(), new List <ReplaceStep>());


            var ex = Assert.Throws <Exception>(() => builder.Build());

            Assert.AreEqual("Registration 'DoesNotExist' specified in the insertbefore of the 'AnotherBehaviorOfParentContext' step does not exist. Current StepIds: 'SomeBehaviorOfParentContext', 'AnotherBehaviorOfParentContext'", ex.Message);
        }
        public void ShouldOnlyAllowRemovalWhenNoOtherDependsOnItsAfterRegistration()
        {
            var someBehaviorRegistration    = RegisterStep.Create("SomeBehaviorOfParentContext", typeof(SomeBehaviorOfParentContext), "desc");
            var anotherBehaviorRegistration = RegisterStep.Create("AnotherBehaviorOfParentContext", typeof(AnotherBehaviorOfParentContext), "desc");

            anotherBehaviorRegistration.InsertAfter("SomeBehaviorOfParentContext");

            var builder = new PipelineModelBuilder(typeof(IParentContext), new List <RegisterStep>
            {
                someBehaviorRegistration,
                anotherBehaviorRegistration,
            }, new List <RemoveStep> {
                new RemoveStep("SomeBehaviorOfParentContext")
            }, new List <ReplaceStep>());


            var ex = Assert.Throws <Exception>(() => builder.Build());

            Assert.AreEqual("You cannot remove step registration with id 'SomeBehaviorOfParentContext', registration with id 'AnotherBehaviorOfParentContext' depends on it.", ex.Message);
        }