Ejemplo n.º 1
0
        public ActionResult Create(CreateTheaterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var theater = Mapper.Map <CreateTheaterViewModel, Theater>(model);

            var result = new Theater();

            using (var theaterRepo = new Repository <Theater>())
            {
                result = theaterRepo.InsertOrUpdate(theater);
            }
            return(RedirectToAction("Detail", new { id = result.Id }));
        }
        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);
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 6
0
        public ActionResult Create()
        {
            var model = new CreateTheaterViewModel();

            return(View(model));
        }