示例#1
0
        public void ParseInvalidText()
        {
            NhsTimeSpan parsedTimeSpan;

            // Pass rubbish into TimeSpan
            Assert.IsFalse(NhsTimeSpan.TryParse("hsh sdoih", out parsedTimeSpan, CultureInfo.InvariantCulture));
        }
示例#2
0
        /// <summary>
        /// Check if the ControlToValidate is valid
        /// </summary>
        /// <returns>True if control properties is valid</returns>
        protected override bool EvaluateIsValid()
        {
            string value = this.GetControlValidationValue(this.ControlToValidate);

            NhsTimeSpan tryParseResult;

            return(NhsTimeSpan.TryParse(value, out tryParseResult, System.Threading.Thread.CurrentThread.CurrentCulture, ((TimeSpanInputBox)this.NamingContainer.FindControl(this.ControlToValidate)).IsAge));
        }
示例#3
0
        public void Parse_InvalidTextRepeatedValues()
        {
            DateTime baseDateTime = BaseDate;

            NhsTimeSpan timeSpan = new NhsTimeSpan();

            timeSpan.To = baseDateTime.AddDays(3).AddHours(17);

            NhsTimeSpan parsedTimeSpan;

            // Pass a TimeSpan in twice to simulate multiple entries for the same unit e.g "3d 3d"
            Assert.IsFalse(NhsTimeSpan.TryParse(string.Format(CultureInfo.InvariantCulture, "{0} {1}", timeSpan.ToString(), timeSpan.ToString()), out parsedTimeSpan, CultureInfo.InvariantCulture));
        }
示例#4
0
        /// <summary>
        /// Refresh the text displayed in the text box.
        /// </summary>
        /// <returns>
        /// Status of update.
        /// </returns>
        private bool ValidateAndUpdateValue()
        {
            bool status = true;

            this.SetValid();
            this.txtInput.Text = this.txtInput.Text.Trim();
            string preParsedValue;

            if (!string.IsNullOrEmpty(this.txtInput.Text))
            {
                NhsTimeSpan tmp;
                if (TryPreParseUnits(this.txtInput.Text.Trim(), out preParsedValue))
                {
                    try
                    {
                        if (NhsTimeSpan.TryParse(preParsedValue, out tmp, CultureInfo.CurrentCulture, this.IsAge))
                        {
                            this.Value.From = tmp.From;
                            this.Value.To   = tmp.To;
                            this.RefreshDisplayText();
                            this.NotifyPropertyChanged("Value");
                        }
                        else
                        {
                            this.SetInvalid(ref status);
                        }
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        this.SetInvalid(ref status);
                    }
                }
                else
                {
                    this.SetInvalid(ref status);
                }
            }
            else
            {
                this.Value = new NhsTimeSpan();
                this.RefreshDisplayText();
            }

            return(status);
        }