public void ValidateModelWithInvalidModel() {
            // Arrange
            Controller controller = new SimpleController();
            TryValidateModelModel model = new TryValidateModelModel { IntegerProperty = 5 };

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                () => controller.ValidateModel(model, "Prefix"),
                "The model of type '" + model.GetType().FullName + "' is not valid.");

            Assert.AreEqual("Out of range!", controller.ModelState["Prefix.IntegerProperty"].Errors[0].ErrorMessage);
        }
        public void ValidateModelGuardClauses() {
            // Arrange
            Controller controller = new SimpleController();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => controller.ValidateModel(null),
                "model");
        }
        public void ValidateModelWithValidModel() {
            // Arrange
            Controller controller = new SimpleController();
            TryValidateModelModel model = new TryValidateModelModel { IntegerProperty = 15 };

            // Act
            controller.ValidateModel(model);

            // Assert
            Assert.IsTrue(controller.ModelState.IsValid);
        }
Esempio n. 4
0
        public void ValidateModelGuardClauses()
        {
            // Arrange
            Controller controller = new SimpleController();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => controller.ValidateModel(null),
                "model");
        }