Example #1
0
 private void AssertSuccess(ref bool result, ValidatedProperty <string> property)
 {
     using (new AssertionScope())
     {
         result.Should().BeTrue();
         property.Error.Should().BeNull();
     }
 }
Example #2
0
 private void AssertFailed(ref bool result, ValidatedProperty <string> property, string error)
 {
     using (new AssertionScope())
     {
         result.Should().BeFalse();
         property.Error.Should().Be(error);
     }
 }
Example #3
0
        public void Validate_IsDoubleNoValue_ValidationFailed()
        {
            // Arrange
            var property = new ValidatedProperty <string>().IsDouble();

            // Act
            var result = property.Validate();

            // Assert
            AssertFailed(ref result, property, Strings.ValueHasIncorrectFormat);
        }
Example #4
0
        public void Validate_IsRequiredNoValue_ValidationFailed(string value)
        {
            // Arrange
            var property = new ValidatedProperty <string>(value).IsRequired();

            // Act
            var result = property.Validate();

            // Assert
            AssertFailed(ref result, property, Strings.ValueIsMandatory);
        }
Example #5
0
        public void Validate_EmptyRules_ValidationSuccess(string value)
        {
            // Arrange
            var property = new ValidatedProperty <string>(value);

            // Act
            var result = property.Validate();

            // Assert
            AssertSuccess(ref result, property);
        }
Example #6
0
        public void Validate_TwoRules_ValidationFailed(string value, string expectedError)
        {
            // Arrange
            var property = new ValidatedProperty <string>(value)
                           .IsRequired()
                           .IsDouble();

            // Act
            var result = property.Validate();

            // Assert
            AssertFailed(ref result, property, expectedError);
        }
        public PackageDimmsViewModel(IPackageService packageService, IPopupService popupService)
        {
            _packageService = packageService;
            _popupService   = popupService;

            SaveCommand  = new MvxCommand(SaveAction);
            ResetCommand = new MvxCommand(ResetAction);

            Barcode = new ValidatedProperty <string>().IsRequired();
            Width   = new ValidatedProperty <string>().IsRequired().IsDouble();
            Height  = new ValidatedProperty <string>().IsRequired().IsDouble();
            Depth   = new ValidatedProperty <string>().IsRequired().IsDouble();

            _validationGroup = new ValidationGroup(Barcode, Width, Height, Depth);
        }
        public void Validate_AllPropertiesValid_ValidationSuccess()
        {
            // Arrange
            var propertyOne = new ValidatedProperty <string>("5")
                              .IsRequired()
                              .IsDouble();

            var propertyTwo = new ValidatedProperty <string>("12")
                              .IsRequired()
                              .IsDouble();

            var group = new ValidationGroup(propertyOne, propertyTwo);

            // Act
            var result = group.Validate();

            // Assert
            result.Should().BeTrue();
        }
        public void Validate_AllPropertyInvalid_ValidationFailed()
        {
            // Arrange
            var propertyOne = new ValidatedProperty <string>().IsRequired();

            var propertyTwo = new ValidatedProperty <string>("qwerty")
                              .IsRequired()
                              .IsDouble();

            var group = new ValidationGroup(propertyOne, propertyTwo);

            // Act
            var result = group.Validate();

            // Assert
            using (new AssertionScope())
            {
                result.Should().BeFalse();
                propertyOne.Error.Should().Be(Strings.ValueIsMandatory);
                propertyTwo.Error.Should().Be(Strings.ValueHasIncorrectFormat);
            }
        }
 public ValidatedPropertyAssertionExtensions(ValidatedProperty <T> instance)
 {
     Subject = instance;
 }
 public static ValidatedPropertyAssertionExtensions <string> ShouldBe(this ValidatedProperty <string> property)
 {
     return(new ValidatedPropertyAssertionExtensions <string>(property));
 }