public async Task GetEventsByDateRangeReturnsNoContentWhenEventsIsNull() { var may = new DateTimeOffset(2016, 5, 1, 0, 0, 0, new TimeSpan()); var june = new DateTimeOffset(2016, 6, 1, 0, 0, 0, new TimeSpan()); var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <EventByDateRangeQuery>())).ReturnsAsync((List <EventViewModel>)null); var sut = new EventApiController(mediator.Object); var result = await sut.GetEventsByDateRange(may, june); Assert.IsType <NoContentResult>(result); }
public void GetEventsByDateRangeReturnsJsonWhenEventsIsNotNull() { var may = new DateTimeOffset(2016, 5, 1, 0, 0, 0, new TimeSpan()); var june = new DateTimeOffset(2016, 6, 1, 0, 0, 0, new TimeSpan()); var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <EventByDateRangeQuery>())).Returns(new List <EventViewModel>()); var sut = new EventApiController(mediator.Object); var result = sut.GetEventsByDateRange(may, june); Assert.IsType <JsonResult>(result); }
public async Task GetEventsByDateRangeSendsEventByDateRangeQueryWithCorrectDates() { var may = new DateTimeOffset(2016, 5, 1, 0, 0, 0, new TimeSpan()); var june = new DateTimeOffset(2016, 6, 1, 0, 0, 0, new TimeSpan()); var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <EventByDateRangeQuery>())).ReturnsAsync(new List <EventViewModel>()); var sut = new EventApiController(mediator.Object); await sut.GetEventsByDateRange(may, june); mediator.Verify(x => x.SendAsync(It.Is <EventByDateRangeQuery>(y => y.StartDate == may && y.EndDate == june)), Times.Once); }