public void DeleteEventMultiple()
 {
     EventManager eventManager = new EventManager();
     DateTime dateOne = new DateTime(2000, 01, 01, 00, 00, 00);
     DateTime dateTwo = new DateTime(2010, 12, 31, 23, 59, 59);
     DateTime dateThree = new DateTime(2019, 05, 16, 13, 30, 00);
     CalendarEvent calendarEventOne =
         new CalendarEvent(dateOne, "party", "somewhere");
     CalendarEvent calendarEventTwo =
         new CalendarEvent(dateTwo, "exam", "somewhere");
     CalendarEvent calendarEventThree =
         new CalendarEvent(dateThree, "party", "club");
     CalendarEvent calendarEventFour =
         new CalendarEvent(dateOne, "exam", "academy");
     CalendarEvent calendarEventFive =
         new CalendarEvent(dateTwo, "sleep", null);
     CalendarEvent calendarEventSix =
         new CalendarEvent(dateThree, "sleep", null);
     CalendarEvent calendarEventSeven =
         new CalendarEvent(dateTwo, "party", null);
     eventManager.AddEvent(calendarEventOne);
     eventManager.AddEvent(calendarEventTwo);
     eventManager.AddEvent(calendarEventThree);
     eventManager.AddEvent(calendarEventFour);
     eventManager.AddEvent(calendarEventFive);
     eventManager.AddEvent(calendarEventSix);
     eventManager.AddEvent(calendarEventSeven);
     int firstCount = eventManager.DeleteEventsByTitle("party");
     Assert.AreEqual(3, firstCount);
     Assert.AreEqual(2, eventManager.CalendarByTitle.Count);
     Assert.IsFalse(eventManager.CalendarByTitle.ContainsKey("party"));
     int secondCount = eventManager.DeleteEventsByTitle("party");
     Assert.AreEqual(0, secondCount);
     Assert.AreEqual(2, eventManager.CalendarByTitle.Count);
 }
 public void ListEventAsAsked()
 {
     EventManager eventManager = new EventManager();
     DateTime dateOne = new DateTime(2000, 01, 01, 00, 00, 00);
     DateTime dateTwo = new DateTime(2010, 12, 31, 23, 59, 59);
     DateTime dateThree = new DateTime(2019, 05, 16, 13, 30, 00);
     CalendarEvent calendarEventOne =
         new CalendarEvent(dateOne, "party", "somewhere");
     CalendarEvent calendarEventTwo =
         new CalendarEvent(dateTwo, "exam", "somewhere");
     CalendarEvent calendarEventThree =
         new CalendarEvent(dateThree, "party", "club");
     CalendarEvent calendarEventFour =
         new CalendarEvent(dateOne, "exam", "academy");
     CalendarEvent calendarEventFive =
         new CalendarEvent(dateTwo, "sleep", null);
     CalendarEvent calendarEventSix =
         new CalendarEvent(dateThree, "sleep", null);
     CalendarEvent calendarEventSeven =
         new CalendarEvent(dateTwo, "party", null);
     eventManager.AddEvent(calendarEventOne);
     eventManager.AddEvent(calendarEventTwo);
     eventManager.AddEvent(calendarEventThree);
     eventManager.AddEvent(calendarEventFour);
     eventManager.AddEvent(calendarEventFive);
     eventManager.AddEvent(calendarEventSix);
     eventManager.AddEvent(calendarEventSeven);
     IEnumerable<CalendarEvent> list = eventManager.ListEvents(dateOne, 5);
     Assert.AreEqual(5, list.Count());
 }
