Ejemplo n.º 1
0
        public void ActionsFromXmlTest()
        {
            Promotion expected = new Promotion();
            ProductPriceAdjustment a1 = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);
            expected.AddAction(a1);

            string xml = "<Actions>" + System.Environment.NewLine;
            xml += "  <Action>" + System.Environment.NewLine;
            xml += "    <Id>" + a1.Id.ToString() + "</Id>" + System.Environment.NewLine;
            xml += "    <TypeId>" + a1.TypeId + "</TypeId>" + System.Environment.NewLine;
            xml += "    <Settings>" + System.Environment.NewLine;
            xml += "      <Setting>" + System.Environment.NewLine;
            xml += "        <Key>AdjustmentType</Key>" + System.Environment.NewLine;
            xml += "        <Value>1</Value>" + System.Environment.NewLine;
            xml += "      </Setting>" + System.Environment.NewLine;
            xml += "      <Setting>" + System.Environment.NewLine;
            xml += "        <Key>Amount</Key>" + System.Environment.NewLine;
            xml += "        <Value>1.23</Value>" + System.Environment.NewLine;
            xml += "      </Setting>" + System.Environment.NewLine;
            xml += "    </Settings>" + System.Environment.NewLine;
            xml += "  </Action>" + System.Environment.NewLine;
            xml += "</Actions>";

            Promotion actual = new Promotion();
            actual.ActionsFromXml(xml);

            Assert.AreEqual(expected.Actions.Count, actual.Actions.Count, "Actions count did not match");
            Assert.AreEqual(a1.Amount, ((ProductPriceAdjustment)actual.Actions[0]).Amount, "Amount didn't come through");
            Assert.AreEqual(a1.AdjustmentType, ((ProductPriceAdjustment)actual.Actions[0]).AdjustmentType, "Adjustment Type didn't come through");
            for (int i = 0; i < expected.Actions.Count; i++)
            {
                Assert.AreEqual(expected.Actions[i].Id, actual.Actions[i].Id, "Id didn't match for action index " + i.ToString());
                Assert.AreEqual(expected.Actions[i].Settings.Count, actual.Actions[i].Settings.Count, "Settings Count didn't match for action index " + i.ToString());
                Assert.AreEqual(expected.Actions[i].TypeId, actual.Actions[i].TypeId, "TypeId didn't match for action index " + i.ToString());
            }
        }