public void ValidationsCanBeRemoved()
        {
            // Arrange
            var vm = new TestValidation();

            vm.ValidateWrapper(() => vm.Name).Check(name => name != "test").Message("test");

            // Act
            vm.Name = "test";
            string before = vm.GetErrors(nameof(vm.Name)).Cast <string>().First();

            vm.ClearValidationRules();
            vm.Name = "123";
            vm.Name = "test";
            string after = vm.GetErrors(nameof(vm.Name)).Cast <string>().FirstOrDefault();

            // Assert
            Assert.AreEqual("test", before);
            Assert.IsNull(after);
        }
        public void ValidPropertyValueIsValidated()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper(() => vm.Name).Check(name => true).Message("must not be visible");
            vm.Name = "test";

            // Assert
            Assert.IsFalse(vm.GetErrors(nameof(vm.Name)).Cast <string>().Any());
        }
        public void PropertyWithoutValidationIsNotValidated()
        {
            // Arrange
            var vm = new TestValidation
            {
                // Act
                Name = "test"
            };

            // Assert
            Assert.IsFalse(vm.GetErrors(nameof(vm.Name)).Cast <string>().Any());
        }
        public void ValidationMessageIsCorrectlySet()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper(() => vm.Name).Check(name => false).Message("test message");
            vm.Name = "test";

            // Assert
            Assert.AreEqual("test message", vm.GetErrors(nameof(vm.Name)).Cast <string>().First());
        }
        public void ExceptionInValidationActionIsSwallowed()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper(() => vm.Name).Check(name => { throw new Exception("test error"); }).Message("test message");

            vm.Name = "test";

            // Assert
            Assert.AreEqual("test error", vm.GetErrors(nameof(vm.Name)).Cast <string>().First());
        }
        public void UnchangedPropertyIsNotValidated()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper(() => vm.Name).Check(name => { throw new Exception("must not be called"); }).Message("must not be visible");

            // Assert
            var errors = vm.GetErrors(nameof(vm.Name));

            Assert.IsFalse(errors.Cast <string>().Any());
        }
        public void ExceptionInValidationActionIsSwallowed()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper( nameof( vm.Name ) ).Check( () => { throw new Exception( "test error" ); } ).Message( "test message" );

            vm.Name = "test";

            // Assert
            Assert.AreEqual( "test error", vm.GetErrors( nameof( vm.Name ) ).First() );
        }
        public void ValidPropertyValueIsValidated()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper( nameof( vm.Name ) ).Check( () => true ).Message( "must not be visible" );
            vm.Name = "test";

            // Assert
            Assert.IsFalse( vm.GetErrors( nameof( vm.Name ) ).Any() );
        }
        public void ValidationsCanBeRemoved()
        {
            // Arrange
            var vm = new TestValidation();

            vm.ValidateWrapper( nameof( vm.Name ) ).Check( () => vm.Name != "test" ).Message( "test" );

            // Act
            vm.Name = "test";
            string before = (string)vm.GetErrors( nameof( vm.Name ) ).First();
            vm.ClearValidationRules();
            vm.Name = "123";
            vm.Name = "test";
            string after = (string)vm.GetErrors( nameof( vm.Name ) ).FirstOrNull();

            // Assert
            Assert.AreEqual( "test", before );
            Assert.IsNull( after );
        }
        public void ValidationMessageIsCorrectlySet()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper( nameof( vm.Name ) ).Check( () => false ).Message( "test message" );
            vm.Name = "test";

            // Assert
            Assert.AreEqual( "test message", vm.GetErrors( nameof( vm.Name ) ).First() );
        }
        public void UnchangedPropertyIsNotValidated()
        {
            // Arrange
            var vm = new TestValidation();

            // Act
            vm.ValidateWrapper( nameof( vm.Name ) ).Check( () => { throw new Exception( "must not be called" ); } ).Message( "must not be visible" );

            // Assert
            var errors = vm.GetErrors( nameof( vm.Name ) );

            Assert.IsFalse( errors.Any() );
        }
        public void PropertyWithoutValidationIsNotValidated()
        {
            // Arrange
            var vm = new TestValidation
            {
                // Act
                Name = "test"
            };

            // Assert
            Assert.IsFalse( vm.GetErrors( nameof( vm.Name ) ).Any() );
        }