public void CreatePromotionCallsPromotionManager() { // Arrange const int businessId = 1; var promotionDto = new PromotionDto { BusinessId = businessId, Discount = 10, DisplayName = "NewPromo", Name = "Promo", Status = new PromotionStatusDto { Type = PromotionStatusEnumDto.Active } }; var promotionManager = new Mock<IPromotionManager>(); PropertyManagementSystemService.PromotionManager = promotionManager.Object; PropertyManagementSystemService.FakeAuthenticationForDebugging = true; promotionManager.Setup(p => p.CreatePromotion(It.IsAny<Promotion>())); // Act PropertyManagementSystemService.CreatePromotion(promotionDto); // Assert promotionManager.Verify(p => p.CreatePromotion(It.IsAny<Promotion>()), Times.Once); }
public PromotionDto CreatePromotion(PromotionDto promotionDto) { if (promotionDto == null) { throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30088, "PropertyManagementSystemService.CreatePromotion")); } CheckAccessRights(promotionDto.BusinessId); var promotion = Mapper.Map<Promotion>(promotionDto); promotionManager.CreatePromotion(promotion); return promotion.Id != default(int) ? Mapper.Map<Promotion, PromotionDto>(promotion) : null; }
public void ModifyPromotionIsSuccessful() { // Arrange const long BUSINESS_ID = 1; const int PROMOTION_ID = 1; var promotion = new PromotionDto { 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.ModifyPromotion(It.Is<Promotion>(i => i.Id == PROMOTION_ID))).Returns(true); // Act PropertyManagementSystemService.ModifyPromotion(promotion); // Assert promotionManager.VerifyAll(); }
public bool ModifyPromotion(PromotionDto promotionDto) { if (promotionDto == null) { throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30088, "PropertyManagementSystemService.ModifyPromotion")); } CheckAccessRights(promotionDto.BusinessId); var promotion = Mapper.Map<Promotion>(promotionDto); return promotionManager.ModifyPromotion(promotion); }