Exemplo n.º 1
0
        public void ErrorHttpCode_Is_Honoured_in_Error_Response_Test(int?errorHttpCode, int expectedErrorHttpCode)
        {
            var defaultValue = ActionResultConventions.ErrorHttpCode;

            // GIVEN a custom HTTP code for errors
            if (errorHttpCode.HasValue)
            {
                ActionResultConventions.ErrorHttpCode = errorHttpCode.Value;
            }

            // WHEN a IDomainResult with Status 'Error' gets converted to ActionResult
            var domainResult = IDomainResult.Failed();
            var actionRes    = domainResult.ToActionResult() as ObjectResult;

            // THEN the HTTP code is expected
            Assert.Equal(expectedErrorHttpCode, actionRes !.StatusCode);

            ActionResultConventions.ErrorHttpCode = defaultValue;
        }
Exemplo n.º 2
0
        public void ErrorProblemDetailsTitle_Is_Honoured_in_Error_Response_Test(string errorTitle, string expectedErrorTitle)
        {
            var defaultValue = ActionResultConventions.ErrorProblemDetailsTitle;

            // GIVEN a custom HTTP code for errors
            if (!string.IsNullOrEmpty(errorTitle))
            {
                ActionResultConventions.ErrorProblemDetailsTitle = errorTitle;
            }

            // WHEN a IDomainResult with Status 'Error' gets converted to ActionResult
            var domainResult   = IDomainResult.Failed();
            var actionRes      = domainResult.ToActionResult() as ObjectResult;
            var problemDetails = actionRes !.Value as ProblemDetails;

            // THEN the ProblemDetails Title is expected
            Assert.Equal(expectedErrorTitle, problemDetails !.Title);

            ActionResultConventions.ErrorProblemDetailsTitle = defaultValue;
        }