public async Task given_service_returns_error_then_AddScreening_sets_model( AddScreeningViewModel model, ISendAddScreeningCommandService serviceStub, IResourceAwaiter awaiterDummy, Error <ScreeningLocation> error, [NoAutoProperties] MoviesController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendAddScreeningCommand(It.IsAny <AddNewScreening>())) .ReturnsAsync(error); Guid movieId = model.MovieId; // Act dynamic result = await sut.AddScreening(movieId, model, serviceStub, awaiterDummy); // Assert object actual = result.Model; actual.Should().BeSameAs(model); }
public async Task AddScreening_sets_route_values_correctly( AddScreeningViewModel model, ISendAddScreeningCommandService serviceStub, IResourceAwaiter awaiterDummy, Success <ScreeningLocation> success, [NoAutoProperties] MoviesController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendAddScreeningCommand(It.IsAny <AddNewScreening>())) .ReturnsAsync(success); Guid movieId = model.MovieId; // Act dynamic result = await sut.AddScreening(movieId, model, serviceStub, awaiterDummy); // Assert RouteValueDictionary actual = result.RouteValues; actual.Should().Contain("movieId", movieId); }
public async Task AddScreening_returns_RedirectToActionResult( AddScreeningViewModel model, ISendAddScreeningCommandService serviceStub, IResourceAwaiter awaiterDummy, Success <ScreeningLocation> success, [NoAutoProperties] MoviesController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendAddScreeningCommand(It.Is <AddNewScreening>( p => p.MovieId == model.MovieId && p.TheaterId == model.TheaterId && p.ScreeningTime == model.ScreeningTime && p.DefaultFee == model.DefaultFee && p.ChildrenFee == model.ChildrenFee))) .ReturnsAsync(success); Guid movieId = model.MovieId; // Act ActionResult actual = await sut.AddScreening(movieId, model, serviceStub, awaiterDummy); // Assert actual.Should().BeOfType <RedirectToActionResult>(); }
public async Task <ActionResult> AddScreening( [FromRoute] Guid movieId, [FromForm] AddScreeningViewModel model, [FromServices] ISendAddScreeningCommandService service, [FromServices] IResourceAwaiter awaiter) { AddNewScreening command = model.CreateCommand(); IResult <ScreeningLocation> result = await service.SendAddScreeningCommand(command); switch (result) { case Success <ScreeningLocation> success: await awaiter.AwaitResource(success.Value.Uri); var routeValues = new { movieId }; return(RedirectToAction("Screenings", routeValues)); case Error <ScreeningLocation> error: ModelState.AddModelError(string.Empty, error.Message); break; } return(View(model)); }
private void ViewModel_AddingScreening(object sender, EventArgs e) { _mainView.Close(); _mainViewModel.LogoutSucceeded -= ViewModel_LogoutSucceeded; _mainViewModel.MessageApplication -= ViewModel_MessageApplication; _mainViewModel.BuyingTicket -= ViewModel_BuyingTicket; _mainViewModel.AddingMovie -= ViewModel_AddingMovie; _mainViewModel.AddingScreening -= ViewModel_AddingScreening; _addScreeningViewModel = new AddScreeningViewModel(_service); _addScreeningView = new AddScreening { DataContext = _addScreeningViewModel }; _addScreeningViewModel.AddingScreeningEnded += ViewModel_AddingScreeningEnded; _addScreeningView.Closed += ViewModel_AddingScreeningEnded; _addScreeningView.ShowDialog(); }
public async Task given_service_returns_error_then_AddScreening_adds_model_error( AddScreeningViewModel model, ISendAddScreeningCommandService serviceStub, IResourceAwaiter awaiterDummy, Error <ScreeningLocation> error, [NoAutoProperties] MoviesController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendAddScreeningCommand(It.IsAny <AddNewScreening>())) .ReturnsAsync(error); Guid movieId = model.MovieId; // Act await sut.AddScreening(movieId, model, serviceStub, awaiterDummy); // Assert ModelStateEntry state = sut.ModelState[string.Empty]; state.Errors.Should().Contain(e => e.ErrorMessage == error.Message); }
public async Task AddScreening_awaits_resource_creation( AddScreeningViewModel model, ISendAddScreeningCommandService serviceStub, IResourceAwaiter awaiterSpy, Success <ScreeningLocation> success, [NoAutoProperties] MoviesController sut) { // Arrange Mock.Get(serviceStub) .Setup( x => x.SendAddScreeningCommand(It.IsAny <AddNewScreening>())) .ReturnsAsync(success); Guid movieId = model.MovieId; // Act await sut.AddScreening(movieId, model, serviceStub, awaiterSpy); // Assert Uri location = success.Value.Uri; Mock.Get(awaiterSpy).Verify(x => x.AwaitResource(location)); }