public void RemoveCompositeDiscount_composedOfComposites_Success()
        {
            LoginSessionSuccess(REGISTERED_SESSION_ID, FIRST_OPENER_USERNAME, PASSWORD);
            OpenDiscount openDiscount1 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, LONG_DURATION);
            OpenDiscount openDiscount2 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, SECOND_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, SHORT_DURATION);
            CompositeDiscount compositeDiscount = DeserializeCompositeDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, openDiscount1.discountID,
                                                                                      openDiscount2.discountID, "|");

            OpenDiscount openDiscount3 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, LONG_DURATION);
            OpenDiscount openDiscount4 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, SECOND_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, SHORT_DURATION);
            CompositeDiscount compositeDiscount2 = DeserializeCompositeDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, openDiscount3.discountID,
                                                                                       openDiscount4.discountID, "|");

            CompositeDiscount compositeDiscount3 = DeserializeCompositeDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, compositeDiscount.discountID,
                                                                                       compositeDiscount2.discountID, "|");

            Assert.True(DeserializeRemoveDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, compositeDiscount3.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, openDiscount1.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, openDiscount2.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, compositeDiscount.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, openDiscount3.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, openDiscount4.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, compositeDiscount2.discountID));
            Assert.False(marketFacade.DiscountExistsInStore(FIRST_STORE_ID, compositeDiscount3.discountID));
        }
Beispiel #2
0
        public void ADiscount_toDayDate_Success()
        {
            OpenDiscount openDiscount = new OpenDiscount(amount1price15, 0.9, DateTime.Now, MOCK_NAME_FOR_DESCRIPTION);
            Dictionary <Guid, Tuple <int, double> > outCart = openDiscount.GetUpdatedPricesFromCart(testCart);

            validateNothingButTargetItemChanged(outCart, testCart, amount1price15);
            Assert.AreEqual(testCart[amount1price15].Item1, outCart[amount1price15].Item1);
            Assert.AreEqual(testCart[amount1price15].Item2 * (1 - 0.9), outCart[amount1price15].Item2);
        }
