public void PassTestSortByTagsAndDateRange() { // Arrange var eventFinderService = new EventFinderService(); var userService = new UserService(); var eventService = new EventService(); var eventTagService = new EventTagService(); const bool expected = true; var result = false; // Act var dob = DateTime.Parse("09/19/1999"); var user = new User(UserId1, FirstName, LastName, UserName, City, State, Country, dob, true); userService.InsertUser(user); var eventTime = DateTime.Parse("5/25/2028"); var expectedEvent = new Event(UserId1, EventId1, eventTime, EventName, Place, ""); eventService.InsertMadeEvent(expectedEvent); var eventTime2 = DateTime.Parse("5/20/2028"); var expectedEvent2 = new Event(UserId1, EventId2, eventTime2, EventName2, Place, ""); eventService.InsertMadeEvent(expectedEvent2); // TagId 4 -> Art eventTagService.InsertEventTag(EventId1, "Art"); eventTagService.InsertEventTag(EventId2, "Art"); var foundEvents = eventFinderService.FindEventByEventTags(new List <string>() { "Art" }); var sortedEvents = eventFinderService.CullEventListByDateRange(foundEvents, "5/20/2028", "5/25/2028"); if (sortedEvents[0].EventId == expectedEvent2.EventId && sortedEvents[1].EventId == expectedEvent.EventId) { result = true; } // Cleanup userService.DeleteUser(user); eventTagService.DeleteEventTag(EventId1, "Art"); eventTagService.DeleteEventTag(EventId2, "Art"); eventService.DeleteEvent(EventId1, UserId1, ""); eventService.DeleteEvent(EventId2, UserId1, ""); // Assert Assert.AreEqual(expected, result); }
public void PassTestFindEventsByTag() { // Arrange var eventFinderService = new EventFinderService(); var userService = new UserService(); var eventService = new EventService(); var eventTagService = new EventTagService(); const bool expected = true; var result = false; // Act var dob = DateTime.Parse("09/19/1999"); var user = new User(UserId1, FirstName, LastName, UserName, City, State, Country, dob, true); userService.InsertUser(user); var eventTime = DateTime.Parse("5/20/2028"); var expectedEvent = new Event(UserId1, EventId1, eventTime, EventName, Place, ""); eventService.InsertMadeEvent(expectedEvent); // TagId 4 -> Art eventTagService.InsertEventTag(EventId1, "Art"); var foundEvents = eventFinderService.FindEventByEventTags(new List <string>() { "Art" }); foreach (var events in foundEvents) { if (events.EventId.Equals(expectedEvent.EventId)) { result = true; } } // Cleanup userService.DeleteUser(user); eventTagService.DeleteEventTag(EventId1, "Art"); eventService.DeleteEvent(EventId1, UserId1, ""); // Assert Assert.AreEqual(expected, result); }
public IHttpActionResult GetEvents([FromBody] FindEventsForMeRequest request) { var eventFinder = new EventFinderService(); var tempList = new List <Event>(); var filteredEventList = new List <Event>(); try { // Return list of events unfiltered if (!request.UseTags && !request.UseDates && !request.UseLocation) { filteredEventList = eventFinder.FindAllEvents(); } // Return list of events filtered by tags else if (request.UseTags && !request.UseDates && !request.UseLocation) { filteredEventList = eventFinder.FindEventByEventTags(request.Tags); } // Filtered by Dates else if (!request.UseTags && request.UseDates && !request.UseLocation) { filteredEventList = eventFinder.FindEventsByDateRange(request.StartDate, request.EndDate); } // Filtered by Location else if (!request.UseTags && !request.UseDates && request.UseLocation) { filteredEventList = eventFinder.FindEventsByState(request.State); } // Filtered by Tags and Dates else if (request.UseTags && request.UseDates && !request.UseLocation) { tempList = eventFinder.FindEventByEventTags(request.Tags); filteredEventList = eventFinder.CullEventListByDateRange(tempList, request.StartDate, request.EndDate); } // Filtered by Tags and Location else if (request.UseTags && !request.UseDates && request.UseLocation) { tempList = eventFinder.FindEventByEventTags(request.Tags); filteredEventList = eventFinder.CullEventListByState(tempList, request.State); } // Filtered by Dates and Location else if (!request.UseTags && request.UseDates && request.UseLocation) { tempList = eventFinder.FindEventsByDateRange(request.StartDate, request.EndDate); filteredEventList = eventFinder.CullEventListByState(tempList, request.State); } // Filtered by Tags, Dates, and Location else if (request.UseTags && request.UseDates && request.UseLocation) { tempList = eventFinder.FindEventByEventTags(request.Tags); tempList = eventFinder.CullEventListByState(tempList, request.State); filteredEventList = eventFinder.CullEventListByDateRange(tempList, request.StartDate, request.EndDate); } } catch (ArgumentException argExcept) // Wrong should not be found, but if they are, catch here { return(Content(HttpStatusCode.BadRequest, argExcept)); } catch (Exception e) // Catch all of errors bubbling up from services { return(Content(HttpStatusCode.InternalServerError, e)); } // Return results return(Ok(filteredEventList)); }