コード例 #1
0
 private void AssertSuccess(ref bool result, ValidatedProperty <string> property)
 {
     using (new AssertionScope())
     {
         result.Should().BeTrue();
         property.Error.Should().BeNull();
     }
 }
コード例 #2
0
 private void AssertFailed(ref bool result, ValidatedProperty <string> property, string error)
 {
     using (new AssertionScope())
     {
         result.Should().BeFalse();
         property.Error.Should().Be(error);
     }
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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;
 }
コード例 #11
0
 public static ValidatedPropertyAssertionExtensions <string> ShouldBe(this ValidatedProperty <string> property)
 {
     return(new ValidatedPropertyAssertionExtensions <string>(property));
 }