public void OnExceptionAsync_should_handle_error()
        {
            var context = new MethodExecutedContext(new MethodExecutingContext
            {
                InvocationContext = new Dictionary<string, object>()
            });
            var att = Substitute.ForPartsOf<ExceptionFilterAttribute>();
            att.When(x => x.OnException(Arg.Any<MethodExceptionContext>())).Do(c => { throw new Exception("Test exception"); } );
            var exceptionContext = new MethodExceptionContext(new Exception(), context);
            var t = att.OnExceptionAsync(exceptionContext);

            Assert.IsTrue(t.Status == TaskStatus.Faulted);
            Assert.AreEqual("Test exception", t.Exception.InnerExceptions[0].Message);
            Assert.IsNull(context.Result);
            Assert.IsNull(exceptionContext.Result);
        }
Ejemplo n.º 2
0
 public override Task OnExceptionAsync(MethodExceptionContext exceptionContext)
 {
     exceptionContext.Handled = true;
     exceptionContext.Result = "Error OnExceptionAsync";
     //Console.WriteLine($"{DateTime.Now} {nameof(MethodExceptionContext)} OnExceptionAsync");
     return TaskHelpers.DefaultCompleted;
 }
 public override Task OnExceptionAsync(MethodExceptionContext exceptionContext)
 {
     exceptionContext.Handled = true;
     return TaskHelpers.DefaultCompleted;
 }
Ejemplo n.º 4
0
 public override void OnException(MethodExceptionContext exceptionContext)
 {
     exceptionContext.Handled = true;
     exceptionContext.Result = "Error OnException";
     //Console.WriteLine($"{DateTime.Now} {nameof(MethodExceptionContext)} OnException");
 }
 public override void OnException(MethodExceptionContext exceptionContext)
 {
     exceptionContext.Handled = true;
     
 }