public void GetMonthEventsTest() { // given int monthId = 2; var eventComparer = new EventComparerForEventModels(); var expectedResult = _events .FindAll(e => e.EventDateTime.Year == DateTime.Now.Year && e.EventDateTime.Month == monthId) .OrderBy(e => e, eventComparer); // when var events = _eventServices.GetMonthEvents(monthId); // then Assert.IsNotNull(events); CollectionAssert.IsNotEmpty(events); var eventModels = mapper.Map <List <EventModel>, List <Event> >(events.ToList()); var actualResult = eventModels .OrderBy(e => e, eventComparer); CollectionAssert.AreEqual(actualResult, expectedResult, eventComparer); }
// GET api/Events/GetMonthEvents?monthId={monthId} public HttpResponseMessage GetMonthEvents(int monthId) { var events = _eventServices.GetMonthEvents(monthId); if (events != null) { var eventsList = events as List <EventModel> ?? events.ToList(); if (eventsList.Any()) { return(Request.CreateResponse(HttpStatusCode.OK, eventsList)); } } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Events in this month")); }