Ejemplo n.º 1
0
        public async Task ShouldRethrowByDefault()
        {
            var mapper = MapperTestHelper.CreateMapper();

            await Assert.ThrowsAsync <Exception>(async() =>
                                                 await mapper.MapExceptionAsync(new Exception()));
        }
Ejemplo n.º 2
0
        public async Task ShouldRethrowEncapsulatedSchemeResult()
        {
            var mapper = MapperTestHelper.CreateMapper(buildAction: builder =>
                                                       builder.AddScheme <RethrowAnotherExceptionHandler>("rethrow"));

            await Assert.ThrowsAsync <AggregateException>(async() =>
                                                          await mapper.MapExceptionAsync(new Exception()));
        }
Ejemplo n.º 3
0
        public async Task ShouldIgnoreUnhandledSchemeResult()
        {
            var mapper = MapperTestHelper.CreateMapper(
                buildAction: builder =>
                builder.AddScheme <EmptyExceptionHandler>("empty"));

            await Assert.ThrowsAsync <Exception>(async() =>
                                                 await mapper.MapExceptionAsync(new Exception()));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }