public void OnActionExecuting_NoParameters_NoModelError()
        {
            var sut = new ValidateActionParametersAttribute();
            var actionExecutingContext = CreateActionExecutingContext(new ParameterInfo[0]);

            // Act
            sut.OnActionExecuting(actionExecutingContext);

            Assert.Equal(0, actionExecutingContext.ModelState.ErrorCount);
        }
Ejemplo n.º 2
0
        public void OnActionExecuting_NoParameters_NoModelError()
        {
            var sut = new ValidateActionParametersAttribute();
            var actionExecutingContext = CreateActionExecutingContext(typeof(FakeController).GetMethod("MethodWithoutParams"));

            // Act
            sut.OnActionExecuting(actionExecutingContext);

            Assert.Equal(0, actionExecutingContext.ModelState.ErrorCount);
        }
Ejemplo n.º 3
0
        public void OnActionExecuting_ParameterInvalidValidationAttributes_NoModelError()
        {
            var sut = new ValidateActionParametersAttribute();

            var actionExecutingContext = CreateActionExecutingContext(typeof(FakeController).GetMethod("MethodWithInvalidAttribute"));

            // Act
            sut.OnActionExecuting(actionExecutingContext);

            Assert.Equal(1, actionExecutingContext.ModelState.ErrorCount);
            Assert.Contains("TestErrorMessage", actionExecutingContext.ModelState.First().Value.Errors.First().ErrorMessage);
        }
        public void OnActionExecuting_ParameterValidValidationAttributes_ModelErrorAdded()
        {
            var sut = new ValidateActionParametersAttribute();

            var parametersWithValidAttribute = this.GetType().GetMethod("MethodWithValidAttribute").GetParameters();

            var actionExecutingContext = CreateActionExecutingContext(parametersWithValidAttribute);

            // Act
            sut.OnActionExecuting(actionExecutingContext);

            Assert.Equal(0, actionExecutingContext.ModelState.ErrorCount);
        }
Ejemplo n.º 5
0
        public void OnActionExecuting_ParameterInvalidFromBodyAttribute_NoModelError()
        {
            var sut             = new ValidateActionParametersAttribute();
            var actionArguments = new Dictionary <string, object>
            {
                { "arg", new object() },
                { "model", new InvalidFakeViewModel() }
            };
            var actionExecutingContext = CreateActionExecutingContext(typeof(FakeController).GetMethod("MethodWithInvalidAttributeBody"),
                                                                      actionArguments);

            // Act
            sut.OnActionExecuting(actionExecutingContext);

            Assert.Equal(1, actionExecutingContext.ModelState.ErrorCount);
            Assert.Contains("TestErrorMessage", actionExecutingContext.ModelState.First().Value.Errors.First().ErrorMessage);
        }
        public void OnActionExecuting_ParameterWithoutValidationAttributes_NoModelError()
        {
            var sut = new ValidateActionParametersAttribute();

            var parameterInfo = new Mock <ParameterInfo>();

            parameterInfo.SetupGet(p => p.Name).Returns("test");

            var actionExecutingContext = CreateActionExecutingContext(
                new ParameterInfo[]
            {
                parameterInfo.Object
            }
                );

            parameterInfo
            .SetupGet(p => p.CustomAttributes)
            .Returns(new List <CustomAttributeData>());

            // Act
            sut.OnActionExecuting(actionExecutingContext);

            Assert.Equal(0, actionExecutingContext.ModelState.ErrorCount);
        }