Пример #1
0
        public void should_call_authorisation_middleware()
        {
            var configuration = new OcelotMiddlewareConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    _counter++;
                    await next.Invoke();
                }
            };

            var fileConfiguration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamPort         = 41879,
                        DownstreamScheme       = "http",
                        DownstreamHost         = "localhost",
                        UpstreamPathTemplate   = "/",
                        UpstreamHttpMethod     = "Get",
                    }
                }
            };

            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200))
            .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
            .And(x => _steps.GivenOcelotIsRunning(configuration))
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => x.ThenTheCounterIs(1))
            .BDDfy();
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env,
                                    ILoggerFactory loggerFactory, IOptions <Settings> settings)
        {
            app.UseCors("CorsPolicy");
            var configuration = new OcelotMiddlewareConfiguration();

            app.UseRequestResponseLogger();
            app.UseAuthentication();
            await app.UseOcelot(configuration);
        }
Пример #3
0
        /// <summary>
        /// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
        /// </summary>
        public void GivenOcelotIsRunning(OcelotMiddlewareConfiguration ocelotMiddlewareConfig)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("configuration.json")
                          .AddEnvironmentVariables();

            var configuration = builder.Build();

            _webHostBuilder = new WebHostBuilder();

            _webHostBuilder.ConfigureServices(s =>
            {
                s.AddSingleton(_webHostBuilder);
            });

            _ocelotServer = new TestServer(_webHostBuilder
                                           .UseConfiguration(configuration)
                                           .ConfigureServices(s =>
            {
                Action <ConfigurationBuilderCachePart> settings = (x) =>
                {
                    x.WithMicrosoftLogging(log =>
                    {
                        log.AddConsole(LogLevel.Debug);
                    })
                    .WithDictionaryHandle();
                };

                s.AddOcelotOutputCaching(settings);
                s.AddOcelot(configuration);
            })
                                           .ConfigureLogging(l =>
            {
                l.AddConsole(configuration.GetSection("Logging"));
                l.AddDebug();
            })
                                           .Configure(a =>
            {
                a.UseOcelot(ocelotMiddlewareConfig).Wait();
            }));

            _ocelotClient = _ocelotServer.CreateClient();
        }