Ejemplo n.º 1
0
        public PromotionServiceTests()
        {
            _appContext = new FakeAppContext();

            SetupContent();
            SetupPricing();
            SetupMarkets();
            SetupReferenceConverter();
            SetupPromotionEngine();
            _lineItemcalculatorMock = new Mock <ILineItemCalculator>();
            SetupDiscountedPrice();

            _subject = new PromotionService(
                _pricingServiceMock.Object,
                _marketServiceMock.Object,
                _contentLoaderMock.Object,
                _referenceConverterMock.Object,
                _lineItemcalculatorMock.Object,
                _promotionEngineMock.Object
                );
        }
Ejemplo n.º 2
0
        public void QueueDeclare_WithIModel_InvokesQueueDeclareFromModel()
        {
            modelMocker.Setup(o => o.QueueDeclare(
                                  It.IsAny <string>(),
                                  It.IsAny <bool>(),
                                  It.IsAny <bool>(),
                                  It.IsAny <bool>(),
                                  It.IsAny <IDictionary <string, object> >()))
            .Returns(queueDeclareOk);
            PromotionService sut = GetSut();

            sut.QueueDeclare(modelMocker.Object);

            modelMocker.Verify(o => o.QueueDeclare(
                                   It.IsAny <string>(),
                                   It.IsAny <bool>(),
                                   It.IsAny <bool>(),
                                   It.IsAny <bool>(),
                                   It.IsAny <IDictionary <string, object> >()),
                               Times.Once);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// For now service is created each time, there are other better ways
        /// to do it like using DI or a Factory pattern etc.
        /// </summary>
        /// <returns></returns>
        private IPromotionService GetService()
        {
            var service = default(IPromotionService);

            switch (this.Type)
            {
            case PromotionType.Single:
                service = new PromotionService();
                break;

            case PromotionType.Combo:
                service = new ComboPromotionService();
                break;

            case PromotionType.Percent:
                service = new PercentPromotionService();
                break;
            }

            return(service);
        }
Ejemplo n.º 4
0
        private bool SetStarState(int promotionId, bool newState)
        {
            //Create the service
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new PromotionService(userId);

            // Get the promotion
            var detail = service.GetPromotionById(promotionId);

            // Create the PromotionEdit model instance wih the new star state
            var updatedPromotion = new PromotionEdit
            {
                PromotionId   = detail.PromotionId,
                PromotionName = detail.PromotionName,
                IsStarred     = newState,
                DateFounded   = detail.DateFounded,
                Website       = detail.Website
            };

            //Return a value indicating whether the update succeeded
            return(service.UpdatePromotion(updatedPromotion));
        }
Ejemplo n.º 5
0
        public void TestApplyingOnePromotionToBasketWithTwoDifferentItems()
        {
            List <PromotionModel> promotions = new List <PromotionModel> {
                _appleDiscount
            };
            BasketItemModel appleBasketItem  = new BasketItemModel(_apple);
            BasketItemModel orangeBasketItem = new BasketItemModel(_orange);
            BasketModel     basket           = new BasketModel();

            basket.AddOrUpdateBasket(appleBasketItem);
            basket.AddOrUpdateBasket(orangeBasketItem);
            IPromotionService promotionService = new PromotionService();

            promotionService.ApplyPromotionsToBasket(basket, promotions);
            Assert.AreEqual(2, basket.Basket.Count);
            Assert.AreEqual(3, basket.Total);
            Assert.IsTrue(basket.Basket[0].Discount != null);
            Assert.AreEqual("Apple", basket.Basket[0].ItemName);
            Assert.IsTrue(basket.Basket[1].Discount == null);
            Assert.AreEqual("Orange", basket.Basket[1].ItemName);
            Assert.AreEqual(0.5M, basket.Basket[0].Discount.TotalDiscountAmount);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        /// <param name="promotionId">The promotion id.</param>
        public void Run(AdWordsUser user, long businessId, long promotionId)
        {
            // Get the ExpressBusinessService.
            ExpressBusinessService businessService = (ExpressBusinessService)
                                                     user.GetService(AdWordsService.v201506.ExpressBusinessService);

            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201506.PromotionService);

            // Set the business ID to the service.
            promotionService.RequestHeader.expressBusinessId = businessId;

            // Update the budget for the promotion
            Promotion promotion = new Promotion();

            promotion.id = promotionId;
            Money newBudget = new Money();

            newBudget.microAmount = 2000000;
            promotion.budget      = newBudget;

            PromotionOperation operation = new PromotionOperation();

            operation.@operator = Operator.SET;
            operation.operand   = promotion;

            try {
                Promotion[] updatedPromotions = promotionService.mutate(
                    new PromotionOperation[] { operation });

                Console.WriteLine("Promotion ID {0} for business ID {1} now has budget micro " +
                                  "amount {2}.", promotionId, businessId,
                                  updatedPromotions[0].budget.microAmount);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to update promotions.", ex);
            }
        }
Ejemplo n.º 7
0
        public static IPromotion CrearConexionServicio3(Models.ConnectionType type, string connectionString)
        {
            IPromotion nuevoMotor = null;

            switch (type)
            {
            case Models.ConnectionType.NONE:
                break;

            case Models.ConnectionType.MSSQL:
                SqlConexion sql = SqlConexion.Conectar(connectionString);
                nuevoMotor = PromotionService.CrearInstanciaSQL(sql);
                break;

            case Models.ConnectionType.MYSQL:

                break;

            default:
                break;
            }

            return(nuevoMotor);
        }
Ejemplo n.º 8
0
        public JsonResult Promotions()
        {
            var items = new PromotionService().GetPromotions();

            return(Json(items, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
 public PromotionController(DiscordSocketClient client, PromotionService promotionService) : base(client)
 {
     _promotionService = promotionService;
 }
Ejemplo n.º 10
0
 public PromotionController(PromotionService promotionService)
 {
     _promotionService = promotionService;
 }
Ejemplo n.º 11
0
 public void Constructor_ShouldThrowArgumentNullException_WhenDataParameterIsNull()
 {
     // Arrange & Act & Assert
     var promotionService = new PromotionService(null);
 }
 public PromotionServiceTests()
 {
     promotionService = new PromotionService();
 }
Ejemplo n.º 13
0
        private PromotionService GetSut()
        {
            PromotionService sut = consoleServiceMocker.Object;

            return(sut);
        }
Ejemplo n.º 14
0
 protected List <BundleItem> GetBundle()
 {
     //get the bundles from the PromoService
     return(PromotionService.GetBundleByProduct(product.ProductID));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        public void Run(AdWordsUser user, long businessId)
        {
            // Get the ExpressBusinessService.
            ExpressBusinessService businessService = (ExpressBusinessService)
                                                     user.GetService(AdWordsService.v201409.ExpressBusinessService);

            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201409.PromotionService);

            // Get the business for the businessId. We will need its geo point to
            // create a Proximity criterion for the new Promotion.
            Selector businessSelector = new Selector();

            Predicate predicate = new Predicate();

            predicate.field             = "Id";
            predicate.@operator         = PredicateOperator.EQUALS;
            predicate.values            = new string[] { businessId.ToString() };
            businessSelector.predicates = new Predicate[] { predicate };

            businessSelector.fields = new string[] { "Id", "GeoPoint" };

            ExpressBusinessPage businessPage = businessService.get(businessSelector);

            if (businessPage == null || businessPage.entries == null ||
                businessPage.entries.Length == 0)
            {
                Console.WriteLine("No business was found.");
                return;
            }

            // Set the business ID to the service.
            promotionService.RequestHeader.expressBusinessId = businessId;

            // First promotion
            Promotion marsTourPromotion = new Promotion();
            Money     budget            = new Money();

            budget.microAmount                    = 1000000L;
            marsTourPromotion.name                = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
            marsTourPromotion.status              = PromotionStatus.PAUSED;
            marsTourPromotion.destinationUrl      = "http://www.example.com";
            marsTourPromotion.budget              = budget;
            marsTourPromotion.callTrackingEnabled = true;

            // Criteria

            // Criterion - Travel Agency product service
            ProductService productService = new ProductService();

            productService.text = "Travel Agency";

            // Criterion - English language
            // The ID can be found in the documentation:
            // https://developers.google.com/adwords/api/docs/appendix/languagecodes
            Language language = new Language();

            language.id = 1000L;

            // Criterion - Within 15 miles
            Proximity proximity = new Proximity();

            proximity.geoPoint            = businessPage.entries[0].geoPoint;
            proximity.radiusDistanceUnits = ProximityDistanceUnits.MILES;
            proximity.radiusInUnits       = 15;

            marsTourPromotion.criteria = new Criterion[] { productService, language, proximity };

            // Creative
            Creative creative = new Creative();

            creative.headline = "Standard Mars Trip";
            creative.line1    = "Fly coach to Mars";
            creative.line2    = "Free in-flight pretzels";

            marsTourPromotion.creatives = new Creative[] { creative };

            PromotionOperation operation = new PromotionOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = marsTourPromotion;

            try {
                Promotion[] addedPromotions = promotionService.mutate(
                    new PromotionOperation[] { operation });

                Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
                                  addedPromotions[0].id, addedPromotions[0].name, businessId);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to add promotions.", ex);
            }
        }
Ejemplo n.º 16
0
 public BranchViewModel(INavigationService navigationService)
 {
     _eventService      = new EventService();
     _promotionService  = new PromotionService();
     _navigationService = navigationService;
 }
Ejemplo n.º 17
0
 public IEnumerable <Promotion> GetPromotion(Expression <Func <Promotion, bool> > expr)
 {
     return(PromotionService.GetActive(expr));
 }
Ejemplo n.º 18
0
 public IEnumerable <Promotion> GetPromotion()
 {
     return(PromotionService.GetActive());
 }
 public DiscountPolicyController(PromotionService service)
 {
     _promotionService = service;
 }
Ejemplo n.º 20
0
 public PromotionServiceTest()
 {
     _sut = new PromotionService();
 }
Ejemplo n.º 21
0
 public PromotionController(PromotionService promServ)
 {
     this.promServ = promServ;
 }
Ejemplo n.º 22
0
        public JsonResult PromotionsByPaging(DataTablesPaging request)
        {
            var view = new PromotionService().GetPromotionsByPaging(request);

            return(Json(view, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 23
0
 public PromotionModule(PromotionService service)
 {
     _service = service;
 }
Ejemplo n.º 24
0
 public Promotion Create(Promotion p)
 {
     PromotionService.Create(p);
     return(p);
 }
Ejemplo n.º 25
0
 public Promotion GetPromotion(int pDetailId)
 {
     return(PromotionService.GetActive(p => p.PromotionID == pDetailId).FirstOrDefault());
 }
Ejemplo n.º 26
0
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     PromotionService.DeleteBundle(int.Parse(lblID.Text));
     Response.Redirect(Request.Url.PathAndQuery, false);
 }
 public PromotionCardDetailViewModel()
 {
     promotionService = new PromotionService();
 }
Ejemplo n.º 28
0
 public Promotion GetPromotion(string pCode)
 {
     return(PromotionService.GetActive(p => p.PromotionCode == pCode).FirstOrDefault());
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        public void Run(AdWordsUser user, long businessId)
        {
            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201605.PromotionService);

            // Set the business ID to the service.
            promotionService.RequestHeader.expressBusinessId = businessId;

            // First promotion
            Promotion marsTourPromotion = new Promotion();
            Money     budget            = new Money();

            budget.microAmount                    = 1000000L;
            marsTourPromotion.name                = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
            marsTourPromotion.status              = PromotionStatus.PAUSED;
            marsTourPromotion.destinationUrl      = "http://www.example.com";
            marsTourPromotion.budget              = budget;
            marsTourPromotion.callTrackingEnabled = true;

            // Criteria

            // Criterion - Travel Agency product service
            ProductService productService = new ProductService();

            productService.text = "Travel Agency";

            // Criterion - English language
            // The ID can be found in the documentation:
            // https://developers.google.com/adwords/api/docs/appendix/languagecodes
            Language language = new Language();

            language.id = 1000L;

            // Criterion - State of California
            Location location = new Location();

            location.id = 21137L;

            marsTourPromotion.criteria = new Criterion[] { productService, language, location };

            // Creative
            Creative creative = new Creative();

            creative.headline = "Standard Mars Trip";
            creative.line1    = "Fly coach to Mars";
            creative.line2    = "Free in-flight pretzels";

            marsTourPromotion.creatives = new Creative[] { creative };

            PromotionOperation operation = new PromotionOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = marsTourPromotion;

            try {
                Promotion[] addedPromotions = promotionService.mutate(
                    new PromotionOperation[] { operation });

                Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
                                  addedPromotions[0].id, addedPromotions[0].name, businessId);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add promotions.", e);
            }
        }
Ejemplo n.º 30
0
 public Promotion Update(Promotion p)
 {
     PromotionService.Update(p);
     return(p);
 }