예제 #1
0
        public void EditLocation_Should_Edit()
        {
            Location existingLocation = new Location()
            {
                ID     = 1,
                Name   = "Location1",
                Active = true,
                AdditionalInformation = "Original additional info"
            };

            Location edittedLocation = new Location()
            {
                ID     = 1,
                Name   = "Location1",
                Active = true,
                AdditionalInformation = "Editted additional info"
            };

            mockLocationRepository.Setup(m => m.UpdateLocation(edittedLocation));

            LocationsService locationService = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object);

            locationService.EditLocation(existingLocation, edittedLocation);

            mockLocationRepository.Verify(m => m.UpdateLocation(edittedLocation), Times.Once);
        }
예제 #2
0
        public void EditLocation_Should_ThrowException_If_LocationExists()
        {
            Location existingLocation = new Location()
            {
                ID     = 1,
                Name   = "Location1",
                Active = true,
                AdditionalInformation = "Original additional info"
            };

            Location edittedLocation = new Location()
            {
                ID     = 1,
                Name   = "Location2",
                Active = true,
                AdditionalInformation = "Editted additional info"
            };

            mockLocationRepository.Setup(m => m.GetLocationByName(edittedLocation.Name)).Returns(edittedLocation);
            mockLocationRepository.Setup(m => m.UpdateLocation(edittedLocation));

            LocationsService locationService = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object);

            Assert.Throws <LocationExistsException>(() => locationService.EditLocation(existingLocation, edittedLocation));

            mockLocationRepository.Verify(m => m.UpdateLocation(edittedLocation), Times.Never);
        }
예제 #3
0
        public HttpResponseMessage EditLocation(int id, Location editLocation)
        {
            try
            {
                Location originalLoc = _locationRepository.GetLocationById(id);

                _locationService.EditLocation(originalLoc, editLocation);
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (LocationExistsException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, string.Format("Location {0} already exists.", editLocation.Name)));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to edit the location: " + editLocation.Name, ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }