public void Configure(IApplicationBuilder builder, IConfiguration configuration) { builder.UseMultipleErrorHandlerPipelines(app => { MapExtensions.Map( app, "/throws", inner => RunExtensions.Run( inner, async ctx => { await Task.Yield(); throw new Exception("Map exception"); })); MvcApplicationBuilderExtensions.UseMvc( app, routes => { MapRouteRouteBuilderExtensions.MapRoute(routes, "custom", "Test/{action=Index}", new { Controller = "MyTest" }); MapRouteRouteBuilderExtensions.MapRoute(routes, "default", "{controller=Home}/{action=Index}/{id?}"); }); }); }
public async Task ExceptionHandlerMustSaveExceptionToLogStoreBecauseOfExceptionInRequest() { using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs { AdditionalDependencies = manager => { manager.RegisterOwinMiddlewareUsing(owinApp => { MapExtensions.Map((IAppBuilder)owinApp, (string)"/Exception", innerApp => { AppBuilderUseExtensions.Use <ExceptionThrownMiddleware>(innerApp); }); }); } })) { try { TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner"); await testEnvironment.Server.GetHttpClient(token) .GetAsync("/Exception"); Assert.Fail(); } catch { IScopeStatusManager scopeStatusManager = TestDependencyManager.CurrentTestDependencyManager .Objects.OfType <IScopeStatusManager>() .Last(); A.CallTo(() => scopeStatusManager.MarkAsFailed()) .MustHaveHappened(Repeated.Exactly.Once); ILogger logger = TestDependencyManager.CurrentTestDependencyManager .Objects.OfType <ILogger>() .Last(); A.CallTo(() => logger.LogExceptionAsync(A <Exception> .That.Matches(e => e is InvalidOperationException), A <string> .Ignored)) .MustHaveHappened(Repeated.Exactly.Once); IEnumerable <LogData> logData = logger.LogData; logData.Single(c => c.Key == "ExceptionType" && ((string)c.Value).Contains("InvalidOperationException")); logData.Single(c => c.Key == nameof(IRequestInformationProvider.HttpMethod) && (string)c.Value == "GET"); logData.Single(c => c.Key == "UserId" && (string)c.Value == "ValidUserName"); } } }
public static IAppBuilder MapAndLog(this IAppBuilder app, string pathMatch, Action <IAppBuilder> configuration) { return(MapExtensions.Map(app, pathMatch, configuration)); }