示例#1
0
        public void Load()
        {
            UndoMgr undomgr = new UndoMgr(5);
            ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr);

            string xmlText =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<testobjects>
  <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject>
  <testobject id=""3"" x=""9"" f=""9.9"">bat</testobject>
  <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject>
</testobjects>";

            XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile");

            xmlinput.CheckElement("testobjects");
            xmlinput.Read();

            objstore.Load(xmlinput);
            xmlinput.Dispose();

            TestUtil.TestEnumerableAnyOrder(objstore.AllPairs,
                                            new KeyValuePair <Id <TestObject>, TestObject>[] {
                new KeyValuePair <Id <TestObject>, TestObject>(new Id <TestObject>(3), new TestObject(9, "bat", 9.9F)),
                new KeyValuePair <Id <TestObject>, TestObject>(new Id <TestObject>(4), new TestObject(11, "foo", 1.4F)),
                new KeyValuePair <Id <TestObject>, TestObject>(new Id <TestObject>(2), new TestObject(8, "goodbye", 9.4F))
            });
        }
示例#2
0
 public void CloseFile()
 {
     // Make sure that Dispose really closes the underlying file.
     File.Copy(TestUtil.GetTestFile("xmlinput.xml"), TestUtil.GetTestFile("temp.xml"));
     XmlInput xmlinput = new XmlInput(TestUtil.GetTestFile("temp.xml"));
     xmlinput.CheckElement("rootsym");
     xmlinput.Dispose();
     File.Delete(TestUtil.GetTestFile("temp.xml"));
 }
示例#3
0
        public void LoadModifySave()
        {
            Id <TestObject>          id;
            UndoMgr                  undomgr  = new UndoMgr(5);
            ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr);

            string xmlText =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<testobjects>
  <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject>
  <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject>
</testobjects>";

            XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile");

            xmlinput.CheckElement("testobjects");
            xmlinput.Read();

            objstore.Load(xmlinput);
            xmlinput.Dispose();

            undomgr.BeginCommand(57, "Command1");
            id = objstore.Add(new TestObject(5, "hello", 5.4F));
            Assert.AreEqual(5, id.id);
            id = objstore.Add(new TestObject(9, "bat", 9.9F));
            Assert.AreEqual(6, id.id);
            undomgr.EndCommand(57);

            undomgr.BeginCommand(58, "Command2");
            objstore.Replace(new Id <TestObject>(2), new TestObject(-9, "elvis", 9.1F));
            objstore.Remove(new Id <TestObject>(4));
            undomgr.EndCommand(58);

            TextWriter    writer    = new StringWriter();
            XmlTextWriter xmloutput = new XmlTextWriter(writer);

            xmloutput.Formatting = Formatting.Indented;
            xmloutput.Namespaces = false;

            xmloutput.WriteStartDocument();
            xmloutput.WriteStartElement("testobjects");

            objstore.Save(xmloutput);

            xmloutput.WriteEndElement();
            xmloutput.WriteEndDocument();
            xmloutput.Close();

            Assert.AreEqual(
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<testobjects>
  <testobject id=""2"" x=""-9"" f=""9.1"">elvis</testobject>
  <testobject id=""5"" x=""5"" f=""5.4"">hello</testobject>
  <testobject id=""6"" x=""9"" f=""9.9"">bat</testobject>
</testobjects>",
                writer.ToString());
        }
示例#4
0
        public void CloseFile()
        {
            // Make sure that Dispose really closes the underlying file.
            File.Copy(TestUtil.GetTestFile("xmlinput.xml"), TestUtil.GetTestFile("temp.xml"));
            XmlInput xmlinput = new XmlInput(TestUtil.GetTestFile("temp.xml"));

            xmlinput.CheckElement("rootsym");
            xmlinput.Dispose();
            File.Delete(TestUtil.GetTestFile("temp.xml"));
        }
示例#5
0
        public void LoadModifySave()
        {
            Id<TestObject> id;
            UndoMgr undomgr = new UndoMgr(5);
            ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr);

            string xmlText =
            @"<?xml version=""1.0"" encoding=""utf-16""?>
            <testobjects>
              <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject>
              <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject>
            </testobjects>";

            XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile");

            xmlinput.CheckElement("testobjects");
            xmlinput.Read();

            objstore.Load(xmlinput);
            xmlinput.Dispose();

            undomgr.BeginCommand(57, "Command1");
            id = objstore.Add(new TestObject(5, "hello", 5.4F));
            Assert.AreEqual(5, id.id);
            id = objstore.Add(new TestObject(9, "bat", 9.9F));
            Assert.AreEqual(6, id.id);
            undomgr.EndCommand(57);

            undomgr.BeginCommand(58, "Command2");
            objstore.Replace(new Id<TestObject>(2), new TestObject(-9, "elvis", 9.1F));
            objstore.Remove(new Id<TestObject>(4));
            undomgr.EndCommand(58);

            TextWriter writer = new StringWriter();
            XmlTextWriter xmloutput = new XmlTextWriter(writer);
            xmloutput.Formatting = Formatting.Indented;
            xmloutput.Namespaces = false;

            xmloutput.WriteStartDocument();
            xmloutput.WriteStartElement("testobjects");

            objstore.Save(xmloutput);

            xmloutput.WriteEndElement();
            xmloutput.WriteEndDocument();
            xmloutput.Close();

            Assert.AreEqual(
            @"<?xml version=""1.0"" encoding=""utf-16""?>
            <testobjects>
              <testobject id=""2"" x=""-9"" f=""9.1"">elvis</testobject>
              <testobject id=""5"" x=""5"" f=""5.4"">hello</testobject>
              <testobject id=""6"" x=""9"" f=""9.9"">bat</testobject>
            </testobjects>",
            writer.ToString());
        }
示例#6
0
        public void Load()
        {
            UndoMgr undomgr = new UndoMgr(5);
            ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr);

            string xmlText =
            @"<?xml version=""1.0"" encoding=""utf-16""?>
            <testobjects>
              <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject>
              <testobject id=""3"" x=""9"" f=""9.9"">bat</testobject>
              <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject>
            </testobjects>";

            XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile");

            xmlinput.CheckElement("testobjects");
            xmlinput.Read();

            objstore.Load(xmlinput);
            xmlinput.Dispose();

            TestUtil.TestEnumerableAnyOrder(objstore.AllPairs,
                                        new KeyValuePair<Id<TestObject>, TestObject>[] {
                                        new KeyValuePair<Id<TestObject>, TestObject>(new Id<TestObject>(3), new TestObject(9, "bat", 9.9F)),
                                        new KeyValuePair<Id<TestObject>, TestObject>(new Id<TestObject>(4), new TestObject(11, "foo", 1.4F)),
                                        new KeyValuePair<Id<TestObject>, TestObject>(new Id<TestObject>(2), new TestObject(8, "goodbye", 9.4F)) });
        }