private CourseService GetCourseService(Course course, IValidator validator = null)
 {
     if (validator == null)
     {
         validator = new FakeValidator();
     }
     return(new CourseService(course, validator));
 }
        public void Given_AbstractValidatorWithoutRules_When_CheckingIfRuleCountIs0_Then_ValidationPass()
        {
            // Arrange
            var validation = new FakeValidator <int>();

            //Act & Assert
            AssertExtension.NotThrows(() => validation.ShouldHaveRulesCount(0));
        }
        public void Given_AbstractValidatorWith1Rule_When_CheckingIfRuleCountIs2_Then_ValidationFail()
        {
            // Arrange
            var validation = new FakeValidator <int>();

            validation.Include(new FakeValidator <int>());

            //Act & Assert
            AssertExtension.Throws <XunitException>(() => validation.ShouldHaveRulesCount(2),
                                                    "(number of rules for object)");
        }
        public void GetArgumentValidator_should_get_validator_when_parameter_is_of_type_object()
        {
            // Arrange
            var validator = new FakeValidator <object>();
            var argument  = ExpressionHelper.GetArgumentExpression <ITestInterface>(x => x.Bar(GetValidator(validator)), 0);

            // Act
            var factory           = this.CreateFactory();
            var producedValidator = factory.GetArgumentValidator(argument);

            // Assert
            Assert.That(producedValidator, Is.SameAs(validator));
        }
        public void GetArgumentValidator_should_get_validator_when_Argument_property_has_been_called_on_it()
        {
            // Arrange
            var validator = new FakeValidator <int>();
            var argument  = ExpressionHelper.GetArgumentExpression <ITestInterface>(x => x.Foo(validator.Argument), 0);

            // Act
            var factory           = this.CreateFactory();
            var producedValidator = factory.GetArgumentValidator(argument);

            // Assert
            Assert.That(producedValidator, Is.SameAs(validator));
        }
        public void GetArgumentValidator_should_get_validator_passed_in_directly()
        {
            // Arrange
            var validator = new FakeValidator <int>();
            var argument  = ExpressionHelper.GetArgumentExpression <ITestInterface>(x => x.Foo(validator), 0);

            // Act
            var factory           = this.CreateFactory();
            var producedValidator = factory.GetArgumentValidator(argument);

            // Assert
            Assert.That(producedValidator, Is.SameAs(validator));
        }
        public void Validate_WhenStudentIsApproved_ReturnsTrue()
        {
            //Arrange
            var course        = new Course();
            var stubValidator = new FakeValidator {
                IsApproved = true
            };
            var service = GetCourseService(course, stubValidator);
            var student = new Student();

            //Act
            bool result = service.Validate(student);

            //Assert
            Assert.IsTrue(result);
        }
Exemplo n.º 8
0
        public void TextValidatable_OnValueChanged_Validate()
        {
            var validator = new FakeValidator <string> {
                Message = ErrorMessage,
                IsValid = false,
            };
            var validatable = MakeValidatable(validator, true);

            // Asserts the initial state
            Assert.IsTrue(validatable.IsValid);

            // Change the value and check if state has changed
            validatable.Value = "test content";
            Assert.IsFalse(validatable.IsValid);
            Assert.AreEqual(ErrorMessage, validatable.ErrorMessage);
        }