public async Task PostCallsWithInValidModelStateExpectedNotFoundResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498 }; mediatR = new Mock <IMediator>(); controller = new WatchListController(mediatR.Object); controller.ModelState.AddModelError("Comments", "Comments is Required"); // Act var result = await controller.Post(watchListModel) as BadRequestObjectResult; // Assert Assert.NotNull(result); Assert.Equal(400, result.StatusCode); }
public async Task PostCallsMediatRWithExpectedNotFoundResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498, Comments = "Deadpool 2 is review good" }; mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <CreateBookingRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <WatchListModel>(null)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Post(watchListModel) as ObjectResult; // Assert mediatR.Verify(m => m.Send(It.IsAny <CreateBookingRequest>(), It.IsAny <CancellationToken>()), Times.Once()); Assert.NotNull(result); Assert.Equal(409, result.StatusCode); }
public async Task PostCallsMediatRWithExpectedResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498, Comments = "Deadpool 2 is review good" }; mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <CreateBookingRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(watchListModel)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Post(watchListModel) as CreatedResult; // Assert Assert.NotNull(result); Assert.Equal(201, result.StatusCode); var watchListModels = result.Value as WatchListModel; Assert.NotNull(watchListModels); Assert.Equal("Deadpool 2 is review good", watchListModels.Comments); }