コード例 #1
0
 public HttpResponseMessage SaveNewLocation(Location newLocation)
 {
     try
     {
         _locationService.SaveNewLocation(newLocation);
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     catch (LocationExistsException e)
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
     catch (Exception ex)
     {
         _logger.ErrorException("Unable to create new location: " + newLocation.Name, ex);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
コード例 #2
0
        public void SaveNewLocation_Should_ThrowException_When_LocationExists()
        {
            Location newLocation = new Location()
            {
                ID     = 1,
                Name   = "Location1",
                Active = true,
                AdditionalInformation = "Original additional info"
            };

            mockLocationRepository.Setup(m => m.GetLocationById(newLocation.ID)).Returns(newLocation);
            mockLocationRepository.Setup(m => m.SaveNewLocation(newLocation));

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

            Assert.Throws <LocationExistsException>(() => locationService.SaveNewLocation(newLocation));

            mockLocationRepository.Verify(m => m.SaveNewLocation(newLocation), Times.Never);
        }
コード例 #3
0
        public void SaveNewLocation_Should_SaveLocation()
        {
            Location newLocation = new Location()
            {
                ID     = 1,
                Name   = "Location1",
                Active = true,
                AdditionalInformation = "Original additional info"
            };

            mockLocationRepository.Setup(m => m.GetLocationById(newLocation.ID)).Returns((Location)null);
            mockLocationRepository.Setup(m => m.SaveNewLocation(newLocation));

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

            locationService.SaveNewLocation(newLocation);

            mockLocationRepository.Verify(m => m.SaveNewLocation(newLocation), Times.Once);
        }