Exemplo n.º 1
0
        public void XmlFileSavesClass()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var orig = TestResourceFactory.CreateRandom().WithId(1234) as MockClassC;

            using (var repo = new XmlFileManager<MockClassC>())
            {
                repo.WorkingPath = "";
                repo.SaveToFile(orig, _testName + ".xml", ".");
            }

            using (var repo = new XmlFileManager<MockClassC>())
            {
                var item = repo.LoadFromFile(_testName + ".xml");

                Assert.AreEqual(item.Id, orig.Id);
                Assert.AreEqual(item.Name, orig.Name);
                Assert.AreEqual(item.GetSomeCheckSum[0], orig.GetSomeCheckSum[0]);
                Assert.AreEqual(item.Location.X, orig.Location.X);
                Assert.AreEqual(item.Location.Y, orig.Location.Y);
                Assert.AreEqual(item.Location.Z, orig.Location.Z);
                Assert.AreEqual(item.Location.W, orig.Location.W);
                Assert.AreEqual(item.ReferenceCode, orig.ReferenceCode);
                Assert.AreEqual(item.ReplicationID, orig.ReplicationID);
            }
        }
Exemplo n.º 2
0
        public void XmlFileSavesBinaryReadsXml()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var orig = TestResourceFactory.CreateRandom().WithId(1234) as MockClassC;

            using (var repo = new XmlFileManager<MockClassC>())
            {
                repo.WorkingPath = "";
                var xml = XmlSerializationHelper.Serialize(orig);
                var buffer = UTF8Encoding.UTF8.GetBytes(xml);

                repo.SaveToFile(buffer, _testName + ".xml", ".");
            }

            using (var repo = new XmlFileManager<MockClassC>())
            {
                repo.WorkingPath = "";
                var item = repo.LoadFromFile(_testName + ".xml", ".");

                Assert.AreEqual(item.Id, orig.Id);
                Assert.AreEqual(item.Name, orig.Name);
                Assert.AreEqual(item.GetSomeCheckSum[0], orig.GetSomeCheckSum[0]);
                Assert.AreEqual(item.Location.X, orig.Location.X);
                Assert.AreEqual(item.Location.Y, orig.Location.Y);
                Assert.AreEqual(item.Location.Z, orig.Location.Z);
                Assert.AreEqual(item.Location.W, orig.Location.W);
                Assert.AreEqual(item.ReferenceCode, orig.ReferenceCode);
                Assert.AreEqual(item.ReplicationID, orig.ReplicationID);

                var stream = repo.LoadAsStream(_testName + ".xml", ".");

                Assert.IsNotNull(stream);
            }
        }