public async Task GetCallsMediatRWithExpectedNotFoundResult() { // Arrange mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <GetWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <IList <WatchListModel> >(null)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Get() as NotFoundObjectResult; // Assert mediatR.Verify(m => m.Send(It.IsAny <GetWatchListRequest>(), It.IsAny <CancellationToken>()), Times.Once()); Assert.NotNull(result); Assert.Equal("No watchlist WatchList found", result.Value); Assert.Equal(404, result.StatusCode); }
public async Task GetCallsMediatRWithExpectedResult() { // Arrange mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <GetWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(GetWatchListResponse())); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Get() as OkObjectResult; // Assert Assert.NotNull(result); Assert.Equal(200, result.StatusCode); var watchListModel = result.Value as IList <WatchListModel>; Assert.NotNull(watchListModel); Assert.Equal(2, watchListModel.Count); }