public void Pipeline_ShouldInitializeTheCorrectModule()
        {
            var container          = new CompositionContainer();
            var clockService       = new ClockService();
            var factory            = new Mef.ClassFactory();
            var module             = new ValidateAccount4Module(clockService, factory);
            var accountingPipeline = Substitute.For <AccountingPipeline>();

            var clockServicePart          = AttributedModelServices.CreatePart(clockService);
            var factoryPart               = AttributedModelServices.CreatePart(factory);
            var modulePart                = AttributedModelServices.CreatePart(module);
            var accountingPipelinePart    = AttributedModelServices.CreatePart(accountingPipeline);
            var accountingPipelineContext = new AccountingPipelineContext();
            //Manual composition
            var batch = new CompositionBatch(new List <ComposablePart>
            {
                clockServicePart, factoryPart, modulePart, accountingPipelinePart
            }, null);

            container.Compose(batch);
            Mef.ClassFactory.Set(container);
            var pipeline = accountingPipelineContext.CreatePipelineHost(factory);

            pipeline.Execute();

            accountingPipeline.Received(1).ValidateAccount += Arg.Any <ModuleDelegate <IAccountingPipelineContext> >();

            //Manual cleanup to prevent memory leaks that will affect other tests
            batch.RemovePart(clockServicePart);
            batch.RemovePart(factoryPart);
            batch.RemovePart(modulePart);
            batch.RemovePart(accountingPipelinePart);

            Mef.ClassFactory.Dispose();
        }
Пример #2
0
        public async Task Pipeline_ShouldExecuteModulesWithDiffentNamespace()
        {
            var context  = new AccountingPipelineContext();
            var pipeline = context.CreatePipelineHost(classFactory);

            await pipeline.ExecuteAsync();

            context.Messages.Count.ShouldBe(3, "Should be called exactly thrice.");
            context.Messages.Contains("Lowest Version.").ShouldBeFalse();
            context.Messages.Contains("Highest Version.").ShouldBeTrue();
            context.Messages.Contains("Same module but different namespace.").ShouldBeTrue();
            context.Messages.Contains("Module from another assembly.").ShouldBeTrue();
        }
Пример #3
0
        public void Pipeline_ShouldUnloadAllDiscoveredModules()
        {
            //PipelineHost 1
            var accountingPipelineContext = new AccountingPipelineContext();
            var accountingPipeline        = accountingPipelineContext.CreatePipelineHost(classFactory);

            accountingPipeline.Execute();

            accountingPipelineContext.Messages.Count.ShouldBe(3, "Should be called exactly thrice.");
            accountingPipelineContext.Messages.Contains("Lowest Version.").ShouldBeFalse();
            accountingPipelineContext.Messages.Contains("Highest Version.").ShouldBeTrue();
            accountingPipelineContext.Messages.Contains("Same module but different namespace.").ShouldBeTrue();
            accountingPipelineContext.Messages.Contains("Module from another assembly.").ShouldBeTrue();


            //PipelineHost 2
            var fakeContext  = new FakePipelineContext();
            var fakePipeline = fakeContext.CreatePipelineHost(classFactory);

            fakePipeline.Execute();

            fakeContext.Messages.Count.ShouldBe(2);
            fakeContext.Messages.Contains("FakeModule ValidateAccount.").ShouldBeTrue();
            fakeContext.Messages.Contains("FakeModule SetJournal.").ShouldBeTrue();

            dotMemory.Check(memory =>
            {
                memory.GetObjects(where => where.Type.Is <FakeModule>()).ObjectsCount.ShouldBe(0);
                memory.GetObjects(where => where.Type.Is <ValidateAccount1Module>()).ObjectsCount.ShouldBe(0);
                memory.GetObjects(where => where.Type.Is <ValidateAccount2Module>()).ObjectsCount.ShouldBe(0);
                memory.GetObjects(where => where.Type.Is <ValidateAccount3Module>()).ObjectsCount.ShouldBe(0);
                memory.GetObjects(where => where.Type.Is <ValidateAccount4Module>()).ObjectsCount.ShouldBe(0);
                memory.GetObjects(where => where.Type.Is <AccountingPipeline>()).ObjectsCount.ShouldBe(0);
                memory.GetObjects(where => where.Type.Is <FakePipeline>()).ObjectsCount.ShouldBe(0);
            });
        }
Пример #4
0
        public void MultitplePipeline_ShouldBeExecuted()
        {
            //PipelineHost 1
            var accountingPipelineContext = new AccountingPipelineContext();
            var accountingPipeline        = accountingPipelineContext.CreatePipelineHost(classFactory);

            accountingPipeline.Execute();

            accountingPipelineContext.Messages.Count.ShouldBe(3, "Should be called exactly thrice.");
            accountingPipelineContext.Messages.Contains("Lowest Version.").ShouldBeFalse();
            accountingPipelineContext.Messages.Contains("Highest Version.").ShouldBeTrue();
            accountingPipelineContext.Messages.Contains("Same module but different namespace.").ShouldBeTrue();
            accountingPipelineContext.Messages.Contains("Module from another assembly.").ShouldBeTrue();

            //PipelineHost 2
            var fakeContext  = new FakePipelineContext();
            var fakePipeline = fakeContext.CreatePipelineHost(classFactory);

            fakePipeline.Execute();

            fakeContext.Messages.Count.ShouldBe(2);
            fakeContext.Messages.Contains("FakeModule ValidateAccount.").ShouldBeTrue();
            fakeContext.Messages.Contains("FakeModule SetJournal.").ShouldBeTrue();
        }