public async Task SetsStatusCode(JSendExceptionResult result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.StatusCode.Should().Be(result.StatusCode);
        }
        public async Task SetsContentTypeHeader(JSendExceptionResult result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.Content.Headers.ContentType.MediaType.Should().Be("application/json");
        }
 public void RequestIsCorrectlyInitialized(Exception ex, string message, int? code, object data,
     bool includeErrorDetail, HttpRequestMessage request)
 {
     // Exercise system
     var result = new JSendExceptionResult(ex, message, code, data, includeErrorDetail, request);
     // Verify outcome
     result.Request.Should().Be(request);
 }
 public void RequestIsCorrectlyInitializedUsingController(
     Exception ex, string message, int? code, object data, ApiController controller)
 {
     // Exercise system
     var result = new JSendExceptionResult(ex, message, code, data, controller);
     // Verify outcome
     result.Request.Should().Be(controller.Request);
 }
        public void ExceptionIsCorrectlyInitialized(Exception ex, string message, int?code, object data,
                                                    ApiController controller)
        {
            // Exercise system
            var result = new JSendExceptionResult(ex, message, code, data, controller);

            // Verify outcome
            result.Exception.Should().Be(ex);
        }
        public void ResponseDataIsSetToData_When_DataIsNotNull(
            Exception ex, string message, int?code, object data, ApiController controller)
        {
            // Exercise system
            var result = new JSendExceptionResult(ex, message, code, data, controller);

            // Verify outcome
            result.Response.Data.Should().BeSameAs(data);
        }
        public void ResponseMessageIsSetToMessage_When_MessageIsNotNull(
            Exception ex, string message, int?code, object data, ApiController controller)
        {
            // Exercise system
            var result = new JSendExceptionResult(ex, message, code, data, controller);

            // Verify outcome
            result.Response.Message.Should().Be(message);
        }
        public void RequestIsCorrectlyInitialized(Exception ex, string message, int?code, object data,
                                                  bool includeErrorDetail, HttpRequestMessage request)
        {
            // Exercise system
            var result = new JSendExceptionResult(ex, message, code, data, includeErrorDetail, request);

            // Verify outcome
            result.Request.Should().Be(request);
        }
        public void ResponseDataIsSetToNull_When_DataIsNull_And_ControllerIsConfiguredToNotIncludeErrorDetails(
            Exception ex, string message, int?code, ApiController controller)
        {
            // Fixture setup
            controller.RequestContext.IncludeErrorDetail = false;
            // Exercise system
            var result = new JSendExceptionResult(ex, message, code, null, controller);

            // Verify outcome
            result.Response.Data.Should().BeNull();
        }
        public void ResponseMessageIsSetToDefaultMessage_When_MessageIsNull_And_ControllerIsConfiguredToNotIncludeErrorDetails(
            Exception ex, int?code, object data, ApiController controller)
        {
            // Fixture setup
            controller.RequestContext.IncludeErrorDetail = false;
            // Exercise system
            var result = new JSendExceptionResult(ex, null, code, data, controller);

            // Verify outcome
            result.Response.Message.Should().Be(StringResources.DefaultErrorMessage);
        }
        public async Task ResponseIsSerializedIntoBody(JSendExceptionResult result)
        {
            // Fixture setup
            var serializedResponse = JsonConvert.SerializeObject(result.Response);
            // Exercise system
            var httpResponse = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            var content = await httpResponse.Content.ReadAsStringAsync();

            content.Should().Be(serializedResponse);
        }
        /// <summary>
        /// Handles an exception by creating a <see cref="JSendExceptionResult"/> with the unhandled exception.
        /// </summary>
        /// <param name="actionExecutedContext">The context for the action.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns></returns>
        public override async Task OnExceptionAsync(HttpActionExecutedContext actionExecutedContext,
            CancellationToken cancellationToken)
        {
            if (actionExecutedContext == null) throw new ArgumentNullException("actionExecutedContext");

            Contract.Assert(actionExecutedContext.Exception != null);

            var exception = actionExecutedContext.Exception;
            var includeErrorDetail = actionExecutedContext.Request.ShouldIncludeErrorDetail();
            var request = actionExecutedContext.Request;

            var result = new JSendExceptionResult(exception, null, null, null,
                includeErrorDetail, request);

            actionExecutedContext.Response = await result.ExecuteAsync(cancellationToken);
        }
        /// <summary>
        /// Handles an exception by creating a <see cref="JSendExceptionResult"/> with the unhandled exception.
        /// </summary>
        /// <param name="actionExecutedContext">The context for the action.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns></returns>
        public override async Task OnExceptionAsync(HttpActionExecutedContext actionExecutedContext,
                                                    CancellationToken cancellationToken)
        {
            if (actionExecutedContext == null)
            {
                throw new ArgumentNullException("actionExecutedContext");
            }

            Contract.Assert(actionExecutedContext.Exception != null);

            var exception          = actionExecutedContext.Exception;
            var includeErrorDetail = actionExecutedContext.Request.ShouldIncludeErrorDetail();
            var request            = actionExecutedContext.Request;

            var result = new JSendExceptionResult(exception, null, null, null,
                                                  includeErrorDetail, request);

            actionExecutedContext.Response = await result.ExecuteAsync(cancellationToken);
        }
 public void StatusCodeIs500(JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
 }
 public void IsHttpActionResult(JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.Should().BeAssignableTo <IHttpActionResult>();
 }
 public void IsHttpActionResult(JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.Should().BeAssignableTo<IHttpActionResult>();
 }
 public async Task SetsContentTypeHeader(JSendExceptionResult result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.Content.Headers.ContentType.MediaType.Should().Be("application/json");
 }
 public void ResponseCodeIsCorrectlySet([Frozen] int? code, JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.Response.Code.Should().HaveValue()
         .And.Be(code);
 }
 public async Task SetsStatusCode(JSendExceptionResult result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.StatusCode.Should().Be(result.StatusCode);
 }
 public void ResponseDataIsSetToData_When_DataIsNotNull(
     Exception ex, string message, int? code, object data, ApiController controller)
 {
     // Exercise system 
     var result = new JSendExceptionResult(ex, message, code, data, controller);
     // Verify outcome
     result.Response.Data.Should().BeSameAs(data);
 }
 public void ResponseDataIsSetToNull_When_DataIsNull_And_ControllerIsConfiguredToNotIncludeErrorDetails(
     Exception ex, string message, int? code, ApiController controller)
 {
     // Fixture setup
     controller.RequestContext.IncludeErrorDetail = false;
     // Exercise system
     var result = new JSendExceptionResult(ex, message, code, null, controller);
     // Verify outcome
     result.Response.Data.Should().BeNull();
 }
 public void ResponseMessageIsSetToMessage_When_MessageIsNotNull(
     Exception ex, string message, int? code, object data, ApiController controller)
 {
     // Exercise system
     var result = new JSendExceptionResult(ex, message, code, data, controller);
     // Verify outcome
     result.Response.Message.Should().Be(message);
 }
 public void ResponseMessageIsSetToDefaultMessage_When_MessageIsNull_And_ControllerIsConfiguredToNotIncludeErrorDetails(
     Exception ex, int? code, object data, ApiController controller)
 {
     // Fixture setup
     controller.RequestContext.IncludeErrorDetail = false;
     // Exercise system
     var result = new JSendExceptionResult(ex, null, code, data, controller);
     // Verify outcome
     result.Response.Message.Should().Be(StringResources.DefaultErrorMessage);
 }
 public async Task ResponseIsSerializedIntoBody(JSendExceptionResult result)
 {
     // Fixture setup
     var serializedResponse = JsonConvert.SerializeObject(result.Response);
     // Exercise system
     var httpResponseMessage = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     var content = await httpResponseMessage.Content.ReadAsStringAsync();
     content.Should().Be(serializedResponse);
 }
 public void ResponseIsError(JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.Response.Should().BeAssignableTo<ErrorResponse>();
 }
 public void ResponseIsError(JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.Response.Should().BeAssignableTo <ErrorResponse>();
 }
 public void ResponseCodeIsCorrectlySet([Frozen] int?code, JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.Response.Code.Should().HaveValue()
     .And.Be(code);
 }
 public void StatusCodeIs500(JSendExceptionResult result)
 {
     // Exercise system and verify outcome
     result.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
 }