public void GivenACreateAction_WhenTheModelStateIsInalid_ThenRenderTheDefaultView()
        {
            var model = new VacationPropertyViewModel();
            var stubRepository = Mock.Of<IVacationPropertiesRepository>();

            var controller = new VacationPropertiesController(stubRepository);
            controller.ModelState.AddModelError("Description", "The Description field is required");
            controller.WithCallTo(c => c.Create(model))
                .ShouldRenderDefaultView();
        }
        public async Task<ActionResult> Edit(VacationPropertyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var vacationProperty = await _repository.FindAsync(model.Id);
                vacationProperty.Description = model.Description;
                vacationProperty.ImageUrl = model.ImageUrl;

                await _repository.UpdateAsync(vacationProperty);

                return RedirectToAction("Index");
            }

            return View();
        }
        public void GivenACreateAction_WhenTheModelStateIsValid_ThenItRedirectsToIndex()
        {
            var model = new VacationPropertyViewModel();
            var mockRepository = new Mock<IVacationPropertiesRepository>();
            mockRepository.Setup(r => r.CreateAsync(It.IsAny<VacationProperty>())).ReturnsAsync(1);

            var controller = new VacationPropertiesController(mockRepository.Object)
            {
                UserId = () => "bob-id"
            };

            controller.WithCallTo(c => c.Create(model))
                .ShouldRedirectTo(c => c.Index());

            mockRepository.Verify(r => r.CreateAsync(It.IsAny<VacationProperty>()), Times.Once);
        }
        public async Task<ActionResult> Create(VacationPropertyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var vacationProperty = new VacationProperty
                {
                    UserId = UserId(),
                    Description = model.Description,
                    ImageUrl = model.ImageUrl,
                    CreatedAt = DateTime.Now
                };

                await _repository.CreateAsync(vacationProperty);

                return RedirectToAction("Index");
            }

            return View();
        }
        public void GivenAnEditAction_WhenTheModelStateIsValid_ThenItRedirectsToIndex()
        {
            var model = new VacationPropertyViewModel();
            var vacationProperty = new VacationProperty();

            var mockRepository = new Mock<IVacationPropertiesRepository>();
            mockRepository.Setup(r => r.FindAsync(It.IsAny<int>())).ReturnsAsync(vacationProperty);
            mockRepository.Setup(r => r.UpdateAsync(It.IsAny<VacationProperty>())).ReturnsAsync(1);

            var controller = new VacationPropertiesController(mockRepository.Object);

            controller.WithCallTo(c => c.Edit(model))
                .ShouldRedirectTo(c => c.Index());

            mockRepository.Verify(r => r.UpdateAsync(It.IsAny<VacationProperty>()), Times.Once);
        }