public void TestSetup()
        {
            request1 = Request.Get("/1");
            request2 = Request.Get("/2");
            request3 = Request.Get("/3");
            request4 = Request.Get("/4");
            request5 = Request.Get("/5");

            context = new RequestContext(request1, new RequestParameters(Strategy.SingleReplica), Budget.Infinite, new ConsoleLog(), null, int.MaxValue);

            transform1 = Substitute.For <IRequestTransform>();
            transform1.Transform(Arg.Any <Request>()).Returns(_ => request2);

            transform2 = Substitute.For <IRequestTransform>();
            transform2.Transform(Arg.Any <Request>()).Returns(_ => request3);

            transform3 = Substitute.For <IAsyncRequestTransform>();
            transform3.TransformAsync(Arg.Any <Request>()).Returns(_ => request4);

            transform4 = Substitute.For <IAsyncRequestTransform>();
            transform4.TransformAsync(Arg.Any <Request>()).Returns(_ => request5);

            transforms = new List <IRequestTransformMetadata> {
                transform1, transform2, transform3, transform4
            };

            module = new RequestTransformationModule(transforms);
        }
        public void Should_apply_all_request_transforms_in_order()
        {
            Execute();

            context.Request.Should().BeSameAs(request3);

            Received.InOrder(
                () =>
            {
                transform1.Transform(request1);
                transform2.Transform(request2);
            });
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            request1 = Request.Get("/1");
            request2 = Request.Get("/2");
            request3 = Request.Get("/3");

            context = new RequestContext(request1, Strategy.SingleReplica, Budget.Infinite, new ConsoleLog(), CancellationToken.None, null, int.MaxValue);

            transform1 = Substitute.For <IRequestTransform>();
            transform1.Transform(Arg.Any <Request>()).Returns(request2);

            transform2 = Substitute.For <IRequestTransform>();
            transform2.Transform(Arg.Any <Request>()).Returns(request3);

            transforms = new List <IRequestTransform> {
                transform1, transform2
            };

            module = new RequestTransformationModule(transforms);
        }
Exemplo n.º 4
0
        public override Task ProcessRequest(IRequestContext context)
        {
            if (_nextNode == null)
            {
                context.Log?.Log(LogType.Step, LogLevel.Important, () => $"Transform node '{Name}' has no downstream and will return 503");

                return(Task.Run(() =>
                {
                    context.Outgoing.StatusCode = 503;
                    context.Outgoing.ReasonPhrase = "Transform " + Name + " has no downstream";
                    context.Outgoing.SendHeaders(context);
                }));
            }

            if (Disabled)
            {
                context.Log?.Log(LogType.Step, LogLevel.Standard, () => $"Transform node '{Name}' is disabled and will not perform any transformation");
            }
            else
            {
                if (_requestTransform != null)
                {
                    context.Log?.Log(LogType.Logic, LogLevel.Detailed, () => $"Transform node '{Name}' inserting request transform into the incoming pipe");
                    _requestTransform.Transform(context);
                }

                if (_responseTransform != null)
                {
                    context.Log?.Log(LogType.Logic, LogLevel.Detailed, () => $"Transform node '{Name}' inserting response transform into the outgoing pipe");
                    _responseTransform.Transform(context);
                }
            }

            context.Log?.Log(LogType.Step, LogLevel.Standard, () => $"Transform node '{Name}' forwarding to '{_nextNode.Name}'");

            return(_nextNode.ProcessRequest(context));
        }