public void SetValue_WithOneRule_AndInvalidValue_RaiseChanges()
        {
            // Arrange
            var    startValue = "Not empty";
            string value      = null;
            var    sut        = new ValidatableValue <string>
            {
                ValidationRules = new IValidationRule <string>[]
                {
                    new NullValidationRule <string>(_ERROR_MESSAGE)
                },
                Value = startValue
            };

            // Act
            using (FluentAssertions.Events.IMonitor <ValidatableValue <string> > monitor = sut.Monitor())
            {
                sut.Value = value;

                // Assert
                monitor.Should().RaisePropertyChangeFor(t => t.Value);
                monitor.Should().RaisePropertyChangeFor(t => t.Errors);
                monitor.Should().RaisePropertyChangeFor(t => t.FirstError);
                monitor.Should().RaisePropertyChangeFor(t => t.IsValid);
                monitor.Should().RaisePropertyChangeFor(t => t.IsNotValid);
            }
        }
        public void SetValue_WithTwoRule_AndInvalidValue_NotRaiseIfIsValidNotChanged()
        {
            // Arrange
            var startValue = "1234";   // valid
            var value      = "1";      // invalid rule 1
            var value2     = "123456"; // invalid rule 2
            var sut        = new ValidatableValue <string>
            {
                ValidationRules = new IValidationRule <string>[]
                {
                    new StringLengthValidationRule("Length Error", 2, false, true),
                    new StringLengthValidationRule(_ERROR_MESSAGE, 5)
                },
                Value = startValue
            };

            // Act
            sut.Value = value;
            using (FluentAssertions.Events.IMonitor <ValidatableValue <string> > monitor = sut.Monitor())
            {
                sut.Value = value2;

                // Assert
                monitor.Should().RaisePropertyChangeFor(t => t.Value);
                monitor.Should().RaisePropertyChangeFor(t => t.Errors);
                monitor.Should().RaisePropertyChangeFor(t => t.FirstError);
                monitor.Should().NotRaisePropertyChangeFor(t => t.IsValid);
                monitor.Should().NotRaisePropertyChangeFor(t => t.IsNotValid);
            }
        }
        public void IsValidChangedEventRaised_OnIsValidChange()
        {
            // Arrange
            var startValue = "123456";
            var sut        = new ValidatableValue <string>
            {
                Value           = startValue,
                ValidationRules = new IValidationRule <string>[]
                {
                    new StringLengthValidationRule("Length Error", 2, false, true),
                    new StringLengthValidationRule(_ERROR_MESSAGE, 5)
                }
            };

            // Act
            sut.IsValid.Should().BeTrue();
            sut.IsNotValid.Should().BeFalse();
            using (FluentAssertions.Events.IMonitor <ValidatableValue <string> > monitor = sut.Monitor())
            {
                sut.RaiseValidation();

                // Assert
                monitor.Should().Raise(nameof(ValidatableValue <string> .IsValidChanged))
                .WithSender(sut)
                .WithArgs <IsValidEventArgs>(t => t.IsValid == false);
            }
        }
        public void SetValue_WithDifferentValue_TriggerPropertyChanged()
        {
            // Arrange
            var value1 = Guid.NewGuid().ToString();
            var value2 = Guid.NewGuid().ToString();
            var sut    = new ValidatableValue <string> {
                Value = value1
            };

            // Act
            using (FluentAssertions.Events.IMonitor <ValidatableValue <string> > monitor = sut.Monitor())
            {
                sut.Value = value2;

                // Assert
                monitor.Should().RaisePropertyChangeFor(t => t.Value);
            }
        }