public void MinValue_Get()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

            attribute.MinValueString = "05:55:55";
            TimeSpan test = attribute.MinValue;

            Assert.Equal(test, TimeSpan.Parse("05:55:55"));

            attribute.MinValueString = "23:59:59";
            test = attribute.MinValue;
            Assert.Equal(test, TimeSpan.Parse("23:59:59"));

            attribute.MinValueString = "00:00:00";
            test = attribute.MinValue;
            Assert.Equal(test, TimeSpan.Parse("00:00:00"));

            attribute.MinValueString = "1:01:00:00";
            test = attribute.MinValue;
            Assert.Equal(test, TimeSpan.Parse("1:01:00:00"));

            attribute.MinValueString = "2.22:50:45.2563";
            test = attribute.MinValue;
            Assert.Equal(test, TimeSpan.Parse("2.22:50:45.2563"));
        }
        public void MinValueString_GetString()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();
            string test = attribute.MinValueString;

            Assert.Equal(test, TimeSpan.MinValue.ToString());
        }
        public void ExcludedRange_ChangeToTrue()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

            attribute.ExcludeRange = true;
            Assert.True(attribute.ExcludeRange);
        }
        public void MaxValueString_GetAndSetCorrectly()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

            attribute.MaxValueString = "05:55:55";
            string test = attribute.MaxValueString;

            Assert.Equal(test, "05:55:55");

            attribute.MaxValueString = "23:59:59";
            test = attribute.MaxValueString;
            Assert.Equal(test, "23:59:59");

            attribute.MaxValueString = "00:00:00";
            test = attribute.MaxValueString;
            Assert.Equal(test, "00:00:00");

            attribute.MaxValueString = "1:01:00:00";
            test = attribute.MaxValueString;
            Assert.Equal(test, "1.01:00:00");

            attribute.MaxValueString = "2:22:50:45.2563";
            test = attribute.MaxValueString;
            Assert.Equal(test, "2.22:50:45.2563000");
        }
示例#5
0
        public void MinValueString_SetValidTimeSpan()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

            attribute.MinValueString = "05:55:55";
            string test = attribute.MinValueString;

            Assert.Equal("05:55:55", test);

            attribute.MinValueString = "23:59:59";
            test = attribute.MinValueString;
            Assert.Equal("23:59:59", test);

            attribute.MinValueString = "00:00:00";
            test = attribute.MinValueString;
            Assert.Equal("00:00:00", test);

            attribute.MinValueString = "1:01:00:00";
            test = attribute.MinValueString;
            Assert.Equal("1.01:00:00", test);

            attribute.MinValueString = "2:22:50:45.2563";
            test = attribute.MinValueString;
            Assert.Equal("2.22:50:45.2563000", test);
        }
        public static void TimeStampValidatorInstance()
        {
            //<Snippet12>

            ConfigurationValidatorBase valBase;
            TimeSpanValidatorAttribute tsValAttr;

            tsValAttr = new TimeSpanValidatorAttribute();

            TimeSpan goodValue = TimeSpan.FromMinutes(10);
            Int16    badValue  = 10;

            try
            {
                valBase = tsValAttr.ValidatorInstance;
                valBase.Validate(goodValue);
                // valBase.Validate(badValue);
            }
            catch (ArgumentException e)
            {
                // Display error message.
                string msg = e.ToString();
#if DEBUG
                Console.WriteLine(msg);
#endif
            }
            //</Snippet12>
        }
        public void IsValid_WhenObjectNotTimeSpan_ReturnsFalse()
        {
            var sut    = new TimeSpanValidatorAttribute();
            var actual = sut.IsValid(new object());

            Assert.False(actual);
        }
        public void IsValid_WhenObjectIsNull_ReturnsTrue()
        {
            var sut    = new TimeSpanValidatorAttribute();
            var actual = sut.IsValid(null);

            Assert.True(actual);
        }
示例#9
0
 public ServiceModelTimeSpanValidatorAttribute()
 {
     this.innerValidatorAttribute = new TimeSpanValidatorAttribute()
     {
         MaxValueString = TimeoutHelper.MaxWait.ToString()
     };
 }
示例#10
0
        public void MaxValueString_TooBig()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

            attribute.MinValueString = new TimeSpan(2, 2, 2, 2).ToString();
            ArgumentOutOfRangeException result            = Assert.Throws <ArgumentOutOfRangeException>(() => attribute.MaxValueString = new TimeSpan(1, 1, 1, 1).ToString());
            ArgumentOutOfRangeException expectedException = new ArgumentOutOfRangeException("value", SR.Validator_min_greater_than_max);

            Assert.Equal(expectedException.Message, result.Message);
        }
        public void IsValid_WhenOnlyMaxValueSet_ThenAllowsAnyValueBelowIt()
        {
            var sut = new TimeSpanValidatorAttribute
            {
                MinValue = "00:00:01",
            };

            Assert.True(sut.IsValid(TimeSpan.FromSeconds(2)));
            Assert.True(sut.IsValid(TimeSpan.MaxValue));
            Assert.False(sut.IsValid(TimeSpan.FromSeconds(0)));
        }
        public void IsValid_WhenTimeSpanOutsideRange_ReturnsFalse()
        {
            var sut = new TimeSpanValidatorAttribute
            {
                MinValue = TimeSpan.FromSeconds(1).ToString(),
                MaxValue = TimeSpan.FromSeconds(5).ToString(),
            };

            var actual = sut.IsValid(TimeSpan.FromSeconds(6));

            Assert.False(actual);
        }
        public void MinValueString_TooSmall()
        {
            using (new ThreadCultureChange(CultureInfo.InvariantCulture))
            {
                TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

                attribute.MaxValueString = new TimeSpan(2, 2, 2, 2).ToString();
                ArgumentOutOfRangeException result = Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                                                 attribute.MinValueString = new TimeSpan(3, 3, 3, 3).ToString());
                ArgumentOutOfRangeException expectedException =
                    new ArgumentOutOfRangeException("value", SR.Validator_min_greater_than_max);
                Assert.Equal(expectedException.Message, result.Message);
            }
        }
        public void MaxValueString_TooBig()
        {
            RemoteExecutor.Invoke(() =>
            {
                CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;

                TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

                attribute.MinValueString           = new TimeSpan(2, 2, 2, 2).ToString();
                ArgumentOutOfRangeException result = Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                                                 attribute.MaxValueString = new TimeSpan(1, 1, 1, 1).ToString());
                ArgumentOutOfRangeException expectedException =
                    new ArgumentOutOfRangeException("value", SR.Validator_min_greater_than_max);
                Assert.Equal(expectedException.Message, result.Message);
            }).Dispose();
        }
        public void ExcludedRange_GetDefault()
        {
            TimeSpanValidatorAttribute attribute = new TimeSpanValidatorAttribute();

            Assert.False(attribute.ExcludeRange);
        }
 public IdentityModelTimeSpanValidatorAttribute()
 {
     this.innerValidatorAttribute = new TimeSpanValidatorAttribute();
     this.innerValidatorAttribute.MaxValueString = TimeoutHelper.MaxWait.ToString();
 }