public void DeleteTest()
        {
            string path = null;

            using (var temp = new WindowsTempFile()) path = temp.Path;
            Assert.IsFalse(File.Exists(path));
        }
Beispiel #2
0
        public void SaveToXml <T>(string path, T t)
        {
            var xmlSerializer = new XmlSerializer(typeof(T));

            using (var tempFile = new WindowsTempFile())
            {
                using (TextWriter tw = new StreamWriter(tempFile.Path))
                    xmlSerializer.Serialize(tw, t);

                File.Copy(tempFile.Path, path, overwrite: true);
            }
        }
        public void WriteLoadTest()
        {
            string content = "trello";
            string loadedContent;

            using (var temp = new WindowsTempFile())
            {
                temp.Save(content);
                loadedContent = temp.Load();
            }

            Assert.AreEqual(content, loadedContent);
        }
Beispiel #4
0
        public void TestSimpleSaveLoad()
        {
            var simple = new SimpleXmlClass()
            {
                Name   = "Grzegorz",
                Number = 33
            };

            using (var temp = new WindowsTempFile())
            {
                xmlService.SaveToXml(temp.Path, simple);
                var loaded = xmlService.LoadFromXml <SimpleXmlClass>(temp.Path);

                Assert.AreEqual(simple.Name, loaded.Name);
                Assert.AreEqual(simple.Number, loaded.Number);
            }
        }
        public void WriteLoadStreamTest()
        {
            string content = "trello";
            string loadedContent;

            using (var temp = new WindowsTempFile())
                using (var stream = generateStreamFromString(content))
                    using (var memoryStream = new MemoryStream())
                        using (var streamReader = new StreamReader(memoryStream, Encoding.UTF8))
                            using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8))
                            {
                                temp.Save(stream);
                                temp.LoadTo(memoryStream);
                                memoryStream.Flush();      //clears buffer
                                memoryStream.Position = 0; //set position to 0 to read all contents
                                loadedContent         = streamReader.ReadToEnd();
                            }
            Assert.AreEqual(content, loadedContent);
        }
Beispiel #6
0
        public void TestNestedSaveLoad()
        {
            var simple = new XmlNestedClass()
            {
                Name   = "Grzegorz",
                Nested = new SimpleXmlClass()
                {
                    Name   = "Brzęczyszczykiewicz",
                    Number = 5
                }
            };

            using (var temp = new WindowsTempFile())
            {
                xmlService.SaveToXml(temp.Path, simple);
                var loaded = xmlService.LoadFromXml <XmlNestedClass>(temp.Path);

                Assert.AreEqual(simple.Name, loaded.Name);
                Assert.AreEqual(simple.Nested.Name, loaded.Nested.Name);
                Assert.AreEqual(simple.Nested.Number, loaded.Nested.Number);
            }
        }
Beispiel #7
0
        public void TestListSaveLoad()
        {
            var simple = new XmlClassWithList()
            {
                Name    = "Grzegorz",
                Numbers = new List <int>()
                {
                    1,
                    3,
                    5,
                }
            };

            using (var temp = new WindowsTempFile())
            {
                xmlService.SaveToXml(temp.Path, simple);
                var loaded = xmlService.LoadFromXml <XmlClassWithList>(temp.Path);

                Assert.AreEqual(simple.Name, loaded.Name);
                CollectionAssert.AreEqual(simple.Numbers, loaded.Numbers);
            }
        }
 public void ExistTest()
 {
     using (var temp = new WindowsTempFile())
         Assert.IsTrue(File.Exists(temp.Path));
 }