コード例 #1
0
        public static async Task CleanTests()
        {
            using BlazorRestaurantDbContext blazorRestaurantDbContext = TestsBase.CreateDbContext();
            var testEntity = await blazorRestaurantDbContext.Location.Where(p => p.Name == TestLocation.Name).SingleAsync();

            blazorRestaurantDbContext.Location.Remove(testEntity);
            await blazorRestaurantDbContext.SaveChangesAsync();
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: efonsecab/BlazorRestaurant
        /// <summary>
        /// Configures Application
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Blazor Restaurant API");
            });
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseExceptionHandler(cfg =>
            {
                cfg.Run(async context =>
                {
                    var exceptionHandlerPathFeature =
                        context.Features.Get <IExceptionHandlerPathFeature>();
                    var error = exceptionHandlerPathFeature.Error;
                    if (error != null)
                    {
                        try
                        {
                            BlazorRestaurantDbContext blazorRestaurantDbContext =
                                this.CreateBlazorRestaurantDbContext(context.RequestServices);
                            await blazorRestaurantDbContext.ErrorLog.AddAsync(new BlazorRestaurant.DataAccess.Models.ErrorLog()
                            {
                                FullException = error.ToString(),
                                StackTrace    = error.StackTrace,
                                Message       = error.Message
                            });
                            await blazorRestaurantDbContext.SaveChangesAsync();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    ProblemHttpResponse problemHttpResponse = new()
                    {
                        Detail = error.Message,
                    };
                    await context.Response.WriteAsJsonAsync <ProblemHttpResponse>(problemHttpResponse);
                });
            });

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("index.html");
            });
        }