Example #1
0
        public async void HandleEnvRequestAsync_ReturnsExpected()
        {
            var opts = new EnvEndpointOptions();

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appSettings);
            var config = configurationBuilder.Build();
            var host   = new HostingEnvironment()
            {
                EnvironmentName = "EnvironmentName"
            };
            var mgmtOptions = TestHelpers.GetManagementOptions(opts);
            var ep          = new EnvEndpoint(opts, config, host);
            var middle      = new EnvEndpointMiddleware(null, ep, mgmtOptions);

            var context = CreateRequest("GET", "/env");
            await middle.HandleEnvRequestAsync(context);

            context.Response.Body.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(context.Response.Body, Encoding.UTF8);
            var json   = await reader.ReadLineAsync();

            var expected = "{\"activeProfiles\":[\"EnvironmentName\"],\"propertySources\":[{\"properties\":{\"management:endpoints:path\":{\"value\":\"/cloudfoundryapplication\"},\"management:endpoints:enabled\":{\"value\":\"true\"},\"Logging:LogLevel:Steeltoe\":{\"value\":\"Information\"},\"Logging:LogLevel:Pivotal\":{\"value\":\"Information\"},\"Logging:LogLevel:Default\":{\"value\":\"Warning\"},\"Logging:IncludeScopes\":{\"value\":\"false\"}},\"name\":\"MemoryConfigurationProvider\"}]}";

            Assert.Equal(expected, json);
        }
Example #2
0
        public void EnvEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts = new EnvEndpointOptions();
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appSettings);
            var config = configurationBuilder.Build();
            var host   = new HostingEnvironment()
            {
                EnvironmentName = "EnvironmentName"
            };
            var ep   = new EnvEndpoint(opts, config, host);
            var mgmt = new CloudFoundryManagementOptions()
            {
                Path = "/"
            };

            mgmt.EndpointOptions.Add(opts);
            var middle = new EnvEndpointMiddleware(null, ep, new List <IManagementOptions> {
                mgmt
            });

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/env"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/env"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/badpath"));
        }