public void GivenAnEditAction_ThenRendersTheDefaultView()
        {
            var vacationProperty = new VacationProperty();
            var mockRepository = new Mock<IVacationPropertiesRepository>();
            mockRepository.Setup(r => r.FindAsync(It.IsAny<int>())).ReturnsAsync(vacationProperty);

            var controller = new VacationPropertiesController(mockRepository.Object);
            controller.WithCallTo(c => c.Edit(1))
                .ShouldRenderDefaultView()
                .WithModel(vacationProperty);
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Description,ImageUrl")] VacationProperty vacationProperty)
        {
            if (ModelState.IsValid)
            {
                var user = await _userRepository.GetUserAsync(HttpContext.User);

                vacationProperty.UserId    = user.Id;
                vacationProperty.CreatedAt = DateTime.Now;

                await _repository.CreateVacationPropertyAsync(vacationProperty);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vacationProperty));
        }
        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);
        }
Esempio n. 4
0
        public void GivenACreateAction_ThenRendersTheDefaultView()
        {
            var vacationProperty = new VacationProperty {
                User = new ApplicationUser()
            };
            var mockVacationsRepository = new Mock <IVacationPropertiesRepository>();

            mockVacationsRepository.Setup(r => r.FindAsync(It.IsAny <int>())).ReturnsAsync(vacationProperty);
            var stubReservationsRepository = Mock.Of <IReservationsRepository>();
            var stubUsersRepository        = Mock.Of <IUsersRepository>();
            var stubNotifier = Mock.Of <INotifier>();
            var controller   = new ReservationsController(
                mockVacationsRepository.Object, stubReservationsRepository, stubUsersRepository, stubNotifier);

            controller.WithCallTo(c => c.Create(1))
            .ShouldRenderDefaultView();
        }
        public async Task CreateActionPost_ThenCreatePropertyAndRedirect()
        {
            var vacationProperty = new VacationProperty()
            {
                Description = "ana's property",
            };

            var result = await _controller.Create(vacationProperty);

            // Assert
            Assert.True(_controller.ModelState.IsValid);
            Assert.IsType <RedirectToActionResult>(result);

            _mockUserRepository
            .Verify(u => u.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);
            _mockAppRepository
            .Verify(a => a.CreateVacationPropertyAsync(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());
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description,ImageUrl")] VacationProperty vacationPropertyUpdate)
        {
            if (id != vacationPropertyUpdate.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var vacationProperty = await _repository.FindVacationPropertyFirstOrDefaultAsync(id);

                if (vacationProperty == null)
                {
                    return(NotFound());
                }
                await _repository.UpdateVacationPropertyAsync(vacationProperty);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = vacationPropertyUpdate.UserId;
            return(View(vacationPropertyUpdate));
        }
 public async Task <int> UpdateAsync(VacationProperty property)
 {
     _context.Entry(property).State = EntityState.Modified;
     return(await _context.SaveChangesAsync());
 }
 public async Task <int> CreateAsync(VacationProperty property)
 {
     _context.VacationProperties.Add(property);
     return(await _context.SaveChangesAsync());
 }
 public async Task<int> UpdateAsync(VacationProperty property)
 {
     _context.Entry(property).State = EntityState.Modified;
     return await _context.SaveChangesAsync();
 }
 public async Task<int> CreateAsync(VacationProperty property)
 {
     _context.VacationProperties.Add(property);
     return await _context.SaveChangesAsync();
 }