public void Be_Creatable()
        {
            var sut = new ValueCheckResult(true);

            sut.IsValid.Should().BeTrue();
            sut.Exception.Should().BeNull();
        }
        public void Be_Creatable_With_Exception_Only()
        {
            var exception = new InvalidCastException();
            var sut       = new ValueCheckResult(exception);

            sut.IsValid.Should().BeFalse();
            sut.Exception.Should().Be(exception);
        }
Beispiel #3
0
 public RequiredCheck(
     IDictionary <string, string> settings,
     Func <FormData> formData,
     INZazuTableDataSerializer tableSerializer,
     int rowIdx,
     FieldDefinition field)
 {
     _fieldMissing =
         new ValueCheckResult(new ArgumentException($"{field.Prompt ?? field.Key}: The field is required"));
 }
Beispiel #4
0
        // ReSharper disable UnusedParameter.Local
        public StringRegExCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx,
            FieldDefinition fieldDefinition)
        {
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value).ToObject <StringRegExCheckSettings>();

            if (string.IsNullOrWhiteSpace(Settings.Hint))
            {
                throw new ArgumentNullException(nameof(Settings.Hint));
            }
            if (string.IsNullOrWhiteSpace(Settings.RegEx))
            {
                throw new ArgumentNullException(nameof(Settings.RegEx));
            }

            _noMatch = new ValueCheckResult(false, new ArgumentException(Settings.Hint));
        }
        public void Aggregate_Single_Error_Results()
        {
            var exception    = new Exception();
            var checkResult1 = new ValueCheckResult(exception);
            var checkResult2 = new ValueCheckResult(true);
            var check1       = Substitute.For <IValueCheck>();
            var check2       = Substitute.For <IValueCheck>();

            check1.Validate(null, null, null).Returns(checkResult1);
            check2.Validate(null, null, null).Returns(checkResult2);

            var sut    = new AggregateCheck(new[] { check1, check2 });
            var result = sut.Validate(null, null, null);

            result.Should().NotBeNull();
            result.Should().Be(checkResult1, "we return the one and only error");
            result.IsValid.Should().BeFalse();
            result.Exception.Should().Be(exception);
        }
Beispiel #6
0
        // ReSharper disable UnusedParameter.Local
        public RangeCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx,
            FieldDefinition fieldDefinition)
        {
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value).ToObject <RangeCheckSettings>();

            if (Settings.MinInt < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Settings.Min),
                                                      $"The specified value must be between {Settings.MinInt} and {Settings.MaxInt}");
            }
            if (Settings.MaxInt < Settings.MinInt)
            {
                throw new ArgumentOutOfRangeException(
                          $"min={Settings.MinInt} must be less than or equal to max={Settings.MaxInt}.");
            }

            _outOfRange = new ValueCheckResult(false, new ArgumentOutOfRangeException(
                                                   $"The specified value must be between {Settings.MinInt} and {Settings.MaxInt}"));
        }
Beispiel #7
0
        // ReSharper disable UnusedParameter.Local
        public StringLengthCheck(
            IDictionary <string, string> settings, Func <FormData> formData,
            INZazuTableDataSerializer tableSerializer, int rowIdx, FieldDefinition field)
        {
            Settings = settings.ToDictionary(x => x.Key, x => (object)x.Value).ToObject <StringLengthCheckSettings>();

            if (Settings.MinInt < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Settings.Min),
                                                      $"Minimum string length '{Settings.MinInt}' must not be negative.");
            }
            if (Settings.MaxInt < Settings.MinInt)
            {
                throw new ArgumentOutOfRangeException(
                          $"min={Settings.MinInt} must be less than or equal to max={Settings.MaxInt}.");
            }

            _valueTooShort = new ValueCheckResult(false, new ArgumentException(
                                                      $"The specified string is too short (at least {Settings.MinInt} characters)"));
            _valueTooLong = new ValueCheckResult(false, new ArgumentException(
                                                     $"The specified string is too long (at most {Settings.MaxInt} characters)"));
        }