Example #1
0
        public OwinMiddlewareTests()
        {
            _config = new MetricsConfig(_context);

            _server = TestServer.Create(app =>
            {
                _config.WithOwin(m => app.Use(m));

                app.Run(ctx =>
                {
                    _context.Clock.Advance(TimeUnit.Milliseconds, TimePerRequest);
                    if (ctx.Request.Path.ToString() == "/test/action")
                    {
                        return(ctx.Response.WriteAsync("response"));
                    }

                    if (ctx.Request.Path.ToString() == "/test/error")
                    {
                        ctx.Response.StatusCode = 500;
                        return(ctx.Response.WriteAsync("response"));
                    }

                    if (ctx.Request.Path.ToString() == "/test/size")
                    {
                        return(ctx.Response.WriteAsync("response"));
                    }

                    if (ctx.Request.Path.ToString() == "/test/post")
                    {
                        return(ctx.Response.WriteAsync("response"));
                    }

                    ctx.Response.StatusCode = 404;
                    return(ctx.Response.WriteAsync("not found"));
                });
            });
        }
Example #2
0
 /// <summary>
 /// Add Metrics Middleware to the Owin pipeline.
 /// Sample: Metric.Config.WithOwin( m => app.Use(m))
 /// Where app is the IAppBuilder
 /// </summary>
 /// <param name="config">Chainable configuration object.</param>
 /// <param name="middlewareRegistration">Action used to register middleware. This should generally be app.Use(middleware)</param>
 /// <returns>Chainable configuration object.</returns>
 public static MetricsConfig WithOwin(this MetricsConfig config, Action <object> middlewareRegistration)
 {
     return(config.WithOwin(middlewareRegistration, owin =>
                            owin.WithRequestMetricsConfig()
                            .WithMetricsEndpoint()));
 }