public void Verify_Update_Should_SetTheEntityStateToModified()
        {
            // Arrange
            Mock <IDbSet <Location> > mockSetLocations;
            var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
            var repository  = new LocationsRepository(mockContext.Object);
            var locations   = repository.Get(1);

            locations.ApiDetailUrl = "/TEST";
            // Act
            repository.Update(locations);
            // Assert
            mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once);
        }
Пример #2
0
        public ActionResult EditPost(int id, LocationEditViewModel model)
        {
            try
            {
                DbLocation location = GetLocationIfExistsAndUserHasAccess(id);
                if (location == null)
                {
                    return(RedirectToAction("Index"));
                }

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                if (location == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                LocationsRepository locationsRepository = _unitOfWork.LocationsRepository;
                location.Name              = model.Name;
                location.Description       = model.Description;
                location.Organisation      = model.Organisation;
                location.PricePerDay       = model.PricePerDay;
                location.Capacity          = model.Capacity;
                location.AddressCity       = model.AddressCity;
                location.AddressNumber     = model.AddressNumber;
                location.AddressPostalCode = model.AddressPostalCode;
                location.AddressProvince   = model.AddressProvince;
                location.AddressStreet     = model.AddressStreet;
                locationsRepository.Update(location);

                TempData["AlertType"]    = "success";
                TempData["AlertMessage"] = "De aanpassingen zijn correct opgeslagen.";

                return(RedirectToAction("Edit", new { id = id }));
            }
            catch
            {
                TempData["AlertType"]    = "danger";
                TempData["AlertMessage"] = "Er is iets fout gelopen tijdens het verwerken van de aanpassingen!";

                return(View(model));
            }
        }
 public void Verify_Update_Should_SetTheEntityStateToModified()
 {
     // Arrange
     Mock<IDbSet<Location>> mockSetLocations;
     var mockContext = LocationsMockingSetup.DoMockingSetupForContext(true, out mockSetLocations);
     var repository = new LocationsRepository(mockContext.Object);
     var locations = repository.Get(1);
     locations.ApiDetailUrl = "/TEST";
     // Act
     repository.Update(locations);
     // Assert
     mockContext.Verify(x => x.SetModified(It.IsAny<object>()), Times.Once);
 }