Пример #1
0
        public async Task CallsAllMatchingOrchestrators(CauseAnarchyType?firstCanHandle, CauseAnarchyType?secondCanHandle, CauseAnarchyType?thirdCanHandle)
        {
            //arrange
            var canHandleStates = new[] { firstCanHandle, secondCanHandle, thirdCanHandle };

            var orchestrators = canHandleStates.Select(state =>
                                                       GetMockOrchestratorWithAnarchyTypeAndHandlingState(state != null, state ?? CauseAnarchyType.Passive))
                                .ToList();

            var sut = new AnarchyManagerNew(orchestrators);

            var context = Get.CustomBuilderFor.MockHttpContext.Build();
            var next    = Substitute.For <RequestDelegate>();

            //act
            await sut.HandleRequest(context, next);

            //assert
            for (var i = 0; i < canHandleStates.Length; i++)
            {
                var shouldHaveHandled = canHandleStates[i] != null;
                if (shouldHaveHandled)
                {
                    await orchestrators[i].Received(1)
                    .HandleRequest(context, next);
                }
                else
                {
                    await orchestrators[i].DidNotReceive()
                    .HandleRequest(Arg.Any <HttpContext>(), Arg.Any <RequestDelegate>());
                }
            }
        }
Пример #2
0
        public async Task AlwaysCallsAlterResponseOrchestratorLast()
        {
            //arrange
            var context = Get.CustomBuilderFor.MockHttpContext.Build();
            var next    = Substitute.For <RequestDelegate>();

            DateTime?alterResponseCalledAt   = null;
            DateTime?passiveResponseCalledAt = null;

            var passiveOrchestrator = GetMockOrchestratorWithAnarchyTypeAndHandlingState(true, CauseAnarchyType.Passive);

            passiveOrchestrator.HandleRequest(context, next)
            .Returns(Task.Delay(100))
            .AndDoes(_ => passiveResponseCalledAt = DateTime.Now);

            var alterResponseOrchestrator = GetMockOrchestratorWithAnarchyTypeAndHandlingState(true, CauseAnarchyType.AlterResponse);

            alterResponseOrchestrator.HandleRequest(context, next)
            .Returns(Task.Delay(100))
            .AndDoes(_ => alterResponseCalledAt = DateTime.Now);

            var sut = new AnarchyManagerNew(new [] { alterResponseOrchestrator, passiveOrchestrator });

            //act
            await sut.HandleRequest(context, next);

            //assert
            alterResponseCalledAt.Value.Should().BeAfter(passiveResponseCalledAt.Value);
        }
Пример #3
0
        public async Task NoMatchingOrchestrator(CauseAnarchyType causeAnarchyType)
        {
            //arrange
            var orchestrator = GetMockOrchestratorWithAnarchyTypeAndHandlingState(false, causeAnarchyType);

            var sut = new AnarchyManagerNew(new[] { orchestrator });

            var context = Get.CustomBuilderFor.MockHttpContext.Build();
            var next    = Substitute.For <RequestDelegate>();

            //act
            await sut.HandleRequest(context, next);

            //assert
            await orchestrator.Received(0).HandleRequest(context, next);
        }
Пример #4
0
        public void OnlyAllowsASingleHandlingActionOrchestratorOfTypeAlterResponse()
        {
            //arrange

            var actionOrchestrators = new[]
            {
                GetMockOrchestratorWithAnarchyTypeAndHandlingState(true, CauseAnarchyType.AlterResponse),
                GetMockOrchestratorWithAnarchyTypeAndHandlingState(true, CauseAnarchyType.Passive),
                GetMockOrchestratorWithAnarchyTypeAndHandlingState(true, CauseAnarchyType.AlterResponse)
            };

            var sut = new AnarchyManagerNew(actionOrchestrators);

            var context = Get.CustomBuilderFor.MockHttpContext.Build();
            var next    = Substitute.For <RequestDelegate>();

            //act
            var exception = Assert.CatchAsync(async() => await sut.HandleRequest(context, next));

            //assert
            exception.Should().BeOfType <MultipleResponseAlteringActionsEnabledException>();
        }