Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            BTContext context = serviceProvider.GetService <BTContext>();

            MockData.AddMockData(context);

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
        /// <summary>
        /// Configures the application using the provided builder, hosting environment, and logging factory.
        /// </summary>
        /// <param name="app">The current application builder.</param>
        /// <param name="env">The current hosting environment.</param>
        /// <param name="httpContextAccessor">Allows access to the HTTP context including request/response</param>
        /// <param name="modelBuilder">The <see cref="VersionedODataModelBuilder">model builder</see> used to create OData entity data models (EDMs).</param>
        /// <param name="provider">The API version descriptor provider used to enumerate defined API versions.</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpContextAccessor httpContextAccessor, VersionedODataModelBuilder modelBuilder, IApiVersionDescriptionProvider provider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            var httpRequestLoggingLevel = Configuration.GetValue <string>("ApplicationInsights:HttpRequestLoggingLevel");

            app.UseCors("AllOrigins");
            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseClientRateLimiting();
            // Add mock data to the database if it is empty (demo uses in memory database only, so always starts empty)
            var context = app.ApplicationServices.GetService <ApiDbContext>();

            MockData.AddMockData(context);
            // Add custom telemetry initializer to add user name from the HTTP context
            app.UseMiddleware <CaptureRequestMiddleware>(httpRequestLoggingLevel);
            var configuration = app.ApplicationServices.GetService <TelemetryConfiguration>();

            configuration.TelemetryInitializers.Add(new TelemetryInitializer(httpContextAccessor));
            app.UseODataBatching();
            app.UseApiVersioning(); // added to fix issue outlined in https://github.com/OData/WebApi/issues/1754
            app.UseMvc(routes => {
                routes.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
                routes.MapVersionedODataRoutes("ODataRoute", "odata", modelBuilder.GetEdmModels());
                routes.MapODataServiceRoute("ODataBatch", null,
                                            configureAction: containerBuilder => containerBuilder
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel),
                                                        sp => modelBuilder.GetEdmModels().First())
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEnumerable <IODataRoutingConvention>),
                                                        sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("ODataBatch", routes))
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataBatchHandler),
                                                        sp => {
                    var oDataBatchHandler = new TransactionalODataBatchHandler();
                    oDataBatchHandler.MessageQuotas.MaxOperationsPerChangeset = 5000;
                    return(oDataBatchHandler);
                })
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataMessageReaderSettings),
                                                        sp => {
                    ODataMessageReaderSettings odataMessageReaderSettings = new ODataMessageReaderSettings();
                    odataMessageReaderSettings.MessageQuotas.MaxOperationsPerChangeset = 5000;
                    return(odataMessageReaderSettings);
                })
                                            );
                routes.EnableDependencyInjection();
            });
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(options => {
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.SwaggerEndpoint(
                        $"/swagger/{description.GroupName}/swagger.json",
                        description.GroupName.ToUpperInvariant());
                }
                options.DefaultModelExpandDepth(2);
                options.DefaultModelsExpandDepth(-1);
                options.DefaultModelRendering(ModelRendering.Model);
                options.DisplayRequestDuration();
                options.DocExpansion(DocExpansion.None);
            });
        }
Esempio n. 3
0
 public BaseTests()
 {
     db = new BTContext();
     MockData.AddMockData(db);
 }