public static bool HasQualifyingItemGiftProductPromotion(IRuleContext ruleContext) { bool isQualifyingItemGiftProductPromotion = false; PromotionController promotionController = CreatePromotionController(); foreach (PromotionsData.PromotionUsage promotionUsage in PromotionsData.DataContextProvider.Current.PromotionUsages.Where(pu => pu.CustomerId == ruleContext.CustomerId && pu.Complete == false)) { PromotionsData.Promotion promotion = PromotionsData.DataContextProvider.Current.Promotions.FirstOrDefault(p => p.Id == promotionUsage.PromotionId); ruleContext.PromotionId = promotion.Id; if (promotionController.ValidatePromotion(promotion, ruleContext, AppLogic.CustomerLevelAllowsCoupons(ruleContext.CustomerLevel)).All(vr => vr.IsValid)) { foreach (PromotionDiscountBase pd in promotion.PromotionDiscounts.Where(p => p.GetType() == typeof(GiftProductPromotionDiscount))) { CategoryPromotionRule categories = new CategoryPromotionRule(); SectionPromotionRule sections = new SectionPromotionRule(); ManufacturerPromotionRule manufacturers = new ManufacturerPromotionRule(); ProductIdPromotionRule productids = new ProductIdPromotionRule(); if (promotion.PromotionRules.Where(pr => (pr.GetType() == typeof(CategoryPromotionRule)) || (pr.GetType() == typeof(SectionPromotionRule)) || (pr.GetType() == typeof(ManufacturerPromotionRule)) || (pr.GetType() == typeof(ProductIdPromotionRule))).Count() > 0) { isQualifyingItemGiftProductPromotion = true; } } } } return(isQualifyingItemGiftProductPromotion); }
public async Task CancelPromotionAsync_ShouldBeNotFoundObjectResult() { // Arrange TestMock.PromotionService .Setup( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>())) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper) { ControllerContext = { HttpContext = MockHttpContextAccessor.GetInstance() } }; // Act var result = await controller.CancelPromotionAsync(TestCode); // Assert result.Should().BeOfType <NotFoundObjectResult>(); TestMock.PromotionService.Verify( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>()), Times.Once); }
public void ScenarioB() { PromotionController promotionController = new PromotionController(); PromotionRequestModel request = new PromotionRequestModel(); PromotionResponseModel response = new PromotionResponseModel(); request.PromotionId = 1; request.CartItems.Add( new CartItemModel { ItemName = "A", ItemQty = 5 }); request.CartItems.Add(new CartItemModel { ItemName = "B", ItemQty = 5 }); request.CartItems.Add(new CartItemModel { ItemName = "C", ItemQty = 1 }); response = promotionController.ApplyPromotion(request); Assert.AreEqual(370, response.TotalCost); }
private void searchPromotion() { var result = PromotionController.SearchPromotion(null, txtTitle.Text); rptPromotions.DataSource = result; rptPromotions.DataBind(); }
private void bindPromotionList() { var result = PromotionController.SearchPromotion(null, null); rptPromotions.DataSource = result; rptPromotions.DataBind(); }
public static IList <PromotionsData.Promotion> GetLoyaltyPromotions(int customerId, IRuleContext ruleContext) { IList <PromotionsData.Promotion> autoAssignPromotions = new List <PromotionsData.Promotion>(); PromotionController promotionController = CreatePromotionController(); if (!AppLogic.AppConfigExists("AspDotNetStorefront.Promotions.excludestates")) { AppLogic.AddAppConfig("AspDotNetStorefront.Promotions.excludestates", "states to be excluded from shipping promotions", String.Empty, "", true); } string excludeConfig = AppLogic.AppConfig("AspDotNetStorefront.Promotions.excludestates"); if (excludeConfig.Length > 0) { ruleContext.ExcludeStates = excludeConfig.Split(','); } IList <PromotionsData.Promotion> loyaltyPromotions = new List <PromotionsData.Promotion>(); foreach (PromotionsData.Promotion promotion in PromotionsData.DataContextProvider.Current.Promotions.Where(p => p.Active)) { if (promotion.PromotionRules.Where(p => p.GetType() == typeof(MinimumOrderAmountPromotionRule) || p.GetType() == typeof(MinimumOrdersPromotionRule) || p.GetType() == typeof(MinimumProductAmountOrderedPromotionRule) || p.GetType() == typeof(MinimumProductsOrderedPromotionRule)).Any()) { ruleContext.PromotionId = promotion.Id; if (promotionController.ValidateLoyaltyPromotion(promotion, ruleContext)) { loyaltyPromotions.Add(promotion); } } } return(loyaltyPromotions); }
public static PromotionController CreatePromotionController() { var promotionController = new PromotionController(); promotionController.OnLookupData += new PromotionController.LookupDataDelegate(PromotionController_OnLookupData); return(promotionController); }
public void Initializate(PromotionController pc, char c, Sprite s) { image = GetComponent <Image>(); promotionController = pc; pieceChar = c; image.sprite = s; }
private void loadPromotions(string searchString, DateTime?start, DateTime?finish, sbyte?status) { if (promotionController == null) { promotionController = new PromotionController(); } tblPro.DataSource = promotionController.Gets(searchString, start, finish, status).ToList(); }
public void AddMemberPromotion_Positive(MemberModel member, string promotionCode) { MemberController memController = new MemberController(Database, TestStep); PromotionController promoController = new PromotionController(Database, TestStep); try { TestStep.Start("Adding Member unique LoyaltyIds for each virtual card", "Unique LoyaltyIds should be assigned"); member = memController.AssignUniqueLIDs(member); TestStep.Pass("Unique LoyaltyIds assigned", member.VirtualCards.ReportDetail()); string loyaltyID = member.VirtualCards[0].LOYALTYIDNUMBER; TestStep.Start($"Make AddMember Call", $"Member with LID {loyaltyID} should be added successfully and member object should be returned"); MemberModel memberOut = memController.AddMember(member); AssertModels.AreEqualOnly(member, memberOut, MemberModel.BaseVerify); TestStep.Pass("Member was added successfully and member object was returned", memberOut.ReportDetail()); TestStep.Start($"Find promotion in database", "Promotion should be found"); IEnumerable <PromotionModel> promos = promoController.GetFromDB(code: promotionCode); Assert.NotNull(promos, "Expected Promotion.GetFromDB to return IEnumerable<Promotion> object"); Assert.IsTrue(promos.Any(x => x.CODE.Equals(promotionCode)), "Expected promotion code was not found in database"); TestStep.Pass("Promotion was found", promos.ReportDetail()); TestStep.Start($"Make AddMemberPromotion Call", "AddMemberPromotion call should return MemberPromotion object"); MemberPromotionModel memberPromoOut = memController.AddMemberPromotion(loyaltyID, promotionCode, null, null, false, null, null, false); Assert.IsNotNull(memberPromoOut, "Expected populated MemberPromotion object, but MemberPromotion object returned was null"); TestStep.Pass("MemberPromotion object was returned", memberPromoOut.ReportDetail()); TestStep.Start($"Verify member promotion exists in {MemberPromotionModel.TableName}", $"Member promotion should be in {MemberPromotionModel.TableName}"); IEnumerable <MemberPromotionModel> dbMemberPromo = memController.GetMemberPromotionsFromDB(memberPromoOut.ID, promotionCode, memberOut.IPCODE); Assert.IsNotNull(dbMemberPromo, "Expected populated MemberPromotion object from database query, but MemberPromotion object returned was null"); Assert.Greater(dbMemberPromo.Count(), 0, "Expected at least one MemberPromotion to be returned from query"); AssertModels.AreEqualOnly(memberPromoOut, dbMemberPromo.First(), MemberPromotionModel.BaseVerify); TestStep.Pass("MemberPromotion object exists in table", dbMemberPromo.ReportDetail()); } catch (AssertionException ex) { TestStep.Fail(ex.Message); Assert.Fail(); } catch (LWServiceException ex) { TestStep.Fail(ex.Message, new[] { $"Error Code: {ex.ErrorCode}", $"Error Message: {ex.ErrorMessage}" }); Assert.Fail(); } catch (AssertModelEqualityException ex) { TestStep.Fail(ex.Message, ex.ComparisonFailures); Assert.Fail(); } catch (Exception ex) { TestStep.Abort(ex.Message); Assert.Fail(); } }
protected void Page_Load(object sender, EventArgs e) { List <Promotion> x = PromotionController.getAll(); lblTitle.Text = x.Last().Title; lblDesc.Text = x.Last().Description; lblDiscount.Text = x.Last().Discount.ToString(); }
private void addPromotion() { PromotionInfo promotion = new PromotionInfo(); promotion.promotion_code = txtPromotionCode.Text; promotion.promotion_type = int.Parse(ddlPromotonType.SelectedValue); float percent; float.TryParse(txtDiscountPercent.Text, out percent); promotion.discount_percent = percent; float value; float.TryParse(txtDiscountValue.Text, out value); promotion.discount_value = value; promotion.free_product_id = txtFreeProductId.Text; int free; int.TryParse(txtFreeAmount.Text, out free); float completePrice; float.TryParse(txtCompletePrice.Text, out completePrice); promotion.complete_price = completePrice; promotion.free_amount = free; promotion.title = txtTitle.Text; promotion.description = txtDesciption.Text; if (fileImage.HasFile) { var current = fileImage.PostedFile; string exttension = System.IO.Path.GetExtension(current.FileName); string newNameImage = Guid.NewGuid().ToString(); current.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), newNameImage + exttension)); listofuploadedfiles.Text += String.Format("{0}<br />", newNameImage + exttension); promotion.image = newNameImage + exttension; } promotion.create_by = (SessionApp.user_info == null) ? "No Login" : SessionApp.user_info.user_name; promotion.lastupdate_by = (SessionApp.user_info == null) ? "No Login" : SessionApp.user_info.user_name; var result = PromotionController.AddPromotion(promotion); if (result == null) { ShowMessage(Page, "เพิ่มผิดพลาด"); } else { ShowMessage(Page, "เพิ่มสำเร็จ"); } }
public void ScenerioA() { var controller = new PromotionController(); var cart = controller.AddtoCart('A'); controller.UpdateCart('B', cart); controller.UpdateCart('C', cart); var results = controller.GetCart(cart); Assert.IsTrue(results.TotalCartPrice == 100); }
public void init() { //Arrange string ip = "192.168.16.98"; int port = 1074; string logfile = "test.log"; var rep = new ECAPIManagerRepository(ip, port, logfile); controller = new PromotionController(rep); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); }
private void load() { dtgvPro.DataSource = tblPro; dtgvDetail.DataSource = tblDetail; if (promotionController == null) { promotionController = new PromotionController(); } promotionController.UpdateStatusByTimeNow(); loadPromotions(null, null, null, null); addBinding(); }
public async Task FetchPromotionsAsync_ShouldBeNoContentResult() { // Arrange TestMock.PromotionService.Setup(promotionService => promotionService.FetchPromotionsAsync()).ReturnsAsync(new List <Promotion>()).Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); // Act var result = await controller.FetchPromotionsAsync(); // Assert result.Should().BeOfType <NoContentResult>(); TestMock.PromotionService.Verify(promotionService => promotionService.FetchPromotionsAsync(), Times.Once); }
public async Task FetchPromotionsAsync_ShouldBeOkObjectResult() { // Arrange TestMock.PromotionService.Setup(promotionService => promotionService.FetchPromotionsAsync()).ReturnsAsync(GeneratePromotions()).Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); // Act var result = await controller.FetchPromotionsAsync(); // Assert result.Should().BeOfType <OkObjectResult>(); result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto[]>(GeneratePromotions())); TestMock.PromotionService.Verify(promotionService => promotionService.FetchPromotionsAsync(), Times.Once); }
public static IDiscountResult GetPromotionDiscount(IRuleContext ruleContext, out IList <IDiscountResult> discountResults) { PromotionController promotionController = CreatePromotionController(); discountResults = new List <IDiscountResult>(); IQueryable <PromotionsData.PromotionUsage> promotionUsages = GetPromotionUsagesByCustomer(ruleContext.CustomerId).Where(p => p.Complete == false); Dictionary <IPromotionUsage, IPromotionDiscount> AllPromotionDiscounts = new Dictionary <IPromotionUsage, IPromotionDiscount>(); //Need to loop all promos and all discount types in those promos so we can build up a list of all the discounts on this order foreach (PromotionsData.PromotionUsage promotionUsage in promotionUsages) { foreach (IPromotionDiscount promoDiscount in promotionUsage.Promotion.PromotionDiscounts) { //We need to add only one item per promo usage but we want to order by the non-shipping option when it has shipping plus another discount type on one promo //this only works becuase we restrict promos to shipping plus one other type of discount. if (promotionUsage.Promotion.PromotionDiscounts.Count == 1 || promoDiscount.SequenceNumber != (int)PromotionDiscountBase.PromotionSequence.Shipping) { AllPromotionDiscounts.Add(promotionUsage, promoDiscount); } } } //Sort the discounts, this is incase we need to deal with line item -vs- order level coupon priority var sortedPromotionDiscounts = AllPromotionDiscounts.ToArray().OrderBy(apd => apd.Key.Id).OrderBy(apd => apd.Value.SequenceNumber); var discountContext = CreateDiscountContext(ruleContext); foreach (KeyValuePair <IPromotionUsage, IPromotionDiscount> discountPair in sortedPromotionDiscounts) { var promotionRuleContext = CreateRuleContext(ruleContext, discountPair.Key.PromotionId); List <DiscountableItem> discountableItems = GetDiscountableItems(promotionRuleContext, discountPair.Key.PromotionId); var promotionDiscountContext = CreateDiscountContext(discountContext, discountableItems); IDiscountResult discountResult = promotionController.ApplyPromotion(discountPair.Key, promotionRuleContext, promotionDiscountContext, () => new SimpleDiscountResult(), CreatePromotionController(), AppLogic.CustomerLevelAllowsCoupons(ruleContext.CustomerLevel)); if (discountResult != null) { discountResults.Add(discountResult); } } return(promotionController.CombineDiscounts(discountResults, delegate() { return new SimpleDiscountResult(); })); }
public void ItemsCanBeLookedUp() { var controller = new PromotionController(b); var theshowing = new Promotion { Expiration = DateTime.Now, PromotionCode = "", PromoType = Promotion.PromotionType.FlatRate, PromotionName = "5 off", PromoValue = 5 }; var showing = controller.Add(theshowing); var retrieved = controller.Get(showing); //retrieved.ShouldEqual(theshowing); // TODO: Need object comparison sans Id }
public async Task CancelPromotionAsync_ShouldBeOkObjectResult() { // Arrange var promotion = GeneratePromotion(); TestMock.PromotionService .Setup( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>())) .ReturnsAsync(promotion) .Verifiable(); TestMock.PromotionService .Setup( promotionService => promotionService.CancelPromotionAsync( It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>())) .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(promotion)) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper) { ControllerContext = { HttpContext = MockHttpContextAccessor.GetInstance() } }; // Act var result = await controller.CancelPromotionAsync(TestCode); // Assert result.Should().BeOfType <OkObjectResult>(); result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(promotion)); TestMock.PromotionService.Verify( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>()), Times.Once); TestMock.PromotionService.Verify( promotionService => promotionService.CancelPromotionAsync( It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>()), Times.Once); }
public async Task RedeemPromotionAsync_ShouldBeBadRequestObjectResult() { // Arrange var promotion = GeneratePromotion(); TestMock.PromotionService .Setup( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>())) .ReturnsAsync(promotion) .Verifiable(); TestMock.PromotionService .Setup( promotionService => promotionService.RedeemPromotionAsync( It.IsAny <Promotion>(), It.IsAny <UserId>(), It.IsAny <IDateTimeProvider>())) .ReturnsAsync(DomainValidationResult <Promotion> .Failure("error message")) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper) { ControllerContext = { HttpContext = MockHttpContextAccessor.GetInstance() } }; // Act var result = await controller.RedeemPromotionAsync(TestCode); // Assert result.Should().BeOfType <BadRequestObjectResult>(); TestMock.PromotionService.Verify( promotionService => promotionService.FindPromotionOrNullAsync( It.IsAny <string>()), Times.Once); TestMock.PromotionService.Verify( promotionService => promotionService.RedeemPromotionAsync( It.IsAny <Promotion>(), It.IsAny <UserId>(), It.IsAny <IDateTimeProvider>()), Times.Once); }
public async Task CreatePromotionAsync_ShouldBeOkObjectResult() { // Arrange TestMock.PromotionService .Setup( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>())) .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(GeneratePromotion())) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); var request = new CreatePromotionRequest { Currency = new CurrencyDto { Amount = 50, Type = EnumCurrencyType.Money }, Duration = new Duration(), ExpiredAt = DateTime.UtcNow.ToTimestamp(), PromotionalCode = TestCode }; // Act var result = await controller.CreatePromotionAsync(request); // Assert result.Should().BeOfType <OkObjectResult>(); result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(GeneratePromotion())); TestMock.PromotionService.Verify( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>()), Times.Once); }
public PromotionsModule(OrmLiteConnectionFactory db) : base("/promotions") { const string obj = "Promotion"; // Would like to totally DRY this class out, but things get a little clunky // without careful planning. Not worthwhile for such a small project. Get["/"] = _ => { var controller = new PromotionController(db); return(View[obj + "List", controller.ListAll()]); }; Get["/{id}"] = req => { var controller = new PromotionController(db); var item = controller.Get(req.id); if (item == null) { return(404); } return(View[obj + "Detail", item]); }; Get["/create"] = _ => { return(View["New" + obj]); }; Post["/create"] = _ => { var item = this.Bind <Promotion>(); LogTo.Debug("Adding promotion: {0}", item); var controller = new PromotionController(db); var newId = controller.Add(item); return(Response.AsRedirect(ModulePath + "/" + newId)); }; Post["/update/{id}"] = _ => { return(500); }; }
public async Task CreatePromotionAsync_ShouldBeBadRequestObjectResult() { // Arrange TestMock.PromotionService .Setup( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>())) .ReturnsAsync(DomainValidationResult <Promotion> .Failure("error message")) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); var request = new CreatePromotionRequest { Currency = new CurrencyDto { Amount = 50, Type = EnumCurrencyType.Money }, Duration = new Duration(), ExpiredAt = DateTime.UtcNow.ToTimestamp(), PromotionalCode = "code1" }; // Act var result = await controller.CreatePromotionAsync(request); // Assert result.Should().BeOfType <BadRequestObjectResult>(); TestMock.PromotionService.Verify( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>()), Times.Once); }
public PromotionsModule(OrmLiteConnectionFactory db) : base("/promotions") { const string obj = "Promotion"; // Would like to totally DRY this class out, but things get a little clunky // without careful planning. Not worthwhile for such a small project. Get["/"] = _ => { var controller = new PromotionController(db); return View[obj + "List", controller.ListAll()]; }; Get["/{id}"] = req => { var controller = new PromotionController(db); var item = controller.Get(req.id); if (item == null) return 404; return View[obj + "Detail", item]; }; Get["/create"] = _ => { return View["New" + obj]; }; Post["/create"] = _ => { var item = this.Bind<Promotion>(); LogTo.Debug("Adding promotion: {0}", item); var controller = new PromotionController(db); var newId = controller.Add(item); return Response.AsRedirect(ModulePath + "/" + newId); }; Post["/update/{id}"] = _ => { return 500; }; }
public void GetTotalOrderBySenarioC() { //Senario C List <UnitPrice> unitPrices = new List <UnitPrice>(); UnitPrice unitPriceA = new UnitPrice(); unitPriceA.STUId = "A"; unitPriceA.Value = 50; unitPriceA.UnitQty = 5; unitPrices.Add(unitPriceA); UnitPrice unitPriceB = new UnitPrice(); unitPriceB.STUId = "B"; unitPriceB.Value = 30; unitPriceB.UnitQty = 5; unitPrices.Add(unitPriceB); UnitPrice unitPriceC = new UnitPrice(); unitPriceC.STUId = "C"; unitPriceC.Value = 20; unitPriceC.UnitQty = 1; unitPrices.Add(unitPriceC); IPromotionRepository promotionRepository = new PromotionRepository(); var controller = new PromotionController(promotionRepository); var result = controller.CalCulateOrderAmount(unitPrices) as ViewResult; var data = result.Model as OrderSummary; Assert.AreEqual(370, data.Total, "Total Order Value not correct"); }
private void bindPromotion() { var result = PromotionController.GetPromotion(promotion_id); if (result.Count > 0) { var current = result[0]; if (current != null) { txtPromotionCode.Text = current.promotion_code; ddlPromotonType.SelectedValue = current.promotion_type.ToString(); txtDiscountPercent.Text = current.discount_percent.ToString(); txtDiscountValue.Text = current.discount_value.ToString(); txtFreeProductId.Text = current.free_product_id; txtFreeAmount.Text = current.free_amount.ToString(); txtTitle.Text = current.title; txtDesciption.Text = current.description; imgPromotion.ImageUrl = getImage(current.image); imgName.Value = current.image; txtCompletePrice.Text = current.complete_price.ToString(); } } }
public static IList <PromotionsData.Promotion> AutoAssignPromotions(int customerId, IRuleContext ruleContext) { IList <PromotionsData.Promotion> autoAssignPromotions = new List <PromotionsData.Promotion>(); if (ruleContext.CartType != null && ruleContext.CartType != (Int32)CartTypeEnum.ShoppingCart) { return(autoAssignPromotions); } PromotionController promotionController = CreatePromotionController(); if (!AppLogic.AppConfigExists("AspDotNetStorefront.Promotions.excludestates")) { AppLogic.AddAppConfig("AspDotNetStorefront.Promotions.excludestates", "states to be excluded from shipping promotions", String.Empty, "", true); } string excludeConfig = AppLogic.AppConfig("AspDotNetStorefront.Promotions.excludestates"); if (excludeConfig.Length > 0) { ruleContext.ExcludeStates = excludeConfig.Split(','); } var promosToAssign = PromotionsData.DataContextProvider.Current.Promotions.Where(p => p.Active && p.AutoAssigned && !PromotionManager.GetRemovedAutoAssignPromotionIdList(customerId).Contains(p.Id)); foreach (PromotionsData.Promotion promotion in promosToAssign) { ruleContext.PromotionId = promotion.Id; if (promotionController.ValidatePromotion(promotion, ruleContext, AppLogic.CustomerLevelAllowsCoupons(ruleContext.CustomerLevel)).All(vr => vr.IsValid)) { AssignPromotion(customerId, promotion.Id); autoAssignPromotions.Add(promotion); } } return(autoAssignPromotions); }
protected void rptPromotions_ItemCommand(object source, RepeaterCommandEventArgs e) { try { string promotion_id = (string)e.CommandArgument; switch (e.CommandName) { case "EDIT": RedirectTo("~/Backend/Promotion/PromotionEdit.aspx" + "?promotion_id=" + promotion_id); break; case "DEL": PromotionController.DelPromotion(promotion_id, true); break; default: break; } bindPromotionList(); } catch (Exception exc) { } }
public async Task Get_PromotionProduct_Items_ByPromotionId_Success() { //Arrange var pageSize = 2; var pageIndex = 0; var promotionId = 1; var promotionContext = new PromotionContext(_dbOptions); var promotionServiceMock = new Mock <IPromotionService>(); var loggerMock = new Mock <ILogger <PromotionController> >(); var mapperMock = new Mock <IMapper>(); //Act var promotionController = new PromotionController(promotionContext, loggerMock.Object, promotionServiceMock.Object, mapperMock.Object); var actionResult = await promotionController.ItemsByPromotionIdAsync(promotionId, pageSize, pageIndex); //Assert Assert.IsType <ActionResult <PaginatedItemsViewModel <PromotionProduct> > >(actionResult); var page = Assert.IsAssignableFrom <PaginatedItemsViewModel <PromotionProduct> >(actionResult.Value); Assert.Equal(pageIndex, page.PageIndex); Assert.Equal(pageSize, page.PageSize); }
public void AddMemberPromotion_Negative(string loyaltyId, string promoCode, int errorCode, string errorMessage) { MemberController memController = new MemberController(Database, TestStep); PromotionController promoController = new PromotionController(Database, TestStep); try { if (!string.IsNullOrEmpty(promoCode) && promoCode.Equals("0000")) { TestStep.Start("Adding Member unique LoyaltyIds for each virtual card", "Unique LoyaltyIds should be assigned"); MemberModel createMember = MemberController.GenerateRandomMember(HertzLoyalty.GoldPointsRewards.RegularGold); createMember = memController.AssignUniqueLIDs(createMember); TestStep.Pass("Unique LoyaltyIds assigned", createMember.VirtualCards.ReportDetail()); loyaltyId = createMember.VirtualCards[0].LOYALTYIDNUMBER; TestStep.Start($"Make AddMember Call", $"Member with LID {loyaltyId} should be added successfully and member object should be returned"); MemberModel memberOut = memController.AddMember(createMember); AssertModels.AreEqualOnly(createMember, memberOut, MemberModel.BaseVerify); TestStep.Pass("Member was added successfully and member object was returned", memberOut.ReportDetail()); loyaltyId = memberOut.VirtualCards.First().LOYALTYIDNUMBER; } else if (promoCode == string.Empty) { TestStep.Start("Get Expired promotion from DB", "Expired promo found in DB"); IEnumerable <PromotionModel> promoOutDb = promoController.GetRandomExpiredPromotionFromDB(); Assert.Greater(promoOutDb.Count(), 0, "Expected one or more expired promotions from DB"); TestStep.Pass("Expired promotion found in DB", promoOutDb.ReportDetail()); promoCode = promoOutDb.First().CODE; errorMessage = $"Promotion {promoCode} is not valid anymore"; TestStep.Start("Adding Member unique LoyaltyIds for each virtual card", "Unique LoyaltyIds should be assigned"); MemberModel createMember = MemberController.GenerateRandomMember(HertzLoyalty.GoldPointsRewards.RegularGold); createMember = memController.AssignUniqueLIDs(createMember); TestStep.Pass("Unique LoyaltyIds assigned", createMember.VirtualCards.ReportDetail()); loyaltyId = createMember.VirtualCards[0].LOYALTYIDNUMBER; TestStep.Start($"Make AddMember Call", $"Member with LID {loyaltyId} should be added successfully and member object should be returned"); MemberModel memberOut = memController.AddMember(createMember); AssertModels.AreEqualOnly(createMember, memberOut, MemberModel.BaseVerify); TestStep.Pass("Member was added successfully and member object was returned", memberOut.ReportDetail()); } TestStep.Start("Make AddMemberPromotion Call", $"AddMemberPromotion call should throw exception with error code = {errorCode}"); LWServiceException exception = Assert.Throws <LWServiceException>(() => memController.AddMemberPromotion(loyaltyId, promoCode, null, null, null, null, null, null), "Expected LWServiceException, exception was not thrown."); Assert.AreEqual(errorCode, exception.ErrorCode, $"Expected Error Code: {errorCode}"); Assert.IsTrue(exception.Message.Contains(errorMessage), $"Expected Error Message to contain: {errorMessage}"); TestStep.Pass("AddMemberPromotion call threw expected exception", exception.ReportDetail()); } catch (AssertionException ex) { TestStep.Fail(ex.Message); Assert.Fail(); } catch (AssertModelEqualityException ex) { TestStep.Fail(ex.Message, ex.ComparisonFailures); Assert.Fail(); } catch (Exception ex) { TestStep.Abort(ex.Message); Assert.Fail(); } }