예제 #1
0
        static void Main(string[] args)
        {
            RawDate rawDate = new RawDate();

            while (true)
            {
                Console.WriteLine("--> Please enter a date with the format DD/MM/YYYY");

                string date = Console.ReadLine();

                bool isValidDate = rawDate.IsDateValid(date);

                if (isValidDate)
                {
                    Console.WriteLine("You entered the date: " + date);
                    Console.WriteLine();

                    Console.WriteLine("--> Please enter the amount of days to add");

                    string daysToAdd = Console.ReadLine();

                    int i;

                    if (int.TryParse(daysToAdd, out i))
                    {
                        if (i < 1)
                        {
                            Console.WriteLine("XXX INVALID NUMBER OF DAYS XXX");
                            continue;
                        }

                        rawDate = new RawDate()
                        {
                            rawDate = date
                        };

                        DateCalculator dateCalculator = new DateCalculator();
                        RawDate        result         = dateCalculator.AddDays(rawDate, int.Parse(daysToAdd));

                        Console.WriteLine("New Date: " + result.rawDate);
                    }
                    else
                    {
                        Console.WriteLine("XXX INVALID NUMBER OF DAYS XXX");
                    }
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("XXX INVALID DATE XXX");
                }

                Console.WriteLine("----------------------");
                Console.WriteLine();
            }
        }
예제 #2
0
        public void AddDays_RawDate_rawDate_IsStringEmpty()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = ""
            };
            RawDate returnedRawDate = dateCalculator.AddDays(rawDate, 0);

            Assert.IsEmpty(returnedRawDate.rawDate);
        }
예제 #3
0
        public void AddDays_RawDateNotNull()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = ""
            };
            RawDate returnedRawDate = dateCalculator.AddDays(rawDate, 0);

            Assert.IsNotNull(returnedRawDate);
        }
예제 #4
0
        public void AddDays_10101972_Minus1_RawDateNull()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "10/10/1972"
            };
            RawDate result = dateCalculator.AddDays(rawDate, -1);

            Assert.IsNull(result.rawDate);
        }
예제 #5
0
        public void AddDays_10101972_52_01121972()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "10/10/1972"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 52);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "01/12/1972"
            }.rawDate, result.rawDate);
        }
예제 #6
0
        public void AddDays_10101972_21_31101972()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "10/10/1972"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 21);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "31/10/1972"
            }.rawDate, result.rawDate);
        }
예제 #7
0
        public void AddDays_28022020_2920_26022028()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "28/02/2020"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 2920);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "26/02/2028"
            }.rawDate, result.rawDate);
        }
예제 #8
0
        public void AddDays_28022020_10000_16072047()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "28/02/2020"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 10000);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "16/07/2047"
            }.rawDate, result.rawDate);
        }
예제 #9
0
        public void AddDays_28022020_1461_28022024()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "28/02/2020"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 1461);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "28/02/2024"
            }.rawDate, result.rawDate);
        }
예제 #10
0
        public void AddDays_28022019_1_01032019()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "28/02/2019"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 1);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "01/03/2019"
            }.rawDate, result.rawDate);
        }
예제 #11
0
        public void AddDays_10101972_365_10101973()
        {
            DateCalculator dateCalculator = new DateCalculator();
            RawDate        rawDate        = new RawDate()
            {
                rawDate = "10/10/1972"
            };
            RawDate result = dateCalculator.AddDays(rawDate, 365);

            Assert.AreEqual(new RawDate()
            {
                rawDate = "10/10/1973"
            }.rawDate, result.rawDate);
        }