Beispiel #3
0
        public void openDiscountSuccessRunner(Guid itemID, double discount)
        {
            OpenDiscount openDiscount = new OpenDiscount(itemID, discount, DateTime.MaxValue, MOCK_NAME_FOR_DESCRIPTION);
            Dictionary <Guid, Tuple <int, double> > outCart = openDiscount.GetUpdatedPricesFromCart(testCart);

            validateNothingButTargetItemChanged(outCart, testCart, itemID);
            Assert.AreEqual(testCart[itemID].Item1, outCart[itemID].Item1);
            Assert.AreEqual(testCart[itemID].Item2 * (1 - discount), outCart[itemID].Item2);
        }
        private void AddOpenDiscount(Guid sessionID, string ownerName, Guid storeID, Guid itemID, int duration = LONG_DURATION,
                                     double discount = HALF_OFF)
        {
            LoginSessionSuccess(sessionID, ownerName);
            OpenDiscount openDiscount = DeserializeOpenDiscountSuccess(sessionID, storeID, itemID, discount, duration);

            Assert.AreEqual(DateTime.Now.Date.AddDays(duration), openDiscount.DateUntil.Date);
            Assert.AreEqual(discount, openDiscount.Precent);
        }
        public void GetAllDiscounts_2_discounts_Success()
        {
            LoginSessionSuccess(REGISTERED_SESSION_ID, FIRST_OPENER_USERNAME, PASSWORD);
            OpenDiscount openDiscount1 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, LONG_DURATION);
            OpenDiscount openDiscount2 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, SECOND_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, SHORT_DURATION);
            string res = marketFacade.GetAllDicsounts(REGISTERED_SESSION_ID, FIRST_STORE_ID, null);

            Assert.True(MarketOperationSuccess(res));
        }
        public void AddcompositeDiscount_typeNotAllowed_failure()
        {
            LoginSessionSuccess(REGISTERED_SESSION_ID, FIRST_OPENER_USERNAME, PASSWORD);
            DeserializeMakeDiscountNotAllowedSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, "composite");

            OpenDiscount openDiscount1 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, LONG_DURATION);
            OpenDiscount openDiscount2 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, SECOND_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, 10);

            Assert.False(DeserializeCompositeDiscount(REGISTERED_SESSION_ID, FIRST_STORE_ID, openDiscount1.discountID,
                                                      openDiscount2.discountID, "&").Success);
        }
        public void CompositeDiscount_2_open_xor_none_discounted(Operator @operator)
        {
            OpenDiscount openDiscountItem1 = new OpenDiscount(amount1price15, 0.7, DateTime.MaxValue, MOCK_NAME_FOR_DESCRIPTION);
            OpenDiscount openDiscountItem3 = new OpenDiscount(amount3price10, 0.3, DateTime.MaxValue, MOCK_NAME_FOR_DESCRIPTION);

            CompositeDiscount compositeDiscount             = new CompositeDiscount(openDiscountItem1, openDiscountItem3, @operator);
            Dictionary <Guid, Tuple <int, double> > outCart = compositeDiscount.GetUpdatedPricesFromCart(testCart);

            Assert.AreEqual(15, outCart[amount1price15].Item2);
            Assert.AreEqual(10.0, outCart[amount3price10].Item2);
            Assert.AreEqual(200, outCart[amount10price200].Item2);
            Assert.AreEqual(5, outCart[amount2price5].Item2);
            validateAmountsAreSame(outCart, testCart);
        }
        public void CompositeDiscount_serealizeIdsWithoutObjects()
        {
            OpenDiscount openDiscountItem1 = new OpenDiscount(amount1price15, 0.7, DateTime.Now, MOCK_NAME_FOR_DESCRIPTION);
            OpenDiscount openDiscountItem3 = new OpenDiscount(amount3price10, 0.3, DateTime.Now, MOCK_NAME_FOR_DESCRIPTION);

            CompositeDiscount compositeDiscount = new CompositeDiscount(openDiscountItem1, openDiscountItem3, Operator.AND);

            string json = JsonConvert.SerializeObject(compositeDiscount);

            CompositeDiscount deserialized = JsonConvert.DeserializeObject <CompositeDiscount>(json);

            Assert.AreEqual(openDiscountItem1.discountID, deserialized.DiscountLeftID);
            Assert.AreEqual(openDiscountItem3.discountID, deserialized.DiscountRightID);
            Assert.Null(deserialized.DiscountLeft);
            Assert.Null(deserialized.DiscountRight);
        }
        private void AddComposite_Open_Open(Guid sessionID, string ownerName, Guid storeID, Guid itemID1, Guid itemID2, Operator op,
                                            double discount1 = HALF_OFF, int duration1 = LONG_DURATION,
                                            double discount2 = HALF_OFF, int duration2 = LONG_DURATION)
        {
            LoginSessionSuccess(sessionID, ownerName);
            OpenDiscount openDiscount1 = DeserializeOpenDiscountSuccess(sessionID, storeID, itemID1,
                                                                        discount1, duration1);
            OpenDiscount openDiscount2 = DeserializeOpenDiscountSuccess(sessionID, storeID, itemID2,
                                                                        discount2, duration2);
            CompositeDiscount compositeDiscount = DeserializeCompositeDiscountSuccess(sessionID, storeID, openDiscount1.discountID,
                                                                                      openDiscount2.discountID, op.ToString());

            int shortest = Math.Min(duration1, duration2);

            Assert.AreEqual(DateTime.Now.Date.AddDays(shortest), compositeDiscount.DateUntil.Date);
            Assert.AreEqual(openDiscount1.discountID, compositeDiscount.DiscountLeftID);
            Assert.AreEqual(openDiscount2.discountID, compositeDiscount.DiscountRightID);
            Assert.AreEqual(op, compositeDiscount.Op);
        }
        public void GetAllDiscounts_BigCompostite_forItem_Success()
        {
            LoginSessionSuccess(REGISTERED_SESSION_ID, FIRST_OPENER_USERNAME, PASSWORD);
            OpenDiscount openDiscount1 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, LONG_DURATION);
            OpenDiscount openDiscount2 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, SECOND_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, SHORT_DURATION);
            CompositeDiscount compositeDiscount = DeserializeCompositeDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, openDiscount1.discountID,
                                                                                      openDiscount2.discountID, "|");

            OpenDiscount openDiscount3 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, LONG_DURATION);
            OpenDiscount openDiscount4 = DeserializeOpenDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, SECOND_ITEM_FIRST_STORE_ID,
                                                                        HALF_OFF, SHORT_DURATION);
            CompositeDiscount compositeDiscount2 = DeserializeCompositeDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, openDiscount3.discountID,
                                                                                       openDiscount4.discountID, "|");

            CompositeDiscount compositeDiscount3 = DeserializeCompositeDiscountSuccess(REGISTERED_SESSION_ID, FIRST_STORE_ID, compositeDiscount.discountID,
                                                                                       compositeDiscount2.discountID, "|");
            string res = marketFacade.GetAllDicsounts(REGISTERED_SESSION_ID, FIRST_STORE_ID, FIRST_ITEM_FIRST_STORE_ID);

            Assert.True(MarketOperationSuccess(res));
        }