Exemplo n.º 1
0
        public static void UpdateValidaton(UserInputModel updateUserRequest)
        {
            var validationException = new ValidationException();

            validationException.AddValidation(() => !updateUserRequest.Password.Equals(updateUserRequest.PasswordConfirmation), PasswordConfirmationKey, PasswordConfirmationMessage);
            validationException.AddValidation(() => string.IsNullOrWhiteSpace(updateUserRequest.Id), MissingIdKey, MissingIdMessage);
            validationException.ThrowIfHasError();
        }
Exemplo n.º 2
0
        public static void Validate(this ClientInputModel inputModel)
        {
            var validationException = new ValidationException();

            validationException.AddValidation(() => inputModel.AllowedGrantTypes.IsNullOrEmpty(), nameof(inputModel.AllowedGrantTypes), ALLOWED_GRANT_TYPES_VALIDATION_MESSAGE);
            validationException.AddValidation(() => string.IsNullOrWhiteSpace(inputModel.ClientName), nameof(inputModel.ClientName), CLIENT_NAME_VALIDATION_MESSAGE);
            validationException.AddValidation(() => string.IsNullOrWhiteSpace(inputModel.ClientId), nameof(inputModel.ClientId), CLIENT_ID_VALIDATION_MESSAGE);

            validationException.ThrowIfHasError();
        }
Exemplo n.º 3
0
        public static void InsertValidation(UserInputModel createUserRequest)
        {
            var validationException = new ValidationException();

            validationException.AddValidation(() => !createUserRequest.Password.Equals(createUserRequest.PasswordConfirmation), PasswordConfirmationKey, PasswordConfirmationMessage);
            validationException.ThrowIfHasError();
        }
        public void WhenCallEdit_AndTheCommandIsSave_AndThrowValidationException_TheShouldReturnEditViewWithModelStateInvalid()
        {
            // Arrange
            var clientInputModel    = CreateClientModel("1", "secret").ToInputModel();
            var someKey             = "someKey";
            var validationException = new ValidationException();

            validationException.AddValidation(() => true, someKey, "someMessage");
            ClientServiceMock.Setup(service => service.UpsertClientAsync(It.IsAny <ClientInputModel>())).Throws(validationException);

            // Act
            var actionResult      = ClientController.Edit(clientInputModel, ControllerConstants.SAVE, string.Empty).GetAwaiter().GetResult() as ViewResult;
            var actionResultModel = actionResult?.Model as ClientInputModel;

            // Assert
            Assert.IsFalse(ClientController.ModelState.IsValid);
            Assert.IsTrue(ClientController.ModelState.ContainsKey(someKey));
            Assert.IsNotNull(actionResult);
            Assert.AreEqual(clientInputModel, actionResultModel);
        }