コード例 #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());
            }
        }
コード例 #2
0
        public void ActionsToXmlTest()
        {
            Promotion target = new Promotion();
            ProductPriceAdjustment a1 = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);
            target.AddAction(a1);

            string expected = "<Actions>" + System.Environment.NewLine;

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

            expected += "</Actions>";

            string actual;
            actual = target.ActionsToXml();
            Assert.AreEqual(expected, actual);
        }