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"
         };
 }
Esempio n. 2
0
            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();
            }
Esempio n. 3
0
            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();
            }
Esempio n. 4
0
            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();
            }
Esempio n. 5
0
            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");
            }
Esempio n. 6
0
            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();
            }
Esempio n. 7
0
            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();
            }
Esempio n. 8
0
            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");
                }
            }
Esempio n. 9
0
            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");
                }
            }
Esempio n. 10
0
            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);
            }
Esempio n. 11
0
            public void UpsertPromotionRatePlanLinksCallsMethodsCorrectly()
            {
                var existingPromotions = new List<Model.Pricing.Promotions.Promotion>
                    {
                        new Promotion
                        {
                            Id = 1,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID,
                                RATEPLAN_ID + 1
                            }
                        },
                        new Promotion
                        {
                            Id = 2,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID + 1
                            }
                        },
                        new Promotion
                        {
                            Id = 3,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID,
                                RATEPLAN_ID + 2
                            }
                        },
                    };

                var ratePlan = new VariantRatePlan
                {
                    BusinessId = BUSINESS_ID,
                    Id = RATEPLAN_ID,
                    AssociatedPromotions = new List<Model.Pricing.Promotions.Promotion>
                    {
                        new Promotion
                        {
                            Id = 2,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID,
                                RATEPLAN_ID + 1
                            }
                        }
                    }
                };

                var promotionDaoMock = new Mock<IPromotionDao>();
                promotionDaoMock.Setup(p => p.DeletePromoLinks(ratePlan.Id, It.Is<IEnumerable<int>>(i => i.Any(x => x == 1 || x == 3))));
                promotionDaoMock.Setup(p => p.CreateRatePlanLinks(It.Is<List<PromotionRatePlanLink>>(prpl => prpl.Any(x => x.PromotionId == 2 && x.RatePlanId == RATEPLAN_ID))));

                var promotionManager = new PromotionManager();
                promotionManager.PromotionDao = promotionDaoMock.Object;
                Helpers.CacheHelper.StubPromoCacheWithPromotions(BUSINESS_ID, existingPromotions);
                Cache.PromoCache.Invalidate();

                promotionManager.UpsertPromotionRatePlanLinks(ratePlan);

                promotionDaoMock.VerifyAll();
                Helpers.CacheHelper.ReAssignPromotionDaoToPromoCache();
            }