Esempio n. 1
0
        public void Promotion_ActionsFromXmlTest()
        {
            var expected = new Promotion();
            var a1       = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);

            expected.AddAction(a1);

            var xml = "<Actions>" + Environment.NewLine;

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

            var 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 (var 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);
                Assert.AreEqual(expected.Actions[i].Settings.Count, actual.Actions[i].Settings.Count,
                                "Settings Count didn't match for action index " + i);
                Assert.AreEqual(expected.Actions[i].TypeId, actual.Actions[i].TypeId,
                                "TypeId didn't match for action index " + i);
            }
        }