public async Task ShouldRethrowByDefault() { var mapper = MapperTestHelper.CreateMapper(); await Assert.ThrowsAsync <Exception>(async() => await mapper.MapExceptionAsync(new Exception())); }
public async Task ShouldRethrowEncapsulatedSchemeResult() { var mapper = MapperTestHelper.CreateMapper(buildAction: builder => builder.AddScheme <RethrowAnotherExceptionHandler>("rethrow")); await Assert.ThrowsAsync <AggregateException>(async() => await mapper.MapExceptionAsync(new Exception())); }
public async Task ShouldIgnoreUnhandledSchemeResult() { var mapper = MapperTestHelper.CreateMapper( buildAction: builder => builder.AddScheme <EmptyExceptionHandler>("empty")); await Assert.ThrowsAsync <Exception>(async() => await mapper.MapExceptionAsync(new Exception())); }
public async Task ShouldReturnSchemeResult() { var result = new object(); var mapper = MapperTestHelper.CreateMapper(buildAction: builder => builder.AddParameterizedScheme <ReturnResultExceptionHandler>("return", result)); var actual = await mapper.MapExceptionAsync(new Exception()); Assert.Equal(result, actual); }
public async Task ShouldReturnNullIfSuppressDefault() { var mapper = MapperTestHelper.CreateMapper(opt => opt.FallbackExceptionHandler = async ctx => { await Task.Yield(); ctx.Result = ExceptionHandlingResult.Return(null); }); var result = await mapper.MapExceptionAsync(new Exception()); Assert.Null(result); }
public async Task ShouldReturnSchemeResultAsPerOptions() { var result = new object(); var mapper = MapperTestHelper.CreateMapper(buildAction: builder => builder .AddParameterizedScheme <ExceptionHandlerWithOptionsOptions, object, ExceptionHandlerWithOptions>( "return1", opt => opt.Run = false, new object()) .AddParameterizedScheme <ExceptionHandlerWithOptionsOptions, object, ExceptionHandlerWithOptions>( "return2", opt => opt.Run = true, result) .AddParameterizedScheme <ExceptionHandlerWithOptionsOptions, object, ExceptionHandlerWithOptions>( "return3", opt => opt.Run = true, new object())); var actual = await mapper.MapExceptionAsync(new Exception()); Assert.Equal(result, actual); }