コード例 #1
0
        public async Task given_service_returns_error_then_AddScreening_returns_ViewResult(
            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
            ActionResult actual = await
                                  sut.AddScreening(movieId, model, serviceStub, awaiterDummy);

            // Assert
            actual.Should().BeOfType <ViewResult>();
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public async Task given_service_returns_success_then_Create_returns_RedirectToActionResult(
            CreateMovieViewModel model,
            ISendCreateMovieCommandService serviceStub,
            IResourceAwaiter awaiterDummy,
            Success <MovieLocation> success,
            [NoAutoProperties] MoviesController sut)
        {
            // Arrange
            Mock.Get(serviceStub)
            .Setup(
                x =>
                x.SendCreateMovieCommand(It.Is <CreateNewMovie>(
                                             p =>
                                             p.Title == model.Title)))
            .ReturnsAsync(success);

            // Act
            ActionResult actual = await
                                  sut.Create(model, serviceStub, awaiterDummy);

            // Assert
            actual.Should().BeOfType <RedirectToActionResult>();
            actual.As <RedirectToActionResult>().ActionName.Should().Be("Index");
        }