Exemplo n.º 1
0
        public void Validate_Exclusive()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), true);

            v.Validate(new TimeSpan(1000));
            v.Validate(new TimeSpan(15000));
        }
        static void Main(string[] args)
        {
            // Display title.
            Console.WriteLine("ASP.NET Validators");
            Console.WriteLine();

            // Create TimeSpan and Validator.
            TimeSpan          testTimeSpan        = new TimeSpan(0, 1, 05);
            TimeSpan          minTimeSpan         = new TimeSpan(0, 1, 0);
            TimeSpan          maxTimeSpan         = new TimeSpan(0, 1, 10);
            TimeSpanValidator myTimeSpanValidator = new TimeSpanValidator(minTimeSpan, maxTimeSpan, false, 65);

            // Determine if the object to validate can be validated.
            Console.WriteLine("CanValidate: {0}",
                              myTimeSpanValidator.CanValidate(testTimeSpan.GetType()));

            try
            {
                // Attempt validation.
                myTimeSpanValidator.Validate(testTimeSpan);
                Console.WriteLine("Validated.");
            }
            catch (ArgumentException e)
            {
                // Validation failed.
                Console.WriteLine("Error: {0}", e.Message.ToString());
            }

            // Display and wait
            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void Validate_Inclusive()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), false);

            v.Validate(new TimeSpan(5000));
            v.Validate(new TimeSpan(10000));
        }
Exemplo n.º 4
0
        public void CanValidate()
        {
            TimeSpan          t = new TimeSpan(1000);
            TimeSpanValidator v = new TimeSpanValidator(t, t);

            Assert.True(v.CanValidate(typeof(TimeSpan)), "A1");
            Assert.False(v.CanValidate(typeof(int)), "A2");
            Assert.False(v.CanValidate(typeof(long)), "A3");
        }
Exemplo n.º 5
0
        public void Validate_Resolution()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(20000),
                                                        new TimeSpan(50000),
                                                        false,
                                                        2);

            AssertExtensions.Throws <ArgumentException>(null, () => v.Validate(TimeSpan.FromTicks(40000)));
        }
Exemplo n.º 6
0
        public void Validate_Resolution()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(20000),
                                                        new TimeSpan(50000),
                                                        false,
                                                        2);

            v.Validate(TimeSpan.FromTicks(40000));
        }
		private void setup()
		{
			Thread.CurrentThread.CurrentCulture =
				Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

			validator = new TimeSpanValidator();
			
			validator.Initialize(new CachedValidationRegistry(), typeof (TestTarget).GetProperty("TargetField"));
			target = new TestTarget();
		}
Exemplo n.º 8
0
        private void setup()
        {
            Thread.CurrentThread.CurrentCulture       =
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

            validator = new TimeSpanValidator();

            validator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("TargetField"));
            target = new TestTarget();
        }
Exemplo n.º 9
0
        // CustomSection constructor.
        static CustomSection()
        {
            // <Snippet2>
            // Initialize the _FileName property
            _FileName =
                new ConfigurationProperty("fileName",
                                          typeof(string), "default.txt");
            // </Snippet2>

            // <Snippet3>
            // Initialize the _MaxUsers property
            _MaxUsers =
                new ConfigurationProperty("maxUsers",
                                          typeof(long), (long)1000,
                                          ConfigurationPropertyOptions.None);
            // </Snippet3>

            // <Snippet4>
            // Initialize the _MaxIdleTime property
            TimeSpan minTime = TimeSpan.FromSeconds(30);
            TimeSpan maxTime = TimeSpan.FromMinutes(5);

            ConfigurationValidatorBase _TimeSpanValidator =
                new TimeSpanValidator(minTime, maxTime, false);

            _MaxIdleTime =
                new ConfigurationProperty("maxIdleTime",
                                          typeof(TimeSpan), TimeSpan.FromMinutes(5),
                                          TypeDescriptor.GetConverter(typeof(TimeSpan)),
                                          _TimeSpanValidator,
                                          ConfigurationPropertyOptions.IsRequired,
                                          "[Description:This is the max idle time.]");
            // </Snippet4>

            // Initialize the _Alias property
            _Alias =
                new ConfigurationProperty("alias",
                                          typeof(string), "alias.txt");

            // Initialize the Property collection.
            _Properties = new ConfigurationPropertyCollection();
            _Properties.Add(_FileName);
            _Properties.Add(_Alias);
            _Properties.Add(_MaxUsers);
            _Properties.Add(_MaxIdleTime);
        }
Exemplo n.º 10
0
        public void Validate_Exclusive_fail3()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), true);

            AssertExtensions.Throws <ArgumentException>(null, () => v.Validate(new TimeSpan(7000)));
        }
Exemplo n.º 11
0
        public void Validate_inRange()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000));

            v.Validate(new TimeSpan(7000));
        }
Exemplo n.º 12
0
        // </Snippet30>

        // Get the property characteristics.
        // Shows how to use the property.
        static void GetPropertyCharacteristics()
        {
            // Initialize the MaxIdleTime property.
            ConfigurationProperty _MaxIdleTime;
            TimeSpan minTime = TimeSpan.FromSeconds(30);
            TimeSpan maxTime = TimeSpan.FromMinutes(5);
            ConfigurationValidatorBase _TimeSpanValidator =
                new TimeSpanValidator(minTime, maxTime, false);

            _MaxIdleTime =
                new ConfigurationProperty("maxIdleTime",
                                          typeof(TimeSpan), TimeSpan.FromMinutes(5),
                                          TypeDescriptor.GetConverter(typeof(TimeSpan)),
                                          _TimeSpanValidator,
                                          ConfigurationPropertyOptions.IsRequired,
                                          "[Description:This is the max idle time.]");

            Console.WriteLine("[Display MaxIdleTime properties]");

            // <Snippet5>
            string converter = _MaxIdleTime.Converter.ToString();

            Console.WriteLine("MaxIdleTime coverter: {0}", converter);
            // </Snippet5>

            // <Snippet6>
            string defaultValue = _MaxIdleTime.DefaultValue.ToString();

            Console.WriteLine("MaxIdleTime default value: {0}",
                              defaultValue);
            // </Snippet6>

            // <Snippet7>
            string isKey = _MaxIdleTime.IsKey.ToString();

            Console.WriteLine("MaxIdleTime is key: {0}", isKey);
            // </Snippet7>

            // <Snippet8>
            string isRequired = _MaxIdleTime.IsRequired.ToString();

            Console.WriteLine("MaxIdleTime is required: {0}", isRequired);
            // </Snippet8>

            // <Snippet9>
            string name = _MaxIdleTime.Name;

            Console.WriteLine("MaxIdleTime name: {0}", name);
            // </Snippet9>

            // <Snippet10>
            string type = _MaxIdleTime.Type.ToString();

            Console.WriteLine("MaxIdleTime type: {0}", type);
            // </Snippet10>

            // <Snippet11>
            string description = _MaxIdleTime.Description;

            Console.WriteLine("MaxIdleTime description: {0}", description);
            // </Snippet11>

            // <Snippet12>
            string validator = _MaxIdleTime.Validator.ToString();

            Console.WriteLine("MaxIdleTime validator: {0}", validator);
            // </Snippet12>
        }
Exemplo n.º 13
0
        public void Validate_Exclusive_fail2()
        {
            TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), true);

            Assert.Throws <ArgumentException>(() => v.Validate(new TimeSpan(10000)));
        }