예제 #1
0
            public void ThrowsForNonExistingPipeline()
            {
                // Given
                TestDocument a1 = new TestDocument("a1");
                TestDocument b1 = new TestDocument("b1");
                TestDocument b2 = new TestDocument("b2");
                TestDocument c1 = new TestDocument("c1");
                TestDocument d1 = new TestDocument("d1");
                TestDocument d2 = new TestDocument("d2");
                ConcurrentDictionary <string, ImmutableArray <IDocument> > documents =
                    new ConcurrentDictionary <string, ImmutableArray <IDocument> >(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new PipelineCollection();
                PipelinePhase       phaseA    =
                    GetPipelineAndPhase("A", Phase.Process, pipelines, documents, new[] { a1 });
                PipelinePhase phaseB =
                    GetPipelineAndPhase("B", Phase.Process, pipelines, documents, new[] { b1, b2 }, phaseA);
                PipelinePhase phaseC =
                    GetPipelineAndPhase("C", Phase.Process, pipelines, documents, new[] { c1 }, phaseB);
                PipelinePhase phaseD =
                    GetPipelineAndPhase("D", Phase.Process, pipelines, documents, new[] { d1, d2 });
                PipelineOutputs documentCollection = new PipelineOutputs(documents, phaseC, pipelines);

                // When, Then
                Should.Throw <KeyNotFoundException>(() => documentCollection.FromPipeline("E"));
            }
예제 #2
0
            public void ExcludeFromDeploymentDuringOutput()
            {
                // Given
                TestDocument a1 = new TestDocument("a1");
                TestDocument b1 = new TestDocument("b1");
                TestDocument b2 = new TestDocument("b2");
                TestDocument c1 = new TestDocument("c1");
                TestDocument d1 = new TestDocument("d1");
                TestDocument d2 = new TestDocument("d2");
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new TestPipelineCollection();
                PipelinePhase       phaseA    =
                    GetPipelineAndPhase("A", Phase.Output, pipelines, phaseResults, new[] { a1 }, Phase.Output);
                PipelinePhase phaseB =
                    GetPipelineAndPhase("B", Phase.Output, pipelines, phaseResults, new[] { b1, b2 }, Phase.Output, phaseA);
                PipelinePhase phaseC =
                    GetPipelineAndPhase("C", Phase.Output, pipelines, phaseResults, new[] { c1 }, Phase.Output, phaseB);

                phaseC.Pipeline.Deployment = true;
                PipelinePhase phaseD =
                    GetPipelineAndPhase("D", Phase.Output, pipelines, phaseResults, new[] { d1, d2 }, Phase.Output);

                phaseD.Pipeline.Deployment = true;
                PhaseOutputs documentCollection = new PhaseOutputs(phaseResults, phaseC, pipelines);

                // When
                IDocument[] result = documentCollection.ExceptPipeline("A").ToArray();

                // Then
                result.ShouldBe(new[] { b1, b2 }, true);
            }
            public void ThrowsForNonDependentPipelineDuringProcessPhase()
            {
                // Given
                TestDocument a1 = new TestDocument("a1");
                TestDocument b1 = new TestDocument("b1");
                TestDocument b2 = new TestDocument("b2");
                TestDocument c1 = new TestDocument("c1");
                TestDocument d1 = new TestDocument("d1");
                TestDocument d2 = new TestDocument("d2");
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new TestPipelineCollection();
                PipelinePhase       phaseA    =
                    GetPipelineAndPhase("A", Phase.Process, pipelines, phaseResults, new[] { a1 });
                PipelinePhase phaseB =
                    GetPipelineAndPhase("B", Phase.Process, pipelines, phaseResults, new[] { b1, b2 }, phaseA);
                PipelinePhase phaseC =
                    GetPipelineAndPhase("C", Phase.Process, pipelines, phaseResults, new[] { c1 }, phaseB);
                PipelinePhase phaseD =
                    GetPipelineAndPhase("D", Phase.Process, pipelines, phaseResults, new[] { d1, d2 });
                ProcessPhaseOutputs documentCollection = new ProcessPhaseOutputs(phaseResults, phaseC, pipelines);

                // When, Then
                Should.Throw <InvalidOperationException>(() => documentCollection.FromPipeline("D"));
            }
            public void TransformPhaseGetsAllDocuments()
            {
                // Given
                TestDocument a1 = new TestDocument("a1");
                TestDocument b1 = new TestDocument("b1");
                TestDocument b2 = new TestDocument("b2");
                TestDocument c1 = new TestDocument("c1");
                TestDocument d1 = new TestDocument("d1");
                TestDocument d2 = new TestDocument("d2");
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new TestPipelineCollection();
                PipelinePhase       phaseA    =
                    GetPipelineAndPhase("A", Phase.Transform, pipelines, phaseResults, new[] { a1 });
                PipelinePhase phaseB =
                    GetPipelineAndPhase("B", Phase.Transform, pipelines, phaseResults, new[] { b1, b2 }, phaseA);
                PipelinePhase phaseC =
                    GetPipelineAndPhase("C", Phase.Transform, pipelines, phaseResults, new[] { c1 }, phaseB);
                PipelinePhase phaseD =
                    GetPipelineAndPhase("D", Phase.Transform, pipelines, phaseResults, new[] { d1, d2 });
                ProcessPhaseOutputs documentCollection = new ProcessPhaseOutputs(phaseResults, phaseC, pipelines);

                // When
                IDocument[] result = documentCollection.ToArray();

                // Then
                result.ShouldBe(new[] { a1, b1, b2, c1, d1, d2 }, true);
            }
예제 #5
0
            public void GetsDocumentsForTransientDependentPipelineDuringProcessPhase()
            {
                // Given
                TestDocument a1 = new TestDocument("a1");
                TestDocument b1 = new TestDocument("b1");
                TestDocument b2 = new TestDocument("b2");
                TestDocument c1 = new TestDocument("c1");
                TestDocument d1 = new TestDocument("d1");
                TestDocument d2 = new TestDocument("d2");
                ConcurrentDictionary <string, ImmutableArray <IDocument> > documents =
                    new ConcurrentDictionary <string, ImmutableArray <IDocument> >(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new PipelineCollection();
                PipelinePhase       phaseA    =
                    GetPipelineAndPhase("A", Phase.Process, pipelines, documents, new[] { a1 });
                PipelinePhase phaseB =
                    GetPipelineAndPhase("B", Phase.Process, pipelines, documents, new[] { b1, b2 }, phaseA);
                PipelinePhase phaseC =
                    GetPipelineAndPhase("C", Phase.Process, pipelines, documents, new[] { c1 }, phaseB);
                PipelinePhase phaseD =
                    GetPipelineAndPhase("D", Phase.Process, pipelines, documents, new[] { d1, d2 });
                PipelineOutputs documentCollection = new PipelineOutputs(documents, phaseC, pipelines);

                // When
                IDocument[] result = documentCollection.FromPipeline("A").ToArray();

                // Then
                result.ShouldBe(new[] { a1 });
            }
예제 #6
0
        private static string DescribeValidEnumRange(PipelinePhase start, PipelinePhase end)
        {
            var enumValues = Enum.GetValues(typeof(PipelinePhase))
                             .Cast <PipelinePhase>()
                             .Where(value => value >= start && value <= end);

            return(string.Join(", ", enumValues));
        }
예제 #7
0
            public void ThrowsForEmptyPipeline()
            {
                // Given
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines          = new TestPipelineCollection();
                PipelinePhase       phase              = GetPipelineAndPhase("A", Phase.Transform, pipelines, phaseResults, Array.Empty <IDocument>());
                PhaseOutputs        documentCollection = new PhaseOutputs(phaseResults, phase, pipelines);

                // When, Then
                Should.Throw <ArgumentException>(() => documentCollection.FromPipeline(string.Empty));
            }
예제 #8
0
            public void ThrowsForNullPipeline()
            {
                // Given
                ConcurrentDictionary <string, ImmutableArray <IDocument> > documents =
                    new ConcurrentDictionary <string, ImmutableArray <IDocument> >(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines          = new PipelineCollection();
                PipelinePhase       phase              = GetPipelineAndPhase("A", Phase.Transform, pipelines, documents, Array.Empty <IDocument>());
                PipelineOutputs     documentCollection = new PipelineOutputs(documents, phase, pipelines);

                // When, Then
                Should.Throw <ArgumentException>(() => documentCollection.FromPipeline(null));
            }
            public void ThrowsForCurrentPipelineDuringProcess()
            {
                // Given
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines          = new TestPipelineCollection();
                PipelinePhase       phase              = GetPipelineAndPhase("A", Phase.Process, pipelines, phaseResults, Array.Empty <IDocument>());
                ProcessPhaseOutputs documentCollection = new ProcessPhaseOutputs(phaseResults, phase, pipelines);

                // When, Then
                Should.Throw <InvalidOperationException>(() => documentCollection.FromPipeline("A"));
            }
            public void DoesNotThrowForCurrentPipelineDuringTransform()
            {
                // Given
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines          = new TestPipelineCollection();
                PipelinePhase       phase              = GetPipelineAndPhase("A", Phase.Transform, pipelines, phaseResults, Array.Empty <IDocument>());
                ProcessPhaseOutputs documentCollection = new ProcessPhaseOutputs(phaseResults, phase, pipelines);

                // When, Then
                Should.NotThrow(() => documentCollection.FromPipeline("A"));
            }
            public void ThrowsIfInputPhase()
            {
                // Given
                ConcurrentDictionary <string, PhaseResult[]> documents =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new TestPipelineCollection();
                PipelinePhase       phase     = GetPipelineAndPhase("A", Phase.Input, pipelines, documents, Array.Empty <IDocument>());

                phase.Pipeline.Isolated = true;
                ProcessPhaseOutputs documentCollection = new ProcessPhaseOutputs(documents, phase, pipelines);

                // When, Then
                Should.Throw <InvalidOperationException>(() => documentCollection.ToArray());
            }
예제 #12
0
        private PipelinePhase GetPipelineAndPhase(
            string pipelineName,
            Phase phase,
            IPipelineCollection pipelines,
            ConcurrentDictionary <string, ImmutableArray <IDocument> > documentCollection,
            IDocument[] documents,
            params PipelinePhase[] dependencies)
        {
            TestPipeline  pipeline      = new TestPipeline();
            PipelinePhase pipelinePhase = new PipelinePhase(pipeline, pipelineName, phase, Array.Empty <IModule>(), NullLogger.Instance, dependencies);

            pipelines.Add(pipelineName, pipeline);
            documentCollection.AddOrUpdate(pipelineName, documents.ToImmutableArray(), (_, __) => documents.ToImmutableArray());
            return(pipelinePhase);
        }
예제 #13
0
            public void DoesNotThrowForDeploymentDuringOutput()
            {
                // Given
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new TestPipelineCollection();
                PipelinePhase       phase     = GetPipelineAndPhase("A", Phase.Output, pipelines, phaseResults, Array.Empty <IDocument>(), Phase.Output);

                phase.Pipeline.Deployment = true;
                GetPipelineAndPhase("B", Phase.Output, pipelines, phaseResults, Array.Empty <IDocument>(), Phase.Output);
                PhaseOutputs documentCollection = new PhaseOutputs(phaseResults, phase, pipelines);

                // When, Then
                Should.NotThrow(() => documentCollection.FromPipeline("B"));
            }
        private PipelinePhase GetPipelineAndPhase(
            string pipelineName,
            Phase currentPhase,
            IPipelineCollection pipelines,
            ConcurrentDictionary <string, PhaseResult[]> phaseResults,
            IDocument[] outputs,
            Phase phaseForOutputs,
            params PipelinePhase[] dependencies)
        {
            TestPipeline  pipeline      = new TestPipeline();
            PipelinePhase pipelinePhase = new PipelinePhase(pipeline, pipelineName, currentPhase, Array.Empty <IModule>(), NullLogger.Instance, dependencies);

            pipelines.Add(pipelineName, pipeline);
            PhaseResult[] results = new PhaseResult[4];
            if (outputs != null)
            {
                results[(int)phaseForOutputs] = new PhaseResult(pipelineName, phaseForOutputs, outputs.ToImmutableArray(), default, 0);
        private PipelinePhase GetPipelineAndPhase(
            string pipelineName,
            Phase phase,
            IPipelineCollection pipelines,
            ConcurrentDictionary <string, PhaseResult[]> phaseResults,
            IDocument[] outputs,
            params PipelinePhase[] dependencies)
        {
            TestPipeline  pipeline      = new TestPipeline();
            PipelinePhase pipelinePhase = new PipelinePhase(pipeline, pipelineName, phase, Array.Empty <IModule>(), NullLogger.Instance, dependencies);

            pipelines.Add(pipelineName, pipeline);
            PhaseResult[] results = new PhaseResult[4];
            results[(int)Phase.Process] = new PhaseResult(pipelineName, Phase.Process, outputs.ToImmutableArray(), 0);
            phaseResults.TryAdd(pipelineName, results);
            return(pipelinePhase);
        }
            public void GetsDocumentsForInputPhaseDuringTransformPhase()
            {
                // Given
                TestDocument a1 = new TestDocument("a1");
                TestDocument a2 = new TestDocument("a2");
                TestDocument b1 = new TestDocument("b1");
                TestDocument b2 = new TestDocument("b2");
                ConcurrentDictionary <string, PhaseResult[]> phaseResults =
                    new ConcurrentDictionary <string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
                IPipelineCollection pipelines = new TestPipelineCollection();
                PipelinePhase       phaseA    =
                    GetPipelineAndPhase("A", Phase.PostProcess, pipelines, phaseResults, new[] { a1, a2 }, Phase.Input);
                PipelinePhase phaseB =
                    GetPipelineAndPhase("B", Phase.PostProcess, pipelines, phaseResults, new[] { b1, b2 }, phaseA);
                PhaseOutputs documentCollection = new PhaseOutputs(phaseResults, phaseB, pipelines);

                // When
                IDocument[] result = documentCollection.FromPipeline("A").ToArray();

                // Then
                result.ShouldBe(new[] { a1, a2 });
            }
예제 #17
0
 private void VerifyPhase(PipelinePhase middlewarePhase)
 {
     if (Type == PipelineType.Service)
     {
         if (middlewarePhase > PipelinePhase.ServicePipelineEnd)
         {
             throw new InvalidOperationException(
                       string.Format(
                           CultureInfo.CurrentCulture,
                           ResolvePipelineBuilderMessages.CannotAddRegistrationMiddlewareToServicePipeline,
                           middlewarePhase,
                           DescribeValidEnumRange(PipelinePhase.ResolveRequestStart, PipelinePhase.ServicePipelineEnd)));
         }
     }
     else if (middlewarePhase < PipelinePhase.RegistrationPipelineStart)
     {
         throw new InvalidOperationException(
                   string.Format(
                       CultureInfo.CurrentCulture,
                       ResolvePipelineBuilderMessages.CannotAddServiceMiddlewareToRegistrationPipeline,
                       middlewarePhase,
                       DescribeValidEnumRange(PipelinePhase.ResolveRequestStart, PipelinePhase.ServicePipelineEnd)));
     }
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DelegateMiddleware"/> class.
 /// </summary>
 /// <param name="descriptor">The middleware description.</param>
 /// <param name="phase">The pipeline phase.</param>
 /// <param name="callback">The callback to execute.</param>
 public DelegateMiddleware(string descriptor, PipelinePhase phase, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
 {
     _descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
     Phase       = phase;
     _callback   = callback ?? throw new ArgumentNullException(nameof(callback));
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoreEventMiddleware"/> class.
 /// </summary>
 /// <param name="eventType">The type of event.</param>
 /// <param name="phase">The phase of the pipeine at which the event runs.</param>
 /// <param name="callback">The middleware callback to process the event.</param>
 internal CoreEventMiddleware(ResolveEventType eventType, PipelinePhase phase, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
 {
     Phase     = phase;
     _callback = callback;
     EventType = eventType;
 }
예제 #20
0
        /// <summary>
        /// Use a middleware callback in a resolve pipeline.
        /// </summary>
        /// <param name="builder">The container builder.</param>
        /// <param name="phase">The phase of the pipeline the middleware should run at.</param>
        /// <param name="callback">
        /// A callback invoked to run your middleware.
        /// This callback takes a <see cref="ResolveRequestContext"/>, containing the context for the resolve request, plus
        /// a callback to invoke to continue the pipeline.
        /// </param>
        /// <returns>The same builder instance.</returns>
        public static IResolvePipelineBuilder Use(this IResolvePipelineBuilder builder, PipelinePhase phase, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
        {
            builder.Use(phase, MiddlewareInsertionMode.EndOfPhase, callback);

            return(builder);
        }
예제 #21
0
        /// <summary>
        /// Use a middleware callback in a resolve pipeline.
        /// </summary>
        /// <param name="builder">The container builder.</param>
        /// <param name="phase">The phase of the pipeline the middleware should run at.</param>
        /// <param name="insertionMode">The insertion mode specifying whether to add at the start or end of the phase.</param>
        /// <param name="callback">
        /// A callback invoked to run your middleware.
        /// This callback takes a <see cref="ResolveRequestContext"/>, containing the context for the resolve request, plus
        /// a callback to invoke to continue the pipeline.
        /// </param>
        /// <returns>The same builder instance.</returns>
        public static IResolvePipelineBuilder Use(this IResolvePipelineBuilder builder, PipelinePhase phase, MiddlewareInsertionMode insertionMode, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
        {
            builder.Use(AnonymousDescriptor, phase, insertionMode, callback);

            return(builder);
        }
예제 #22
0
        /// <summary>
        /// Use a middleware callback in a resolve pipeline.
        /// </summary>
        /// <param name="builder">The container builder.</param>
        /// <param name="descriptor">A description for the middleware; this will show up in any resolve tracing.</param>
        /// <param name="phase">The phase of the pipeline the middleware should run at.</param>
        /// <param name="insertionMode">The insertion mode specifying whether to add at the start or end of the phase.</param>
        /// <param name="callback">
        /// A callback invoked to run your middleware.
        /// This callback takes a <see cref="ResolveRequestContext"/>, containing the context for the resolve request, plus
        /// a callback to invoke to continue the pipeline.
        /// </param>
        /// <returns>The same builder instance.</returns>
        public static IResolvePipelineBuilder Use(this IResolvePipelineBuilder builder, string descriptor, PipelinePhase phase, MiddlewareInsertionMode insertionMode, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (callback is null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            builder.Use(new DelegateMiddleware(descriptor, phase, callback), insertionMode);

            return(builder);
        }
예제 #23
0
 /// <summary>
 /// Register a resolve middleware for services providing a particular type.
 /// </summary>
 /// <typeparam name="TService">The service type.</typeparam>
 /// <param name="builder">The container builder.</param>
 /// <param name="descriptor">A description for the middleware; this will show up in any resolve tracing.</param>
 /// <param name="phase">The phase of the pipeline the middleware should run at.</param>
 /// <param name="callback">
 /// A callback invoked to run your middleware.
 /// This callback takes a <see cref="ResolveRequestContext"/>, containing the context for the resolve request, plus
 /// a callback to invoke to continue the pipeline.
 /// </param>
 /// <param name="insertionMode">The insertion mode of the middleware (start or end of phase).</param>
 public static void RegisterServiceMiddleware <TService>(this ContainerBuilder builder, string descriptor, PipelinePhase phase, MiddlewareInsertionMode insertionMode, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
 {
     builder.RegisterServiceMiddleware(typeof(TService), new DelegateMiddleware(descriptor, phase, callback), insertionMode);
 }
예제 #24
0
 /// <summary>
 /// Register a resolve middleware for services providing a particular type.
 /// </summary>
 /// <typeparam name="TService">The service type.</typeparam>
 /// <param name="builder">The container builder.</param>
 /// <param name="descriptor">A description for the middleware; this will show up in any resolve tracing.</param>
 /// <param name="phase">The phase of the pipeline the middleware should run at.</param>
 /// <param name="callback">
 /// A callback invoked to run your middleware.
 /// This callback takes a <see cref="ResolveRequestContext"/>, containing the context for the resolve request, plus
 /// a callback to invoke to continue the pipeline.
 /// </param>
 public static void RegisterServiceMiddleware <TService>(this ContainerBuilder builder, string descriptor, PipelinePhase phase, Action <ResolveRequestContext, Action <ResolveRequestContext> > callback)
 {
     builder.RegisterServiceMiddleware <TService>(descriptor, phase, MiddlewareInsertionMode.EndOfPhase, callback);
 }