Exemplo n.º 1
0
        public void ReturnSnakeCaseForTwoModelStateErrorsWhenSnakeCaseIsSet()
        {
            //--Arrange
            var attribute     = new RidgidValidateModelAttribute();
            var actionContext = new HttpActionContext();

            actionContext.ModelState["Field"] = new ModelState
            {
                Errors =
                {
                    ModelStateCustomErrorMessage.Create(1, "ErrorMessage1"),
                    ModelStateCustomErrorMessage.Create(2, "ErrorMessage2")
                }
            };
            FormatResponseMessage.SetSnakeCaseSetting(true);

            //--Act
            attribute.OnActionExecuting(actionContext);
            var response = actionContext.Response;

            //--Assert
            var contentAsString = ContentAsString(actionContext, response);

            contentAsString.ShouldBe(
                "{\"errors\":[{\"error_id\":1,\"debug_error_message\":\"ErrorMessage1\"},{\"error_id\":2,\"debug_error_message\":\"ErrorMessage2\"}]}");
        }
Exemplo n.º 2
0
        public void DoNothingWhenModelIsValid()
        {
            //--Arrange
            var attribute     = new RidgidValidateModelAttribute();
            var actionContext = new HttpActionContext();

            //--Act
            attribute.OnActionExecuting(actionContext);

            //--Assert
            actionContext.Response.ShouldBe(null);
        }
Exemplo n.º 3
0
        public void ReturnCamelCaseForOneModelStateErrorByDefault()
        {
            //--Arrange
            var attribute     = new RidgidValidateModelAttribute();
            var actionContext = new HttpActionContext();

            actionContext.ModelState["Field"] = new ModelState
            {
                Errors = { ModelStateCustomErrorMessage.Create(1, "ErrorMessage") }
            };
            FormatResponseMessage.SetSnakeCaseSetting(false);

            //--Act
            attribute.OnActionExecuting(actionContext);
            var response = actionContext.Response;

            //--Assert
            var contentAsString = ContentAsString(actionContext, response);

            contentAsString.ShouldBe("{\"errors\":[{\"errorId\":1,\"debugErrorMessage\":\"ErrorMessage\"}]}");
        }