Example #1
0
        public void TestOpenAppend()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file26.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            using (var streamWriter = fi.CreateText())
            {
                streamWriter.WriteLine("file26");
            }
            try
            {
                using (var fileStream = fi.Open(System.IO.FileMode.Append))
                {
                    Assert.IsNotNull(fileStream);
                    using (var streamWriter = new System.IO.StreamWriter(fileStream))
                    {
                        streamWriter.WriteLine("eof");
                    }
                }

                Assert.AreEqual("file26" + Environment.NewLine + "eof" + Environment.NewLine, File.ReadAllText(fi.FullName));
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Example #2
0
        public void TestCreateText()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file20.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            Assert.IsFalse(fi.Exists);

            using (fi.CreateText())
            {
            }

            try
            {
                Assert.IsTrue(File.Exists(fi.FullName));                 // don't use FileInfo.Exists, it caches existance
            }
            finally
            {
                fi.Delete();
            }
        }
Example #3
0
        public void TestOpenAppend()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file26.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);
            using (var streamWriter = fi.CreateText())
            {
                streamWriter.WriteLine("file26");
            }
            try
            {
                using (var fileStream = fi.Open(System.IO.FileMode.Append))
                {
                    Assert.IsNotNull(fileStream);
                    using (var streamWriter = new System.IO.StreamWriter(fileStream))
                    {
                        streamWriter.WriteLine("eof");
                    }
                }

                Assert.AreEqual("file26" + Environment.NewLine + "eof" + Environment.NewLine, File.ReadAllText(fi.FullName));
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Example #4
0
        public void TestCreateText()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file20.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);
            Assert.IsFalse(fi.Exists);

            using (fi.CreateText())
            {
            }

            try
            {
                Assert.IsTrue(File.Exists(fi.FullName)); // don't use FileInfo.Exists, it caches existance
            }
            finally
            {
                fi.Delete();
            }
        }