Exemplo n.º 1
0
        public void BooleanExpressionComplexSerializeTest()
        {
            ItemFilter         filter1 = new CategoryFilter("cat");
            IBooleanExpression leaf1   = new MaxAmount(10, filter1);
            ItemFilter         filter2 = new AllProductsFilter();
            IBooleanExpression leaf2   = new UserCountry("Wakanda forever", filter2);
            IBooleanExpression complex = new XorExpression();

            leaf1.id = 1;
            leaf2.id = 2;
            complex.addChildren(leaf1, leaf2);

            string json = JsonConvert.SerializeObject(complex, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });

            IBooleanExpression result = JsonConvert.DeserializeObject <IBooleanExpression>(json, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            Assert.IsInstanceOfType(result, typeof(XorExpression));
            Assert.IsInstanceOfType(((XorExpression)result).firstChild, typeof(MaxAmount));
            Assert.IsInstanceOfType(((XorExpression)result).secondChild, typeof(UserCountry));
        }
Exemplo n.º 2
0
        public void DiscountSerializeTest()
        {
            ItemFilter         filter1 = new CategoryFilter("cat");
            IBooleanExpression leaf1   = new MaxAmount(10, filter1);
            ItemFilter         filter2 = new AllProductsFilter();
            IBooleanExpression leaf2   = new UserCountry("Wakanda forever", filter2);
            IBooleanExpression complex = new XorExpression();

            //we add manually ids for the leaves becuase there is no stub for them at the moment.
            //Not adding these ids will cause the json serializer to falsly think it has a loop (parent and children have the same id -> .Equals() = true)
            leaf2.id = 10;
            leaf1.id = 11;
            complex.addChildren(leaf1, leaf2);

            //TODO: when there are concrete Outcomes, we can test this
            //IOutcome outcome = new
            //Discount discount = new Discount(complex,)



            string json = JsonConvert.SerializeObject(complex, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });

            IBooleanExpression result = JsonConvert.DeserializeObject <IBooleanExpression>(json, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            Assert.IsInstanceOfType(result, typeof(XorExpression));
            Assert.IsInstanceOfType(((XorExpression)result).firstChild, typeof(MaxAmount));
            Assert.IsInstanceOfType(((XorExpression)result).secondChild, typeof(UserCountry));
        }
Exemplo n.º 3
0
        void TextBox_TextChanged(object sender, EventArgs e)
        {
            if (uint.TryParse(InputTextBox.Text, out Amount) && Amount >= MinAmount)
            {
                InputTextBox.BorderColour = Color.Lime;

                OKButton.Visible = true;
                if (Amount > MaxAmount)
                {
                    Amount            = MaxAmount;
                    InputTextBox.Text = MaxAmount.ToString();
                    InputTextBox.TextBox.SelectionStart = InputTextBox.Text.Length;
                }

                if (Amount == MaxAmount)
                {
                    InputTextBox.BorderColour = Color.Orange;
                }
            }
            else
            {
                InputTextBox.BorderColour = Color.Red;
                OKButton.Visible          = false;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds HTML attributes and styles that need to be rendered.
        /// </summary>
        /// <param name="writer">
        /// A System.Web.UI.HtmlTextWriter that represents the output stream to render
        /// HTML content on the client
        /// </param>
        /// <remarks>
        /// The method overrides the base class to add the attributes necessary to
        /// render the control as as text input.
        /// </remarks>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            // Add attributes necessary to display an text control
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
            writer.AddStyleAttribute("text-align", Alignment.ToString());
            // Add user defined attributes to control colour formatting
            writer.AddAttribute("negativeColor", NegativeColor.Name);


            if (PositiveColor != Color.Empty)
            {
                writer.AddAttribute("positiveColor", PositiveColor.Name);
            }
            // Add user defined attributes to control minimum and maximum values
            writer.AddAttribute("minAmount", MinAmount.ToString());
            writer.AddAttribute("maxAmount", MaxAmount.ToString());
            // Add client side event handlers
            string onKeyPress = "EnsureNumeric()";

            if (OnKeyPress != string.Empty)
            {
                onKeyPress += "," + OnKeyPress;
            }
            writer.AddAttribute("onkeypress", onKeyPress);
        }
        public void MaxAmountevaluateTest()
        {
            MaxAmount max = new MaxAmount(5, filter);

            Assert.IsFalse(max.evaluate(list, user));

            max = new MaxAmount(15, filter);
            Assert.IsTrue(max.evaluate(list, user));
        }
Exemplo n.º 6
0
        public void BooleanExpressionLeafSerializeTest()
        {
            ItemFilter         filter = new CategoryFilter("cat");
            IBooleanExpression leaf   = new MaxAmount(10, filter);

            string json = JsonConvert.SerializeObject(leaf, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });

            IBooleanExpression result = JsonConvert.DeserializeObject <IBooleanExpression>(json, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            Assert.IsInstanceOfType(result, typeof(MaxAmount));
            Assert.AreEqual(((MaxAmount)result).amount, 10);
        }
Exemplo n.º 7
0
        public void checkConsistency()
        {
            int            min = 10, max = 5;
            TrueCondition  trueCondition  = new TrueCondition();
            FalseCondition falseCondition = new FalseCondition();

            Assert.IsFalse(trueCondition.checkConsistent(falseCondition), "1");
            Assert.IsFalse(falseCondition.checkConsistent(trueCondition), "2");

            MinAmount minAmount = new MinAmount(min, new AllProductsFilter());
            MaxAmount maxAmount = new MaxAmount(max, new AllProductsFilter());

            Assert.IsFalse(minAmount.checkConsistent(maxAmount), "3");
            Assert.IsFalse(maxAmount.checkConsistent(minAmount), "4");

            List <IBooleanExpression> list = new List <IBooleanExpression>();

            list.Add(trueCondition);
            list.Add(minAmount);

            Assert.IsFalse(IBooleanExpression.confirmListConsist(falseCondition, list));
            Assert.IsFalse(IBooleanExpression.confirmListConsist(maxAmount, list));

            List <int> list1 = new List <int>();

            list1.Add(1);
            List <int> list2 = new List <int>();

            list2.Add(2);
            ProductListFilter f1         = new ProductListFilter(list1);
            ProductListFilter f2         = new ProductListFilter(list2);
            MinAmount         minAmount2 = new MinAmount(min, f1);
            MaxAmount         maxAmount2 = new MaxAmount(max, f2);

            Assert.IsFalse(maxAmount.checkConsistent(minAmount2));
            Assert.IsTrue(maxAmount2.checkConsistent(minAmount2));
            f2.productIds = list1;
            Assert.IsFalse(maxAmount2.checkConsistent(minAmount2));

            minAmount.amount = max;
            maxAmount.amount = min;
            Assert.IsTrue(minAmount.checkConsistent(maxAmount), "5");
        }