예제 #3
0
        public static void Main()
        {
            // Second bottleneck
            // In the original code is used EM (EventManagerWithList)
            // It uses List<CalendarEvent> instead of
            // MultiDictionary<string, CalendarEvent> and
            // OrderedMultiDictionary<DateTime, CalendarEvent>, which are faster
            // Solution: use EventManager (EventManagerFast) instead of EM
            EventManager eventManager = new EventManager();
            var commandExecutor = new CommandExecutor(eventManager);

            while (true)
            {
                string commandText = Console.ReadLine();
                if (commandText == "End" || commandText == null)
                {
                    break;
                }

                try
                {
                    Command command = Command.Parse(commandText);
                    string result = commandExecutor.ProcessCommand(command);
                    Console.WriteLine(result);
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
 public void AddEventDuplicate()
 {
     EventManager eventManager = new EventManager();
     DateTime dateOne = new DateTime(2000, 01, 01, 00, 00, 00);
     DateTime dateTwo = new DateTime(2010, 12, 31, 23, 59, 59);
     DateTime dateThree = new DateTime(2019, 05, 16, 13, 30, 00);
     CalendarEvent calendarEventOne =
         new CalendarEvent(dateOne, "party", "somewhere");
     CalendarEvent calendarEventTwo =
         new CalendarEvent(dateTwo, "exam", "academy");
     CalendarEvent calendarEventThree =
         new CalendarEvent(dateThree, "sleep", null);
     CalendarEvent calendarEventFour =
         new CalendarEvent(dateTwo, "party", null);
     eventManager.AddEvent(calendarEventOne);
     eventManager.AddEvent(calendarEventTwo);
     eventManager.AddEvent(calendarEventThree);
     eventManager.AddEvent(calendarEventFour);
     eventManager.AddEvent(calendarEventTwo);
     eventManager.AddEvent(calendarEventTwo);
     eventManager.AddEvent(calendarEventOne);
     Assert.AreEqual(3, eventManager.CalendarByDate.Count);
     Assert.AreEqual(3, eventManager.CalendarByTitle.Count);
     Assert.IsTrue(eventManager.CalendarByTitle.ContainsKey("exam"));
     Assert.IsTrue(eventManager.CalendarByTitle.ContainsKey("party"));
     Assert.IsTrue(eventManager.CalendarByTitle.ContainsKey("sleep"));
 }
 public void AddEventWithLocation()
 {
     EventManager eventManager = new EventManager();
     DateTime date = new DateTime(2012, 01, 21, 20, 00, 00);
     CalendarEvent calendarEvent =
         new CalendarEvent(date, "party", "somewhere");
     eventManager.AddEvent(calendarEvent);
     Assert.AreEqual(1, eventManager.CalendarByDate.Count);
     Assert.IsTrue(eventManager.CalendarByDate.ContainsKey(date));
     Assert.IsTrue(eventManager.CalendarByTitle.ContainsKey("party"));
 }
 public void DeleteEvent()
 {
     EventManager eventManager = new EventManager();
     DateTime date = new DateTime(2012, 01, 21, 20, 00, 00);
     CalendarEvent calendarEvent =
         new CalendarEvent(date, "party", "somewhere");
     eventManager.AddEvent(calendarEvent);
     int count = eventManager.DeleteEventsByTitle("party");
     Assert.AreEqual(1, count);
     Assert.AreEqual(0, eventManager.CalendarByTitle.Count);
     Assert.AreEqual(0, eventManager.CalendarByDate.Count);
 }
        public void ListEventCheckOrder()
        {
            EventManager eventManager = new EventManager();
            DateTime dateOne = new DateTime(2000, 01, 01, 00, 00, 00);
            DateTime dateTwo = new DateTime(2010, 12, 31, 23, 59, 59);
            DateTime dateThree = new DateTime(2019, 05, 16, 13, 30, 00);
            CalendarEvent calendarEventOne =
                new CalendarEvent(dateOne, "party", "somewhere");
            CalendarEvent calendarEventTwo =
                new CalendarEvent(dateTwo, "exam", "somewhere");
            CalendarEvent calendarEventThree =
                new CalendarEvent(dateThree, "party", "club");
            CalendarEvent calendarEventFour =
                new CalendarEvent(dateOne, "exam", "academy");
            CalendarEvent calendarEventFive =
                new CalendarEvent(dateTwo, "sleep", null);
            CalendarEvent calendarEventSix =
                new CalendarEvent(dateThree, "party", null);
            CalendarEvent calendarEventSeven =
                new CalendarEvent(dateTwo, "party", null);
            eventManager.AddEvent(calendarEventOne);
            eventManager.AddEvent(calendarEventTwo);
            eventManager.AddEvent(calendarEventThree);
            eventManager.AddEvent(calendarEventFour);
            eventManager.AddEvent(calendarEventFive);
            eventManager.AddEvent(calendarEventSix);
            eventManager.AddEvent(calendarEventSeven);
            IEnumerable<CalendarEvent> list = eventManager.ListEvents(dateTwo, 5);
            Assert.AreEqual(5, list.Count());

            string expected = calendarEventTwo.ToString() + "\n" +
                calendarEventSeven.ToString() + "\n" +
                calendarEventFive.ToString() + "\n" +
                calendarEventSix.ToString() + "\n" +
                calendarEventThree.ToString();
            string actual = list.First().ToString() + "\n" +
                list.Skip(1).First().ToString() + "\n" +
                list.Skip(2).First().ToString() + "\n" +
                list.Skip(3).First().ToString() + "\n" +
                list.Skip(4).First().ToString();
            Assert.AreEqual(expected, actual);
        }
 public void DeleteNoEvent()
 {
     EventManager eventManager = new EventManager();
     DateTime date = new DateTime(2000, 01, 01, 00, 00, 00);
     CalendarEvent calendarEvent = new CalendarEvent(date, "party", null);
     eventManager.AddEvent(calendarEvent);
     int count = eventManager.DeleteEventsByTitle("exam");
     Assert.AreEqual(0, count);
     Assert.AreEqual(1, eventManager.CalendarByTitle.Count);
     Assert.AreEqual(1, eventManager.CalendarByDate.Count);
     Assert.IsTrue(eventManager.CalendarByDate.ContainsKey(date));
     Assert.IsTrue(eventManager.CalendarByTitle.ContainsKey("party"));
 }
 public void DeleteNoEventFromEmptyCatalog()
 {
     EventManager eventManager = new EventManager();
     int count = eventManager.DeleteEventsByTitle("party");
     Assert.AreEqual(0, count);
     Assert.AreEqual(0, eventManager.CalendarByTitle.Count);
     Assert.AreEqual(0, eventManager.CalendarByDate.Count);
 }
 public void ListNoEventLaterDate()
 {
     EventManager eventManager = new EventManager();
     DateTime date = new DateTime(2000, 01, 01, 00, 00, 00);
     DateTime otherDate = new DateTime(2010, 01, 01, 00, 00, 00);
     CalendarEvent calendarEvent = new CalendarEvent(date, "party", null);
     eventManager.AddEvent(calendarEvent);
     IEnumerable<CalendarEvent> list = eventManager.ListEvents(otherDate, 1);
     Assert.AreEqual(0, list.Count());
     Assert.AreEqual(1, eventManager.CalendarByTitle.Count);
     Assert.AreEqual(1, eventManager.CalendarByDate.Count);
     Assert.IsTrue(eventManager.CalendarByDate.ContainsKey(date));
     Assert.IsTrue(eventManager.CalendarByTitle.ContainsKey("party"));
 }
 public void ListEventOne()
 {
     EventManager eventManager = new EventManager();
     DateTime date = new DateTime(2012, 01, 21, 20, 00, 00);
     CalendarEvent calendarEvent = new CalendarEvent(date, "party", "somewhere");
     eventManager.AddEvent(calendarEvent);
     IEnumerable<CalendarEvent> list = eventManager.ListEvents(date, 1);
     Assert.AreEqual(1, list.Count());
     Assert.AreEqual(date, list.First().Date);
     Assert.AreEqual("party", list.First().Title);
     Assert.AreEqual("somewhere", list.First().Location);
 }
 public void ListEventFromEmptyCatalog()
 {
     EventManager eventManager = new EventManager();
     DateTime date = new DateTime(2000, 01, 01, 00, 00, 00);
     IEnumerable<CalendarEvent> list = eventManager.ListEvents(date, 1);
     Assert.AreEqual(0, list.Count());
     Assert.AreEqual(0, eventManager.CalendarByTitle.Count);
     Assert.AreEqual(0, eventManager.CalendarByDate.Count);
 }
 public void AddNoEvent()
 {
     EventManager eventManager = new EventManager();
     Assert.AreEqual(0, eventManager.CalendarByDate.Count);
 }