public void InterpretAsInt_DecimalInput_CannotExtractInt()
        {
            int  outValue;
            bool successfullyInturpreted = EntryFieldInterpretingUtils.InterpretAsInt("1.5", out outValue);

            Assert.IsFalse(successfullyInturpreted);
        }
        public void InterpretAsInt_NonIntegerString_CannotExtractInt()
        {
            int  outValue;
            bool successfullyInturpreted = EntryFieldInterpretingUtils.InterpretAsInt("1b", out outValue);

            Assert.IsFalse(successfullyInturpreted);
        }
        public void InterpretAsInt_ValidIntegerWithWhitespace_SuccessfullyExtractsInt()
        {
            int  outValue;
            bool successfullyInturpreted = EntryFieldInterpretingUtils.InterpretAsInt("  12  ", out outValue);

            Assert.IsTrue(successfullyInturpreted);
            Assert.AreEqual(12, outValue);
        }
        public void InterpretAsInt_ValidInteger_SuccessfullyExtractsInt()
        {
            int  outValue;
            bool successfullyInturpreted = EntryFieldInterpretingUtils.InterpretAsInt("25", out outValue);

            Assert.IsTrue(successfullyInturpreted);
            Assert.AreEqual(25, outValue);
        }
コード例 #5
0
        public virtual bool GetRangeFromUserInput(string userInput, int minValue, int maxValue,
                                                  out int rangeBottom, out int rangeTop, out string errorMsg)
        {
            int singleRangeValue;
            int tempRangeTop;
            int tempRangeBottom;

            errorMsg = "";
            bool validFormat;
            bool validRange;

            if (EntryFieldInterpretingUtils.InterpretAsInt(userInput, out singleRangeValue))
            {
                rangeTop    = singleRangeValue;
                rangeBottom = singleRangeValue;
                validFormat = true;
            }
            else if (EntryFieldInterpretingUtils.InterpretAsRangeAllStr(userInput))
            {
                rangeTop    = maxValue;
                rangeBottom = minValue;
                validFormat = true;
            }
            else if (EntryFieldInterpretingUtils.InterpretAsRangeOfInts(userInput, out tempRangeTop, out tempRangeBottom))
            {
                rangeTop    = tempRangeTop;
                rangeBottom = tempRangeBottom;
                validFormat = true;
            }
            else
            {
                errorMsg    = "Invalid range format";
                rangeTop    = MssMsgUtil.UNUSED_MSS_MSG_DATA;
                rangeBottom = MssMsgUtil.UNUSED_MSS_MSG_DATA;
                validFormat = false;
            }

            if (validFormat == true)
            {
                if (rangeBottom >= minValue && rangeTop <= maxValue)
                {
                    validRange = true;
                }
                else
                {
                    errorMsg   = "Out of range";
                    validRange = false;
                }
            }
            else
            {
                validRange = false;
            }

            return(validRange);
        }