public void CheckIncorrectDatesTest() { var converter = new ConvertDate(); DateTime date1, date2; string format = "dd.MM.yyyy"; // same date try { date1 = DateTime.ParseExact("01.01.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); date2 = DateTime.ParseExact("01.01.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); converter.CheckDates(date1, date2); } catch (IncorrectRelationshipException) { } catch (Exception) { Assert.Fail(); } // greater day try { date1 = DateTime.ParseExact("02.01.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); date2 = DateTime.ParseExact("01.01.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); converter.CheckDates(date1, date2); } catch (IncorrectRelationshipException) { } catch (Exception) { Assert.Fail(); } // greater month try { date1 = DateTime.ParseExact("01.02.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); date2 = DateTime.ParseExact("01.01.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); converter.CheckDates(date1, date2); } catch (IncorrectRelationshipException) { } catch (Exception) { Assert.Fail(); } // greater year try { date1 = DateTime.ParseExact("01.01.2022", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); date2 = DateTime.ParseExact("01.01.2021", format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); converter.CheckDates(date1, date2); } catch (IncorrectRelationshipException) { } catch (Exception) { Assert.Fail(); } Assert.IsTrue(true); }
static void Main(string[] args) { ConvertDate converter = new ConvertDate(); if (args.Length == 1 && args[0] == "--help") { Info.WriteHelp(); } else if (args.Length == 2) { try { DateTime date1 = converter.ParseDate(args[0]), date2 = converter.ParseDate(args[1]); converter.CheckDates(date1, date2); Console.WriteLine(converter.GetDateRange(date1, date2)); } catch (IncorrectFormatException e) { Console.WriteLine(e.Message); Info.RunInfo(); } catch (IncorrectRelationshipException e) { Console.WriteLine(e.Message); Info.RunInfo(); } } else { Info.IncorrectNumberOfParameters(args); } }