public async Task given_service_returns_error_then_Create_returns_ViewResult( CreateTheaterViewModel model, ISendCreateTheaterCommandService serviceStub, Error <TheaterLocation> error, [NoAutoProperties] TheatersController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendCreateTheaterCommand(It.IsAny <CreateNewTheater>())) .ReturnsAsync(error); // Act ActionResult actual = await sut.Create(model, serviceStub); // Assert actual.Should().BeOfType <ViewResult>(); actual.As <ViewResult>().Model.Should().BeSameAs(model); }
public async Task given_service_returns_error_then_Create_adds_model_error( CreateTheaterViewModel model, ISendCreateTheaterCommandService serviceStub, Error <TheaterLocation> error, [NoAutoProperties] TheatersController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendCreateTheaterCommand(It.IsAny <CreateNewTheater>())) .ReturnsAsync(error); // Act await sut.Create(model, serviceStub); // Assert ModelStateEntry state = sut.ModelState[string.Empty]; state.Errors.Should().Contain(e => e.ErrorMessage == error.Message); }
public async Task <ActionResult> Create( [FromForm] CreateTheaterViewModel model, [FromServices] ISendCreateTheaterCommandService service) { CreateNewTheater command = model.CreateCommand(); IResult <TheaterLocation> result = await service.SendCreateTheaterCommand(command); switch (result) { case Success <TheaterLocation> success: return(RedirectToAction(nameof(Index))); case Error <TheaterLocation> error: ModelState.AddModelError(string.Empty, error.Message); break; } return(View(model)); }
public async Task given_service_returns_success_then_Create_returns_RedirectToActionResult( CreateTheaterViewModel model, ISendCreateTheaterCommandService serviceStub, Success <TheaterLocation> success, [NoAutoProperties] TheatersController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendCreateTheaterCommand(It.Is <CreateNewTheater>( p => p.Name == model.Name && p.SeatRowCount == model.SeatRowCount && p.SeatColumnCount == model.SeatColumnCount))) .ReturnsAsync(success); // Act ActionResult actual = await sut.Create(model, serviceStub); // Assert actual.Should().BeOfType <RedirectToActionResult>(); actual.As <RedirectToActionResult>().ActionName.Should().Be("Index"); }