public void WhenValidatingValidValidatableObjectCommandThenReturnsTrue()
        {
            // Assign
            ICommandValidator validator = new DefaultCommandValidator();
            ICommand command = new ValidatableObjectCommand(true);
            CommandHandlerRequest request = new CommandHandlerRequest(this.configuration, command);

            // Act
            bool result = validator.Validate(request);

            // Assert
            Assert.True(result);
            Assert.Equal(0, request.ModelState.Count);
        }
        public void WhenValidatingInvalidDataAnnotationsValidatableCommandThenReturnsFalse()
        {
            // Assign
            ICommandValidator validator = new DefaultCommandValidator();
            ICommand command = new DataAnnotationsValidatableCommand { Property1 = "01234567890123456789" };
            CommandHandlerRequest request = new CommandHandlerRequest(this.configuration, command);

            // Act
            bool result = validator.Validate(request);

            // Assert
            Assert.False(result);
            Assert.Equal(1, request.ModelState.Count);
        }
        public void WhenValidatingInvalidValidatableObjectCommandThenReturnsFalse()
        {
            // Assign
            ICommandValidator validator = new DefaultCommandValidator();
            ICommand command = new ValidatableObjectCommand(false);
            CommandHandlerRequest request = new CommandHandlerRequest(this.configuration, command);

            // Act
            bool result = validator.Validate(request);

            // Assert
            Assert.False(result);
            Assert.Equal(2, request.ModelState.Sum(kvp => kvp.Value.Errors.Count));
        }
        public void WhenValidatingCommandWithUriThenReturnsTrue()
        {
            // Assign
            ICommandValidator validator = new DefaultCommandValidator();
            CommandWithUriProperty command = new CommandWithUriProperty();
            command.Property1 = new Uri("/test/values", UriKind.Relative);
            CommandHandlerRequest request = new CommandHandlerRequest(this.configuration, command);

            // Act
            bool result = validator.Validate(request);

            // Assert
            // A lots of properties of Uri throw exceptions but its still valid
            Assert.True(result);
            Assert.Equal(0, request.ModelState.Count);
        }
        public void WhenValidatingInvalidMixedValidatableCommandThenReturnsFalse()
        {
            // Assign
            ICommandValidator validator = new DefaultCommandValidator();
            MixedValidatableCommand command = new MixedValidatableCommand(false);
            command.Property1 = "123456789456132456";
            CommandHandlerRequest request = new CommandHandlerRequest(this.configuration, command);

            // Act
            bool result = validator.Validate(request);

            // Assert
            Assert.False(result);

            // Validator ignore IValidatableObject validation until DataAnnotations succeed.
            Assert.Equal(1, request.ModelState.Count);
        }