Esempio n. 1
0
        public void WithRequestTimingOptionsThrowsWhenActionNull()
        {
            var    options = new ServerTimingOptions();
            Action invoke  = () => options.WithRequestTimingOptions(null);

            invoke.Should().Throw <ArgumentNullException>();
        }
Esempio n. 2
0
        public void TotalMetricNamePropertyValidatesValue(string totalMetricName)
        {
            var    options  = new ServerTimingOptions();
            Action validate = () => options.TotalMetricName = totalMetricName;

            validate.Should().Throw <ArgumentException>()
            .Which.ParamName.Should().Contain(nameof(ServerTimingOptions.TotalMetricName));
        }
Esempio n. 3
0
        public void UseServerTimingWithOptionsThrowsWhenAppNull()
        {
            var    options = new ServerTimingOptions();
            Action use     = () => ApplicationBuilderExtensions.UseServerTiming(null, options);

            use.Should().Throw <ArgumentNullException>()
            .Which.ParamName.Should().Be("app");
        }
Esempio n. 4
0
        public void WithRequestTimingOptionsCapturesAction()
        {
            var options = new ServerTimingOptions();
            var called  = false;

            options.WithRequestTimingOptions((_, __) => called = true);
            options.ConfigureRequestTimingOptions(null, null);
            called.Should().BeTrue();
        }
Esempio n. 5
0
        public void ConfigureRequestTimingOptionsInitializedToEmptyAction()
        {
            var    options        = new ServerTimingOptions();
            var    httpContext    = new DefaultHttpContext();
            var    requestOptions = new RequestTimingOptions();
            Action invoke         = () => options.ConfigureRequestTimingOptions(httpContext, requestOptions);

            invoke.Should().NotThrow();
        }
Esempio n. 6
0
 public void GlobalSetup()
 {
     _serverTimingOptions = new ServerTimingOptions
     {
         InvokeCallbackServices = true
     };
     _serverTimingOptions.WithRequestTimingOptions((_, requestOptions) => requestOptions.WriteHeader = true);
     _middleware = new ServerTimingMiddleware(_ => Task.CompletedTask, _serverTimingOptions, null);
     _callbacks  = Factory.CreateCallbacks(1);
 }
Esempio n. 7
0
        public void GlobalSetup()
        {
            _httpContext  = new DefaultHttpContext();
            _serverTiming = Factory.CreateServerTiming();

            _serverTimingOptions  = new ServerTimingOptions();
            _requestTimingOptions = new RequestTimingOptions {
                WriteHeader = true
            };
            _middleware = new ServerTimingMiddleware(_ => Task.CompletedTask, _serverTimingOptions, null);
        }
Esempio n. 8
0
        public void UseServerTimingInvokesConfigurationAction()
        {
            var serviceProvider = new ServiceCollection().BuildServiceProvider();
            var app             = new ApplicationBuilder(serviceProvider);

            ServerTimingOptions capturedOptions = null;

            app.UseServerTiming(options => capturedOptions = options);

            capturedOptions.Should().NotBeNull();
        }
Esempio n. 9
0
        public void InvokeCallbackServicesInitializedToFalse()
        {
            var options = new ServerTimingOptions();

            options.InvokeCallbackServices.Should().BeFalse();
        }
Esempio n. 10
0
        public void ValidateMetricsInitializedToFalse()
        {
            var options = new ServerTimingOptions();

            options.ValidateMetrics.Should().BeFalse();
        }
Esempio n. 11
0
        public void TotalMetricDescriptionInitializedToDefault()
        {
            var options = new ServerTimingOptions();

            options.TotalMetricDescription.Should().Be(ServerTimingOptions.DefaultTotalDescription);
        }
Esempio n. 12
0
        public void TotalMetricNameInitializedToDefault()
        {
            var options = new ServerTimingOptions();

            options.TotalMetricName.Should().Be(ServerTimingOptions.DefaultTotalMetricName);
        }
Esempio n. 13
0
        public void TimingAllowOriginsInitializedToEmpty()
        {
            var options = new ServerTimingOptions();

            options.TimingAllowOrigins.Should().BeEmpty();
        }
Esempio n. 14
0
        /// <summary>
        /// Adds a <see cref="ServerTimingMiddleware"/> to application pipeline.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/> passed to Configure method.</param>
        /// <param name="options">The <see cref="ServerTimingOptions"/> to configure the middleware.</param>
        /// <returns>The original app parameter</returns>
        public static IApplicationBuilder UseServerTiming(this IApplicationBuilder app, ServerTimingOptions options)
        {
            if (app is null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(app.UseMiddleware <ServerTimingMiddleware>(options));
        }