예제 #1
0
        public void CallsTransformProviders()
        {
            var provider1 = new TestTransformProvider();
            var provider2 = new TestTransformProvider();
            var provider3 = new TestTransformProvider();
            var builder   = new TransformBuilder(new ServiceCollection().BuildServiceProvider(),
                                                 Array.Empty <ITransformFactory>(), new[] { provider1, provider2, provider3 });

            var route  = new ProxyRoute();
            var errors = builder.ValidateRoute(route);

            Assert.Empty(errors);
            Assert.Equal(1, provider1.ValidateRouteCalls);
            Assert.Equal(1, provider2.ValidateRouteCalls);
            Assert.Equal(1, provider3.ValidateRouteCalls);

            var cluster = new Cluster();

            errors = builder.ValidateCluster(cluster);
            Assert.Empty(errors);
            Assert.Equal(1, provider1.ValidateClusterCalls);
            Assert.Equal(1, provider2.ValidateClusterCalls);
            Assert.Equal(1, provider3.ValidateClusterCalls);

            var transforms = builder.BuildInternal(route, cluster);

            Assert.Equal(1, provider1.ApplyCalls);
            Assert.Equal(1, provider2.ApplyCalls);
            Assert.Equal(1, provider3.ApplyCalls);

            Assert.Equal(3, transforms.ResponseTrailerTransforms.Count);
        }
예제 #2
0
        public void CallsTransformFactories()
        {
            var factory1 = new TestTransformFactory("1");
            var factory2 = new TestTransformFactory("2");
            var factory3 = new TestTransformFactory("3");
            var builder  = new TransformBuilder(new ServiceCollection().BuildServiceProvider(),
                                                new[] { factory1, factory2, factory3 }, Array.Empty <ITransformProvider>());

            var route = new ProxyRoute().WithTransform(transform =>
            {
                transform["2"] = "B";
            });
            var errors = builder.ValidateRoute(route);

            Assert.Empty(errors);
            Assert.Equal(1, factory1.ValidationCalls);
            Assert.Equal(1, factory2.ValidationCalls);
            Assert.Equal(0, factory3.ValidationCalls);

            var transforms = builder.BuildInternal(route, new Cluster());

            Assert.Equal(1, factory1.BuildCalls);
            Assert.Equal(1, factory2.BuildCalls);
            Assert.Equal(0, factory3.BuildCalls);

            Assert.Single(transforms.ResponseTrailerTransforms);
        }
예제 #3
0
        private static StructuredTransformer BuildTransform(ProxyRoute proxyRoute)
        {
            var builder = new TransformBuilder(NullTemplateBinderFactory.Instance, new TestRandomFactory());

            return(builder.BuildInternal(proxyRoute.Transforms));
        }