コード例 #1
0
        public void Validation_Of_Field_When_Valid_Should_Succeeed()
        {
            var model = new MockModelWithValidation() { Title = "A valid Title" };
            var target = new BindableValidator(model);

            bool isValid = target.ValidateProperty("Title");

            Assert.True(isValid);
            Assert.True(target.GetAllErrors().Values.Count == 0);
        }
コード例 #2
0
        public void Validation_Of_Field_When_Invalid_Should_Fail()
        {
            var model = new MockModelWithValidation() { Title = string.Empty };
            var target = new BindableValidator(model);

            bool isValid = target.ValidateProperty("Title");

            Assert.False(isValid);
            Assert.False(target.GetAllErrors().Values.Count == 0);
        }
コード例 #3
0
        public void Validation_Of_Fields_When_Invalid_Should_Fail()
        {
            // Test model with invalid title
            var modelWithInvalidTitle = new MockModelWithValidation()
            {
                Title = string.Empty,
                Description = "A valid description"
            };
            var targetWithInvalidTitle = new BindableValidator(modelWithInvalidTitle);
            bool resultWithInvalidTitle = targetWithInvalidTitle.ValidateProperties();

            Assert.False(resultWithInvalidTitle);
            Assert.False(targetWithInvalidTitle.GetAllErrors().Values.Count == 0);

            // Test model with invalid description
            var modelWithInvalidDescription = new MockModelWithValidation()
            {
                Title = "A valid Title",
                Description = string.Empty
            };
            var targetWithInvalidDescription = new BindableValidator(modelWithInvalidDescription);
            bool resultWithInvalidDescription = targetWithInvalidDescription.ValidateProperties();

            Assert.False(resultWithInvalidDescription);
            Assert.False(targetWithInvalidDescription.GetAllErrors().Values.Count == 0);

            // Test model with invalid title + description
            var modelInvalid = new MockModelWithValidation()
            {
                Title = "1234567894",
                Description = string.Empty
            };
            var targetInvalid = new BindableValidator(modelInvalid);
            bool resultInvalid = targetInvalid.ValidateProperties();

            Assert.False(resultInvalid);
            Assert.False(targetInvalid.GetAllErrors().Values.Count == 0);
        }
コード例 #4
0
        public void Validation_Of_A_Nonexistent_Property_Should_Throw()
        {
            var model = new MockModelWithValidation();
            var target = new BindableValidator(model);

            var exception = Assert.Throws<ArgumentException>(() =>
                                        {
                                            target.ValidateProperty("DoesNotExist");
                                        });
            const string expectedMessage = "The entity does not contain a property with that name\r\nParameter name: DoesNotExist";

            Assert.Equal(expectedMessage, exception.Message);
        }
コード例 #5
0
        public void Validation_Of_A_Nonexistent_Property_Should_Throw()
        {
            var model = new MockModelWithValidation();
            var target = new BindableValidator(model, (mapId, key) => "ErrorMessage");
   
           var exception = Assert.ThrowsException<ArgumentException>(() =>
                                       {
                                           target.ValidateProperty("DoesNotExist");
                                       });
            const string expectedMessage = "ErrorMessage\r\nParameter name: DoesNotExist";

            Assert.AreEqual(expectedMessage, exception.Message);
        }