Exemple #1
0
        public void TestWhenFormatIsRight()
        {
            //The date to parse
            string dateTime = "25/07/2017 12:47:00";

            Assert.IsTrue(ParseStringToType.StringToDateTime(dateTime).ToString() == dateTime);
        }
Exemple #2
0
        public void TestWithDatetimeNow()
        {
            //Find now
            string dateTimeNow = DateTime.Now.ToString();

            Assert.IsTrue(ParseStringToType.StringToDateTime(dateTimeNow).ToString() == dateTimeNow);
        }
Exemple #3
0
        public void TestWhenComponentIsNegative()
        {
            //Be sure the right exception is cast
            bool   exceptionIsCast = false;
            string dateTime        = "-5/07/2017 12:47:00";

            try
            {
                Console.WriteLine(ParseStringToType.StringToDateTime(dateTime));
                Console.ReadKey();
            }
            catch (FormatException)
            {
                exceptionIsCast = true;
            }
            catch (Exception)
            {
            }
            Assert.AreEqual(exceptionIsCast, true);
        }
Exemple #4
0
        public void TestWhenYearformatIsWrong()
        {
            //Becomes true if the right exception is cast
            bool   formatExceptionIsCast = false;
            string wrongYearFormat       = "25/07/17 12:30:05";

            try
            {
                Console.WriteLine(ParseStringToType.StringToDateTime(wrongYearFormat));
                Console.ReadKey();
            }
            catch (FormatException)
            {
                formatExceptionIsCast = true;
            }
            catch (Exception)
            {
            }
            Assert.AreEqual(formatExceptionIsCast, true);
        }
Exemple #5
0
        public void TestWhenWrongSeparators()
        {
            //Be sure the right exception is cast
            bool   exceptionIsCast = false;
            string dateTime        = "22:22/2222 22:22:22";

            try
            {
                Console.WriteLine(ParseStringToType.StringToDateTime(dateTime));
                Console.ReadKey();
            }
            catch (FormatException)
            {
                exceptionIsCast = true;
            }
            catch (Exception)
            {
            }
            Assert.AreEqual(exceptionIsCast, true);
        }