public void ThePromotionsAvailableAre(Table promotions) { foreach (TableRow row in promotions.Rows) { Promotion promoToAdd = new Promotion(); foreach (string key in row.Keys) { string value = row[key]; switch (key) { case "Status": promoToAdd.Status = new PromotionStatus { Type = EnumExtensions.ParseEnumFromCode<PromotionStatusEnum>(value) }; break; case "Name": promoToAdd.Name = value; break; case "DisplayName": promoToAdd.DisplayName = value; break; case "Discount": promoToAdd.Discount = decimal.Parse(value); break; case "AssociatedRatePlanIds": var splitString = value.Split(','); promoToAdd.AssociatedRatePlanIds = new List<int>(); foreach (string id in splitString) { int resultVal = 0; if (int.TryParse(id, out resultVal)) { promoToAdd.AssociatedRatePlanIds.Add(resultVal); } } break; case "AvailableStatus": AvailableStatus parsedAvailableStatus; AvailableStatus.TryParse(value, true, out parsedAvailableStatus); promoToAdd.AvailableStatus = parsedAvailableStatus; break; case "AvailableHours": promoToAdd.AvailableHours = int.Parse(value); break; case "AvailableDays": promoToAdd.ApplicableDaysString = value; break; } } promotionsAvailable.Add(promoToAdd); } }
public void GivenIHaveAPromotion() { Manager = new PromotionManager(); Promotion = new Promotion { AvailableStatus = AvailableStatus.Always, Id = PromotionId, BlackoutDates = new List<PromotionBlackoutDate>(), AssociatedRatePlanIds = new List<int>(), Status = new PromotionStatus{ Type = PromotionStatusEnum.Active}, ApplicableDaysString = "1111111" }; }
public void DeletePromotionIsSuccessful() { //Arrange var promotionToDelete = new Promotion(); var promotionDaoMock = new Mock<IPromotionDao>(); var eventTrackingManagerMock = new Mock<IEventTrackingManager>(); var ratePlanManagerMock = new Mock<IRatePlanManager>(); promotionDaoMock.Setup(p => p.DeletePromotion(It.Is<int>(i => i == PROMOTION_ID))).Returns(true); promotionDaoMock.Setup(p => p.GetByKey(It.Is<int>(i => i == PROMOTION_ID))).Returns(promotionToDelete); var links = new List<int> { 1, 2 }; promotionDaoMock.Setup(p => p.GetRatePlanIdsByPromoId(PROMOTION_ID)).Returns(links); promotionDaoMock.Setup(p => p.DeleteRatePlanLinks(PROMOTION_ID, links)); promotionDaoMock.Setup(p => p.GetBlackoutDatesByPromotionId(PROMOTION_ID)).Returns(new List<PromotionBlackoutDate>()); promotionDaoMock.Setup(p => p.DeleteBlackoutDates(It.IsAny<List<int>>())); ratePlanManagerMock.Setup(rpm => rpm.CreateRatePlanUpdateEvent(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())); eventTrackingManagerMock.Setup(e => e.CreateBusinessEventAsync(It.Is<long>(i => i == BUSINESS_ID), It.Is<BusinessEventTypesEnum>(b => b == BusinessEventTypesEnum.PromotionDeleted), It.Is<int>(i => i == PROMOTION_ID), It.IsAny<string>())); var promotionManager = new PromotionManager { EventTrackingManager = eventTrackingManagerMock.Object, PromotionDao = promotionDaoMock.Object, RatePlanManager = ratePlanManagerMock.Object }; //Act var status = promotionManager.DeletePromotion(BUSINESS_ID, PROMOTION_ID); //Assert Assert.IsTrue(status, "Promotion Manager did not return a successful status"); promotionDaoMock.VerifyAll(); eventTrackingManagerMock.VerifyAll(); }
internal static Promotion MapRecord(IDataRecord record, string prefix = "") { var promotion = new Promotion { AdditionalInformation = DbHelper.ConvertValue<string>(record[prefix + Parameters.AdditionalInformation]), ApplicableDaysString = DbHelper.ConvertValue<string>(record[prefix + Parameters.ApplicableDays]), AvailableHours = DbHelper.ConvertValue<int>(record[prefix + Parameters.AvailableNumberOfHours]), AvailableStatus = DbHelper.ConvertEnumValue<AvailableStatus>(record[prefix + Parameters.AvailableStatusCode]), BusinessId = DbHelper.ConvertValue<long>(record[prefix + Parameters.BusinessId]), Discount = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.Discount]), DisplayName = DbHelper.ConvertValue<string>(record[prefix + Parameters.DisplayName]), Id = DbHelper.ConvertValue<int>(record[prefix + Parameters.Id]), Name = DbHelper.ConvertValue<string>(record[prefix + Parameters.Name]), Status = new PromotionStatus { Type = DbHelper.ConvertEnumValue<PromotionStatusEnum>(record[prefix + Parameters.PromotionStatusCode]) }, AssociatedRatePlanCount = record.HasColumn(prefix + Parameters.AssociatedRatePlanCount) ? DbHelper.ConvertValue<int>(record[prefix + Parameters.AssociatedRatePlanCount]) : -1, StayStartDate = DbHelper.ConvertValue<DateTime?>(record[prefix + Parameters.StayStartDate]), StayEndDate = DbHelper.ConvertValue<DateTime?>(record[prefix + Parameters.StayEndDate]) }; return promotion; }
public void CreatePromotionStatusDefaultedToActive() { //Arrange var promotionDao = new Mock<IPromotionDao>(); var eventTrackingManager = new Mock<IEventTrackingManager>(); var checkStatus = new PromotionStatus() { Type = PromotionStatusEnum.Active }; var promotion = new Promotion { BusinessId = BUSINESS_ID, Name = "Test", DisplayName = "Test", Discount = 10, StayStartDate = DateTime.Now, StayEndDate = DateTime.Now.AddDays(1), AssociatedRatePlanIds = new List<int> { 1, 2 }, BlackoutDates = new List<PromotionBlackoutDate>(), }; promotionDao.Setup(p => p.CreatePromotion(promotion)).Callback(delegate { promotion.Id = PROMOTION_ID; }); promotionDao.Setup(p => p.CreateRatePlanLinks(It.IsAny<List<PromotionRatePlanLink>>())); promotionDao.Setup(p => p.CreateBlackoutDates(It.IsAny<List<PromotionBlackoutDate>>())); eventTrackingManager.Setup(e => e.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.PromotionAdded, promotion.Id, It.IsAny<string>())); var promotionManager = new PromotionManager { EventTrackingManager = eventTrackingManager.Object, PromotionDao = promotionDao.Object }; //Act promotionManager.CreatePromotion(promotion); //Assert Assert.AreEqual(checkStatus.Type, promotion.Status.Type, "Promotion Manager Status has changed."); promotionDao.VerifyAll(); eventTrackingManager.Verify(e => e.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.PromotionAdded, PROMOTION_ID, null), Times.Once); }
/// <summary> /// Add and remove promotion rate plan links where applicable /// </summary> /// <param name="promotion">The promotion to modify links for</param> private void ModifyPromotionRatePlanLinks(Promotion promotion) { // Remove old and inapplicable promo rate plans links var existingLinks = promotionDao.GetRatePlanIdsByPromoId(promotion.Id); var linksToDelete = existingLinks.Where(x => promotion.AssociatedRatePlanIds.All(y => y != x)).ToList(); promotionDao.DeleteRatePlanLinks(promotion.Id, linksToDelete); // Create promo rate plan links var linksToCreate = promotion.AssociatedRatePlanIds .Where(x => existingLinks.All(y => y != x)) .Select(ratePlanId => new PromotionRatePlanLink { PromotionId = promotion.Id, RatePlanId = ratePlanId }).ToList(); promotionDao.CreateRatePlanLinks(linksToCreate); }
/// <summary> /// Modify a pre-existing promotion /// </summary> /// <param name="promotion">Promotion</param> /// <returns>Success / Failure</returns> public bool ModifyPromotion(Promotion promotion) { bool status; // make sure the modified promotion data is valid promotion.IsValid(); //We need the promotions before doing modifications so we create push events for them as well var previousAssociatedRatePlanIds = promotionDao.GetRatePlanIdsByPromoId(promotion.Id); using (var tx = new BusinessTransaction()) { status = promotionDao.ModifyPromotion(promotion); ModifyPromotionRatePlanLinks(promotion); ModifyPromotionBlackoutDates(promotion); // commit the transaction tx.Commit(); } // write business event to event table after the commit and refresh promotion cache if (status) { eventTrackingManager.CreateBusinessEventAsync(promotion.BusinessId, BusinessEventTypesEnum.PromotionModified, promotion.Id); //create the events for the rateplans attached to the promotion //we don't pass dates in this case as we want it to do a full update for these rateplans previousAssociatedRatePlanIds.AddRange(promotion.AssociatedRatePlanIds); previousAssociatedRatePlanIds.Distinct().ToList().ForEach(ratePlan => RatePlanManager.CreateRatePlanUpdateEvent(ratePlan, promotion.BusinessId)); // refresh cache for this promotion business Cache.Cache.PromoCache.Invalidate(promotion.BusinessId); } return status; }
public void GetPromotionIsSuccessful() { // Arrange const long BUSINESS_ID = 1; const int PROMOTION_ID = 1; var promotion = new Promotion { BusinessId = BUSINESS_ID, Id = PROMOTION_ID, ApplicableDaysString = Constants.FULL_AVAILABILITY }; // Stub the BusinessCache to be used by our service method CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); var promotionManager = new Mock<IPromotionManager>(); PropertyManagementSystemService.PromotionManager = promotionManager.Object; promotionManager.Setup(p => p.GetByKey(It.Is<int>(i => i == PROMOTION_ID))).Returns(promotion); // Act var promo = PropertyManagementSystemService.GetPromotion(BUSINESS_ID, PROMOTION_ID); // Assert Assert.IsNotNull(promo, "Promotion is not returned"); promotionManager.VerifyAll(); }
/// <summary> /// Modify a pre-existing promotion /// </summary> /// <param name="promotion">Promotion</param> /// <returns>Success / Failure</returns> public bool ModifyPromotion(Promotion promotion) { const string sqlStatement = @"UPDATE Pricing.Promotion SET PromotionStatusCode = @PromotionStatusCode, Name = @Name, DisplayName = @DisplayName, AdditionalInformation = @AdditionalInformation, Discount = @Discount, ApplicableDays = @ApplicableDays, AvailableStatusCode = @AvailableStatusCode, AvailableNumberOfHours = @AvailableNumberOfHours, StayStartDate = @StayStartDate, StayEndDate = @StayEndDate, UpdatedByUserId = @UpdatedByUserId WHERE Id = @Id"; var parameters = new List<SqlParameter> { DbHelper.CreateParameter(Parameters.Id, promotion.Id), DbHelper.CreateParameter(Parameters.PromotionStatusCode, promotion.Status.Type.GetCode()), DbHelper.CreateParameter(Parameters.Name, promotion.Name), DbHelper.CreateParameter(Parameters.DisplayName, promotion.DisplayName), DbHelper.CreateParameter(Parameters.AdditionalInformation, promotion.AdditionalInformation), DbHelper.CreateParameter(Parameters.Discount, promotion.Discount), DbHelper.CreateParameter(Parameters.ApplicableDays, promotion.ApplicableDaysString), DbHelper.CreateParameter(Parameters.AvailableStatusCode, promotion.AvailableStatus.GetCode()), DbHelper.CreateParameter(Parameters.AvailableNumberOfHours, promotion.AvailableHours), DbHelper.CreateParameter(Parameters.StayStartDate, promotion.StayStartDate), DbHelper.CreateParameter(Parameters.StayEndDate, promotion.StayEndDate) }; // Add auditing parameters AuditFieldsHelper.PopulateAuditFields(parameters); return DbHelper.ExecuteNonQueryCommand(sqlStatement, parameters: parameters) != default(int); }
/// <summary> /// Create promotion blackout dates /// </summary> /// <param name="promotion">The promotion to create blackout dates for</param> private void CreatePromotionBlackoutDates(Promotion promotion) { // Create promo blackout dates var datesToCreate = promotion.BlackoutDates.Where(x => !x.Id.HasValue); promotionDao.CreateBlackoutDates(datesToCreate.Select(x => { x.PromotionId = promotion.Id; return x; }).ToList()); }
public void ModifyPromotionIsSuccesful() { //Arrange var promotionDaoMock = new Mock<IPromotionDao>(); var eventTrackingManagerMock = new Mock<IEventTrackingManager>(); var promotion = new Promotion { BusinessId = BUSINESS_ID, Id = PROMOTION_ID, Status = new PromotionStatus { Type = PromotionStatusEnum.Inactive }, AvailableStatus = AvailableStatus.Always, Name = "Test Name", DisplayName = "Test Display Name", Discount = 30, AssociatedRatePlanIds = new List<int> { 1, 2 }, BlackoutDates = new List<PromotionBlackoutDate>() }; var existingLinks = new List<int> { 2, 3, 4 }; promotionDaoMock.Setup(p => p.ModifyPromotion(It.Is<Promotion>(i => i == promotion))).Returns(true); promotionDaoMock.Setup(p => p.GetRatePlanIdsByPromoId(promotion.Id)).Returns(existingLinks); promotionDaoMock.Setup(p => p.DeleteRatePlanLinks(promotion.Id, It.IsAny<List<int>>())); promotionDaoMock.Setup(p => p.CreateRatePlanLinks(It.IsAny<List<PromotionRatePlanLink>>())); promotionDaoMock.Setup(p => p.GetBlackoutDatesByPromotionId(promotion.Id)).Returns(new List<PromotionBlackoutDate>()); promotionDaoMock.Setup(p => p.DeleteBlackoutDates(It.IsAny<List<int>>())); promotionDaoMock.Setup(p => p.ModifyBlackoutDates(It.IsAny<List<PromotionBlackoutDate>>())); promotionDaoMock.Setup(p => p.CreateBlackoutDates(It.IsAny<List<PromotionBlackoutDate>>())); eventTrackingManagerMock.Setup(e => e.CreateBusinessEventAsync(It.Is<long>(i => i == BUSINESS_ID), It.Is<BusinessEventTypesEnum>(b => b == BusinessEventTypesEnum.PromotionModified), It.Is<int>(i => i == PROMOTION_ID), It.IsAny<string>())); var promotionManager = new PromotionManager { EventTrackingManager = eventTrackingManagerMock.Object, PromotionDao = promotionDaoMock.Object }; //Act var status = promotionManager.ModifyPromotion(promotion); //Assert Assert.IsTrue(status, "Promotion Manager did not return a successful status"); promotionDaoMock.VerifyAll(); eventTrackingManagerMock.VerifyAll(); }
/// <summary> /// Check that a specific date is a valid stay date for a given promotion /// </summary> /// <param name="promo">The promotion to check against</param> /// <param name="date">The stay date to check</param> /// <returns>True/False</returns> public static bool IsPromotionAvailableOnStayDate(Promotion promo, DateTime date) { return IsPromotionStayDateValid(promo, date) && IsPromotionValidOnDay(promo, date); }
/// <summary> /// Checks promo stay dates and blackout dates /// </summary> /// <param name="promo">promotion to check against</param> /// <param name="date">date for the check (ratecache day for instance)</param> /// <returns>true if promotion applies, false if it doesn't</returns> private static bool IsPromotionStayDateValid(Promotion promo, DateTime date) { return (promo.StayStartDate == null || promo.StayStartDate <= date) && (promo.StayEndDate == null || promo.StayEndDate >= date) && (promo.BlackoutDates == null || // no blackouts or not in any of them promo.BlackoutDates.TrueForAll(bd => !(bd.StartDate <= date && bd.EndDate >= date))); }
/// <summary> /// Checks that a particular stay date is on a day of the week in which the promotion is active /// </summary> /// <param name="promo">promotion to check</param> /// <param name="date">date to check</param> /// <returns>true if promo available for day</returns> private static bool IsPromotionValidOnDay(Promotion promo, DateTime date) { return promo.ApplicableDays[date.DayOfWeek]; }
/// <summary> /// Checks that a particular stay date is within a promo's booking window /// </summary> /// <param name="promo">promotion to check</param> /// <param name="date">date to check</param> /// <returns>true if promo available for date</returns> private static bool IsPromotionInWindow(Promotion promo, DateTime date) { switch (promo.AvailableStatus) { case AvailableStatus.Always: return true; case AvailableStatus.EarlyBird: return date.Date.AddHours(-promo.AvailableHours) >= DateTime.UtcNow.Date; case AvailableStatus.LateArrival: return date.Date.AddHours(-promo.AvailableHours) <= DateTime.UtcNow.Date; } return false; }
/// <summary> /// Checks Rate Plan /// Status /// Booking Window /// DayOfWeek /// </summary> /// <remarks> /// Change for date checks /// </remarks> /// <param name="promo">promotion to check</param> /// <param name="price">price to check</param> /// <returns>true if available for this price</returns> private bool IsPromotionAvailable(Promotion promo, IPromotable price) { return promo.Status.Type == PromotionStatusEnum.Active && promo.AssociatedRatePlanIds != null && promo.AssociatedRatePlanIds.Any(i => i == price.RatePlanId) && IsPromotionInWindow(promo, price.Date) && IsPromotionStayDateValid(promo, price.Date) && IsPromotionValidOnDay(promo, price.Date); }
public void CreatePromotionWithMissingDataThrowsException() { //Arrange var promotionDao = new Mock<IPromotionDao>(); var promotion = new Promotion { BusinessId = BUSINESS_ID }; var promotionManager = new PromotionManager { PromotionDao = promotionDao.Object }; try { //Act promotionManager.CreatePromotion(promotion); Assert.Fail("Exception not thrown"); } catch (ValidationException ve) { // Assert Assert.AreEqual(Errors.SRVEX30149.ToString(), ve.Code, "Validation exception did not match"); } }
public void ModifyPromotionIsNotSuccesful() { //Arrange var promotionDaoMock = new Mock<IPromotionDao>(); var promotion = new Promotion { Id = PROMOTION_ID, Status = new PromotionStatus { Type = PromotionStatusEnum.Inactive }, AvailableStatus = AvailableStatus.Always, Name = "Test Name", DisplayName = "Test Display Name", Discount = 30, AssociatedRatePlanIds = new List<int>(), BlackoutDates = new List<PromotionBlackoutDate>() }; var existingLinks = new List<int> { 2, 3, 4 }; promotionDaoMock.Setup(p => p.ModifyPromotion(It.Is<Promotion>(i => i == promotion))).Returns(false); promotionDaoMock.Setup(p => p.GetRatePlanIdsByPromoId(promotion.Id)).Returns(existingLinks); promotionDaoMock.Setup(p => p.DeleteRatePlanLinks(promotion.Id, It.IsAny<List<int>>())); promotionDaoMock.Setup(p => p.CreateRatePlanLinks(It.IsAny<List<PromotionRatePlanLink>>())); promotionDaoMock.Setup(p => p.GetBlackoutDatesByPromotionId(promotion.Id)).Returns(new List<PromotionBlackoutDate>()); promotionDaoMock.Setup(p => p.DeleteBlackoutDates(It.IsAny<List<int>>())); promotionDaoMock.Setup(p => p.ModifyBlackoutDates(It.IsAny<List<PromotionBlackoutDate>>())); promotionDaoMock.Setup(p => p.CreateBlackoutDates(It.IsAny<List<PromotionBlackoutDate>>())); var promotionManager = new PromotionManager { PromotionDao = promotionDaoMock.Object }; //Act var status = promotionManager.ModifyPromotion(promotion); //Assert Assert.IsFalse(status, "Promotion Manager returned a successful status"); promotionDaoMock.VerifyAll(); }
public void CreatePromotionWithInvalidStayDatesThrowsException() { //Arrange var promotionDao = new Mock<IPromotionDao>(); var promotion = new Promotion { BusinessId = BUSINESS_ID, Name = "Test", DisplayName = "Test", Discount = 20, StayStartDate = DateTime.Now.AddDays(1), StayEndDate = DateTime.Now }; var promotionManager = new PromotionManager { PromotionDao = promotionDao.Object }; try { //Act promotionManager.CreatePromotion(promotion); Assert.Fail("Exception not thrown"); } catch (ValidationException ve) { // Assert Assert.AreEqual(Errors.SRVEX30151.ToString(), ve.Code, "Validation exception did not match"); } }
public void GetByKeyIsSuccesful() { //Arrange var promotionDaoMock = new Mock<IPromotionDao>(); var promotion = new Promotion { BusinessId = BUSINESS_ID, Id = PROMOTION_ID, Status = new PromotionStatus { Type = PromotionStatusEnum.Inactive }, AvailableStatus = AvailableStatus.Always, }; promotionDaoMock.Setup(p => p.GetByKey(It.Is<int>(i => i == PROMOTION_ID))).Returns(promotion); var promotionManager = new PromotionManager { PromotionDao = promotionDaoMock.Object }; //Act var promo = promotionManager.GetByKey(PROMOTION_ID); //Assert Assert.IsNotNull(promo, "Promotion was not returned"); promotionDaoMock.VerifyAll(); }
public void ModifyPromotionIsUnsuccessful() { // Arrange const int PROMOTION_ID = 1; var promotion = new Promotion { Id = PROMOTION_ID, Name = "Test", DisplayName = "Test", Status = new PromotionStatus { Type = PromotionStatusEnum.Active } }; // Act var status = promotionDao.ModifyPromotion(promotion); // Assert Assert.IsFalse(status, "The promotion was updated correctly"); }
/// <summary> /// Add, remove or modify promotion blackout dates where applicable /// </summary> /// <param name="promotion">The promotion to modify blackout dates for</param> private void ModifyPromotionBlackoutDates(Promotion promotion) { // Remove old and inapplicable promo blackout dates var existingDates = promotionDao.GetBlackoutDatesByPromotionId(promotion.Id); var datesToDelete = existingDates.Where(x => promotion.BlackoutDates.All(y => y.Id != x.Id)).Select(x => x.Id.Value).ToList(); promotionDao.DeleteBlackoutDates(datesToDelete); // Modify existing blackout dates var datesToModify = promotion.BlackoutDates.Where(x => datesToDelete.All(y => y != x.Id && x.Id.HasValue)).ToList(); promotionDao.ModifyBlackoutDates(datesToModify); // Create promo blackout dates CreatePromotionBlackoutDates(promotion); }
public void ModifyPromotionValidationFails() { //Arrange var promotion = new Promotion { Id = PROMOTION_ID, Status = new PromotionStatus { Type = PromotionStatusEnum.Inactive }, AvailableStatus = AvailableStatus.Always, Discount = 30 }; var promotionManager = new PromotionManager(); //Act var status = promotionManager.ModifyPromotion(promotion); //Assert Assert.IsFalse(status, "Promotion Manager returned a successful status"); }
public void CreatePromotionIsSuccessful() { const long businessId = 1; // Arrange var promotion = new Promotion { BusinessId = businessId, Name = "Test", DisplayName = "Test", Discount = 10, Status = new PromotionStatus { Type = PromotionStatusEnum.Active } }; // Act promotionDao.CreatePromotion(promotion); // Assert Assert.AreNotEqual(default(int), promotion.Id, "The promotion was not created successfully"); }
public void DeletePromotionIsNotSuccesful() { //Arrange var promotionToDelete = new Promotion(); var promotionDaoMock = new Mock<IPromotionDao>(); var ratePlanManagerMock = new Mock<IRatePlanManager>(); promotionDaoMock.Setup(p => p.DeletePromotion(It.Is<int>(i => i == PROMOTION_ID))).Returns(false); promotionDaoMock.Setup(p => p.GetByKey(It.Is<int>(i => i == PROMOTION_ID))).Returns(promotionToDelete); promotionDaoMock.Setup(p => p.GetRatePlanIdsByPromoId(It.Is<int>(i => i == PROMOTION_ID))).Returns(new List<int>() { RATEPLAN_ID }); ratePlanManagerMock.Setup(rpm => rpm.CreateRatePlanUpdateEvent(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())); var promotionManager = new PromotionManager { PromotionDao = promotionDaoMock.Object, RatePlanManager = ratePlanManagerMock.Object }; //Act var status = promotionManager.DeletePromotion(BUSINESS_ID, PROMOTION_ID); //Assert Assert.IsFalse(status, "Promotion Manager returned a successful status"); promotionDaoMock.VerifyAll(); }
public void ModifyPromotionIsSuccessful() { using (new TestDataHelper(GetTestQuery(TestQuery.PopulatePromotionTestData), GetTestQuery(TestQuery.CleanupUnitTestData))) { // Arrange const int PROMOTION_ID = 1; var promotion = new Promotion { Id = PROMOTION_ID, Name = "Test", DisplayName = "Test", AvailableStatus = AvailableStatus.Always, Status = new PromotionStatus { Type = PromotionStatusEnum.Active } }; // Act var status = promotionDao.ModifyPromotion(promotion); // Assert Assert.IsTrue(status, "The promotion was not updated correctly"); } }
/// <summary> /// Create a new promotion /// </summary> /// <param name="promotion">Promotion to create</param> public void CreatePromotion(Promotion promotion) { const string sqlStatement = @"INSERT INTO Pricing.Promotion ( BusinessId, PromotionStatusCode, Name, DisplayName, AdditionalInformation, Discount, ApplicableDays, AvailableStatusCode, AvailableNumberOfHours, StayStartDate, StayEndDate, UpdatedByUserId ) VALUES( @BusinessId, @PromotionStatusCode, @Name, @DisplayName, @AdditionalInformation, @Discount, @ApplicableDays, @AvailableStatusCode, @AvailableNumberOfHours, @StayStartDate, @StayEndDate, @UpdatedByUserId) SELECT @Id = SCOPE_IDENTITY()"; if (promotion.Id > 0) { throw new Exception(); } var parameters = new List<SqlParameter> { DbHelper.CreateParameter(Parameters.BusinessId, promotion.BusinessId), DbHelper.CreateParameter(Parameters.Name, promotion.Name), DbHelper.CreateParameter(Parameters.DisplayName, promotion.DisplayName), DbHelper.CreateParameter(Parameters.AdditionalInformation, promotion.AdditionalInformation), DbHelper.CreateParameter(Parameters.PromotionStatusCode, promotion.Status.Type.GetCode()), DbHelper.CreateParameter(Parameters.AvailableStatusCode, promotion.AvailableStatus.GetCode()), DbHelper.CreateParameter(Parameters.AvailableNumberOfHours, promotion.AvailableHours), DbHelper.CreateParameter(Parameters.ApplicableDays, promotion.ApplicableDaysString), DbHelper.CreateParameter(Parameters.Discount, promotion.Discount), DbHelper.CreateParameter(Parameters.StayStartDate, promotion.StayStartDate), DbHelper.CreateParameter(Parameters.StayEndDate, promotion.StayEndDate) }; SqlParameter outputKey = DbHelper.CreateParameterOut<int>(Parameters.Id, SqlDbType.Int); parameters.Add(outputKey); // Add auditing parameters AuditFieldsHelper.PopulateAuditFields(parameters); DbHelper.ExecuteNonQueryCommand(sqlStatement, parameters: parameters); promotion.Id = DbHelper.ParameterValue<int>(outputKey); }
public void GivenThereArePromotions(Table promotions) { promotionsAvailable = new List<Promotion>(); foreach (TableRow row in promotions.Rows) { Promotion promoToAdd = new Promotion { ApplicableDaysString = "1111111", AssociatedRatePlanIds = new List<int> {1}, Discount = 10, AvailableHours = 48, AvailableStatus = AvailableStatus.Always, Status = new PromotionStatus {Type = PromotionStatusEnum.Active}, DisplayName = "Promotion" }; foreach (string key in row.Keys) { string value = row[key]; switch (key) { case "name": case "Name": promoToAdd.Name = value; promoToAdd.DisplayName = value; break; case "Discount": promoToAdd.Discount = decimal.Parse(value); break; } } promotionsAvailable.Add(promoToAdd); } }
public void GetPromotionForIncorrectBusiness() { // Arrange const long BUSINESS_ID = 1; const int PROMOTION_ID = 1; var promotion = new Promotion { BusinessId = 111, Id = PROMOTION_ID, ApplicableDaysString = Constants.FULL_AVAILABILITY }; // Stub the BusinessCache to be used by our service method CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); var promotionManager = new Mock<IPromotionManager>(); PropertyManagementSystemService.PromotionManager = promotionManager.Object; promotionManager.Setup(p => p.GetByKey(It.Is<int>(i => i == PROMOTION_ID))).Returns(promotion); // Act PropertyManagementSystemService.GetPromotion(BUSINESS_ID, PROMOTION_ID); }
/// <summary> /// Create a new promotion /// </summary> /// <param name="promotion">Promotion to create</param> public void CreatePromotion(Promotion promotion) { if (promotion.Status == null) { promotion.Status = new PromotionStatus { Type = PromotionStatusEnum.Active }; } if (promotion.IsValid()) { using (var tx = new BusinessTransaction()) { promotionDao.CreatePromotion(promotion); // Create promo rate plan links var links = promotion.AssociatedRatePlanIds.Select(ratePlanId => new PromotionRatePlanLink { PromotionId = promotion.Id, RatePlanId = ratePlanId }).ToList(); promotionDao.CreateRatePlanLinks(links); // Create promo blackout dates CreatePromotionBlackoutDates(promotion); tx.Commit(); } if (promotion.Id != default(int)) { eventTrackingManager.CreateBusinessEventAsync(promotion.BusinessId, BusinessEventTypesEnum.PromotionAdded, promotion.Id); //create the events for the rateplans attached to the promotion promotion.AssociatedRatePlanIds.ForEach(ratePlan => RatePlanManager.CreateRatePlanUpdateEvent(ratePlan, promotion.BusinessId, promotion.StayStartDate, promotion.StayEndDate)); // refresh cache for this promotion business Cache.Cache.PromoCache.Invalidate(promotion.BusinessId); } } }