Beispiel #1
0
        public async Task StartAsync_ShouldInvokeMiddleware()
        {
            // Arrange
            var middlewareInvoked = false;
            var resolver          = Substitute.For <IDependencyResolver>();

            resolver.Begin().Returns(Substitute.For <IDisposable>());
            var steps = new List <PipelineStep>
            {
                new PipelineStep
                {
                    Instance = new QuidjiboMiddleware(async(ctx, next) =>
                    {
                        middlewareInvoked = true;
                        await next();
                    })
                }
            };
            var pipeline = new QuidjiboPipeline(steps, Substitute.For <ILoggerFactory>(), resolver, Substitute.For <IPayloadProtector>(), Substitute.For <IPayloadSerializer>(), Substitute.For <IWorkDispatcher>());
            var context  = Substitute.For <IQuidjiboContext>();

            // Act
            await pipeline.StartAsync(context, CancellationToken.None);

            // Assert
            middlewareInvoked.Should().BeTrue("Start should invoke the middleware in the pipeline.");
        }
Beispiel #2
0
        public async Task StartAsync_ShouldNotInvokeAllStepsMiddlewareWhenNextIsNotInvoked()
        {
            // Arrange
            var middlewareInvoked = 0;
            var resolver          = Substitute.For <IDependencyResolver>();

            resolver.Begin().Returns(Substitute.For <IDisposable>());
            var steps = new List <PipelineStep>
            {
                new PipelineStep
                {
                    Instance = new QuidjiboMiddleware(async(ctx, next) =>
                    {
                        middlewareInvoked += 1;
                        await Task.CompletedTask;
                    })
                },
                new PipelineStep
                {
                    Instance = new QuidjiboMiddleware(async(ctx, next) =>
                    {
                        middlewareInvoked += 1;
                        await next();
                    })
                }
            };
            var pipeline = new QuidjiboPipeline(steps, Substitute.For <ILoggerFactory>(), resolver, Substitute.For <IPayloadProtector>(), Substitute.For <IPayloadSerializer>(), Substitute.For <IWorkDispatcher>());
            var context  = Substitute.For <IQuidjiboContext>();

            // Act
            await pipeline.StartAsync(context, CancellationToken.None);

            // Assert
            middlewareInvoked.Should().Be(1, "the first step did not call next.");
        }
Beispiel #3
0
        public async Task StartAsync_ShouldNotInvokeStepIfCancellationTokenHasBeenSignalled()
        {
            // Arrange
            var middlewareInvoked = 0;
            var cts      = new CancellationTokenSource();
            var resolver = Substitute.For <IDependencyResolver>();

            resolver.Begin().Returns(Substitute.For <IDisposable>());
            var steps = new List <PipelineStep>
            {
                new PipelineStep
                {
                    Instance = new QuidjiboMiddleware(async(ctx, next) =>
                    {
                        middlewareInvoked += 1;
                        cts.Cancel();
                        await next();
                    })
                },
                new PipelineStep
                {
                    Instance = new QuidjiboMiddleware(async(ctx, next) =>
                    {
                        middlewareInvoked += 1;
                        await next();
                    })
                }
            };
            var pipeline = new QuidjiboPipeline(steps, Substitute.For <ILoggerFactory>(), resolver, Substitute.For <IPayloadProtector>(), Substitute.For <IPayloadSerializer>(), Substitute.For <IWorkDispatcher>());
            var context  = Substitute.For <IQuidjiboContext>();

            // Act
            await pipeline.StartAsync(context, cts.Token);

            // Assert
            middlewareInvoked.Should().Be(1, "the pipeline was canceled before step two.");
        }