示例#1
0
        public void IsLoggersRequest_ReturnsExpected()
        {
            var opts = new LoggersOptions();

            var ep     = new LoggersEndpoint(opts);
            var middle = new LoggersEndpointMiddleware(null, ep);

            var context = CreateRequest("GET", "/loggers");

            Assert.True(middle.IsLoggerRequest(context));

            var context2 = CreateRequest("PUT", "/loggers");

            Assert.False(middle.IsLoggerRequest(context2));

            var context3 = CreateRequest("GET", "/badpath");

            Assert.False(middle.IsLoggerRequest(context3));

            var context4 = CreateRequest("POST", "/loggers");

            Assert.True(middle.IsLoggerRequest(context4));

            var context5 = CreateRequest("POST", "/badpath");

            Assert.False(middle.IsLoggerRequest(context5));

            var context6 = CreateRequest("POST", "/loggers/Foo.Bar.Class");

            Assert.True(middle.IsLoggerRequest(context6));

            var context7 = CreateRequest("POST", "/badpath/Foo.Bar.Class");

            Assert.False(middle.IsLoggerRequest(context7));
        }
示例#2
0
        public void LoggersEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts   = new LoggersOptions();
            var ep     = new LoggersEndpoint(opts, (IDynamicLoggerProvider)null);
            var middle = new LoggersEndpointMiddleware(null, ep);

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/loggers"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/loggers"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/badpath"));
            Assert.True(middle.RequestVerbAndPathMatch("POST", "/loggers"));
            Assert.False(middle.RequestVerbAndPathMatch("POST", "/badpath"));
            Assert.True(middle.RequestVerbAndPathMatch("POST", "/loggers/Foo.Bar.Class"));
            Assert.False(middle.RequestVerbAndPathMatch("POST", "/badpath/Foo.Bar.Class"));
        }
        public async void HandleLoggersRequestAsync_ReturnsExpected()
        {
            var opts    = new LoggersEndpointOptions();
            var mopts   = TestHelpers.GetManagementOptions(opts);
            var ep      = new TestLoggersEndpoint(opts);
            var middle  = new LoggersEndpointMiddleware(null, ep, mopts);
            var context = CreateRequest("GET", "/loggers");
            await middle.HandleLoggersRequestAsync(context);

            context.Response.Body.Seek(0, SeekOrigin.Begin);
            StreamReader rdr  = new StreamReader(context.Response.Body);
            string       json = await rdr.ReadToEndAsync();

            Assert.Equal("{}", json);
        }
        public void LoggersEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts   = new LoggersEndpointOptions();
            var mopts  = TestHelpers.GetManagementOptions(opts);
            var ep     = new LoggersEndpoint(opts, (IDynamicLoggerProvider)null);
            var middle = new LoggersEndpointMiddleware(null, ep, mopts);

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/loggers"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/cloudfoundryapplication/loggers"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/badpath"));
            Assert.True(middle.RequestVerbAndPathMatch("POST", "/cloudfoundryapplication/loggers"));
            Assert.False(middle.RequestVerbAndPathMatch("POST", "/cloudfoundryapplication/badpath"));
            Assert.True(middle.RequestVerbAndPathMatch("POST", "/cloudfoundryapplication/loggers/Foo.Bar.Class"));
            Assert.False(middle.RequestVerbAndPathMatch("POST", "/cloudfoundryapplication/badpath/Foo.Bar.Class"));
        }