Example #1
0
        public void When_BirthDate_is_sixteen_years_before_now_the_object_is_valid()
        {
            var sut = new Citizen();
            sut.Age = 16;
            sut.BirtDate = DateTime.Today.AddYears(-16);
            sut.Name = "AValidName";
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.True(results.IsValid);
        }
Example #2
0
        public void When_Age_is_over_sixteen_the_object_is_valid()
        {
            var sut = new Citizen();
            sut.Age = new Random().Next(16, int.MaxValue);
            sut.BirtDate = DateTime.Parse("1965/10/12");
            sut.Name = "AValidName";
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.True(results.IsValid);
        }
Example #3
0
        public void When_BirthDate_is_not_more_than_fiveteen_years_before_now_the_object_is_invalid()
        {
            var sut = new Citizen();
            sut.Age = 16;
            sut.BirtDate = DateTime.Today.AddYears(-new Random().Next(0, 15));
            sut.Name = "AValidName";
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.False(results.IsValid);
            Assert.Equal(results.Errors.Count, 1);
            Assert.Contains("minimum of sixteen years old", results.Errors.First().ErrorMessage);
            Assert.Contains("BirtDate", results.Errors.First().PropertyName);
        }
Example #4
0
        public void When_Age_is_under_sixteen_the_object_is_invalid()
        {
            var sut = new Citizen();
            sut.Age = new Random().Next(15);
            sut.BirtDate = DateTime.Parse("1965/10/12");
            sut.Name = "AValidName";
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.False(results.IsValid);
            Assert.Equal(results.Errors.Count, 1);
            Assert.Contains("Age must be sixteen or greater", results.Errors.First().ErrorMessage);
            Assert.Contains("Age", results.Errors.First().PropertyName);
        }
Example #5
0
        public void If_the_name_is_null_the_object_is_invalid()
        {
            var sut = new Citizen();
            sut.Age = 20;
            sut.BirtDate = DateTime.Parse("1965/10/12");
            sut.Name = null;
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.False(results.IsValid);
            Assert.Equal(results.Errors.Count, 1);
            Assert.Contains("Name Cant be null or empty", results.Errors.First().ErrorMessage);
            Assert.Contains("Name", results.Errors.First().PropertyName);
        }
Example #6
0
        public void If_the_name_is_not_null_whiteSpace_or_empty_and_has_a_length_between_three_and_fifty_characters_the_object_is_valid()
        {
            var sut = new Citizen();
            sut.Age = 20;
            sut.BirtDate = DateTime.Parse("1965/10/12");
            sut.Name = "b difbjf";
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.True(results.IsValid);
            
        }
Example #7
0
        public void If_the_name_is_more_than_fifty_characters_length_the_object_is_invalid()
        {
            var sut = new Citizen();
            sut.Age = 20;
            sut.BirtDate = DateTime.Parse("1965/10/12");
            sut.Name = "WeweweweweWeweweweweWeweweweweWeweweweweWewewewewes";
            var validator = new CitizenValidator();
            var results = validator.Validate(sut);

            Assert.False(results.IsValid);
            Assert.Equal(results.Errors.Count, 1);
            Assert.Contains("Name has to have between three and fifty", results.Errors.Last().ErrorMessage);
            Assert.Contains("Name", results.Errors.Last().PropertyName);
        }