public void For_SetValidatorAsync_When_OtherValidatorIsAlreadySet_Then_ExceptionIsThrown() { // Arrange: var memberInfo = PropertyValidatorTestsCommon.CreateTestMemberInfo(); var validator = new AsyncPropertyValidator <string>(memberInfo); validator.SetValidator(Mock.Of <IAsyncValidator <string> >()); // First .SetValidator() call // Act & Assert: var exception = Assert.Throws <InvalidOperationException>(() => validator.SetValidator(Mock.Of <IAsyncValidator <string> >())); exception.Message.Should().Be("There is already set other validator"); }
public void For_SetValidatorAsync_When_ProvidedValidatorIsNull_Then_ExceptionIsThrown() { // Arrange: var memberInfo = PropertyValidatorTestsCommon.CreateTestMemberInfo(); var validator = new AsyncPropertyValidator <string>(memberInfo); // Act & Assert: Assert.Throws <ArgumentNullException>(() => validator.SetValidator(null)); }
public void For_SetValidatorAsync_When_PassedValidatorReferenceConcernsTargetValidator_Then_ExceptionIsThrown() { // Arrange: var memberInfo = PropertyValidatorTestsCommon.CreateTestMemberInfo(); var validator = new AsyncPropertyValidator <string>(memberInfo); // Act & Assert: var exception = Assert.Throws <ArgumentException>(() => validator.SetValidator(validator)); exception.Message.Should().Be("Detected circular reference"); }
public void For_SetValidatorAsync_When_ThereIsNoValidationTaskCorrespondingToOtherValidator_Then_NewValidationTaskForValidatorIsAdded() { // Arrange: var memberInfo = PropertyValidatorTestsCommon.CreateTestMemberInfo(); var validator = new AsyncPropertyValidator <string>(memberInfo); // Act: validator.SetValidator(Mock.Of <IAsyncValidator <string> >()); // Assert: validator.ValidationTasksAsReadonly.Count.Should().Be(1); var validationTask = validator.ValidationTasksAsReadonly.First(); validationTask.IsOtherValidator.Should().Be(true); validationTask.Validator.Should().BeAssignableTo <IAsyncValidator <string> >(); }