Esempio n. 1
0
        public void XmlSaveAndRestore()
        {
            var random = new Random(0);
            var saveds = new DemoPayload[3];

            for (var i = 0; i < saveds.Length; i++)
            {
                saveds[i] = new DemoPayload {
                    Text = i.ToString(), Number = random.Next(100, 1000)
                };
            }

            var builder = new StringBuilder();

            for (var i = 0; i < saveds.Length; i++)
            {
                var xml = XmlFragmentHelper.EncodeXmlFragment(saveds[i]);
                builder.AppendLine(xml);
            }

            var fileContent = builder.ToString();
            var restoreds   = XmlFragmentHelper.DecodeXmlFragments <DemoPayload>(fileContent);

            Assert.IsNotNull(restoreds);
            Assert.AreEqual(saveds.Length, restoreds.Length);
            for (var i = 0; i < saveds.Length; i++)
            {
                Assert.AreEqual(saveds[i].Text, restoreds[i].Text);
                Assert.AreEqual(saveds[i].Number, restoreds[i].Number);
            }
        }
Esempio n. 2
0
        public void DeserializeManyElements()
        {
            var xml = "<DemoPayload Text=\"One\" Number=\"1\" /><DemoPayload Text=\"Two\" Number=\"2\" />";

            var obs = XmlFragmentHelper.DecodeXmlFragments <DemoPayload>(xml);

            Assert.IsNotNull(obs);
            Assert.AreEqual(2, obs.Length);
            Assert.AreEqual("One", obs[0].Text);
            Assert.AreEqual(1, obs[0].Number);
            Assert.AreEqual("Two", obs[1].Text);
            Assert.AreEqual(2, obs[1].Number);
        }