public void ToggleLocationActive_Should_Update_When_False_And_HasExistingBookings() { List <Booking> existingBookings = new List <Booking>() { new Booking() { ID = 1, PID = "1234", Owner = "Reece" }, new Booking() { ID = 2, PID = "5678", Owner = "Charlie" } }; Location existingLocation = new Location() { ID = 1, Name = "Location1", Active = true, AdditionalInformation = "Original additional info" }; mockBookingRepository.Setup(x => x.GetByDateAndLocation(It.IsAny <DateTime>().Date, existingLocation)).Returns(existingBookings); mockDirectoryRepository.Setup(m => m.GetUser(It.Is <Pid>(x => x.Identity == "1234"))).Returns(new User() { EmailAddress = "*****@*****.**" }); mockDirectoryRepository.Setup(m => m.GetUser(It.Is <Pid>(x => x.Identity == "5678"))).Returns(new User() { EmailAddress = "*****@*****.**" }); string fakeFromEmailAddress = "*****@*****.**"; string fakeBody = "Some Body Contents"; mockEmailHelper.Setup(m => m.GetEmailMarkup(It.IsAny <string>(), It.IsAny <List <Booking> >())).Returns(fakeBody); mockEmailHelper.Setup(m => m.SendEmail(fakeFromEmailAddress, It.IsAny <string>(), It.IsAny <string>(), fakeBody, It.IsAny <bool>())); NameValueCollection appSettings = new NameValueCollection(); appSettings.Add("fromEmail", fakeFromEmailAddress); LocationsService service = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object); service.ToggleLocationActive(existingLocation, false, appSettings); mockLocationRepository.Verify(m => m.UpdateLocation(existingLocation), Times.Once); mockBookingRepository.Verify(m => m.Delete(It.IsAny <List <Booking> >()), Times.Once); mockEmailHelper.Verify(m => m.SendEmail(fakeFromEmailAddress, It.IsAny <string>(), It.IsAny <string>(), fakeBody, It.IsAny <bool>()), Times.Exactly(existingBookings.Count)); }
public HttpResponseMessage EnableDisableLocation(int id, bool active) { try { Location location = _locationRepository.GetLocationById(id); _locationService.ToggleLocationActive(location, active, ConfigurationManager.AppSettings); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { _logger.ErrorException("Unable to enable/disable room.", ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public void ToggleLocationActive_Should_Update_When_True() { Location existingLocation = new Location() { ID = 1, Name = "Location1", Active = false, AdditionalInformation = "Original additional info" }; NameValueCollection appSettings = new NameValueCollection(); appSettings.Add("fromEmail", "*****@*****.**"); LocationsService service = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object); service.ToggleLocationActive(existingLocation, true, appSettings); mockLocationRepository.Verify(m => m.UpdateLocation(existingLocation), Times.Once); mockBookingRepository.Verify(m => m.Delete(It.IsAny <List <Booking> >()), Times.Never); mockEmailHelper.Verify(m => m.SendEmail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Never); }