Exemplo n.º 1
0
        public void TestOpenHidden()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file25.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            using (fi.Create())
            {
            }
            try
            {
                Assert.Throws <UnauthorizedAccessException>(() =>
                {
                    File.SetAttributes(fi.FullName, File.GetAttributes(fi.FullName) | FileAttributes.Hidden);

                    using (var fileStream = fi.Open(FileMode.Create))
                    {
                        Assert.IsNotNull(fileStream);
                    }
                });
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public void TestOpenOpen()
        {
            var fi = new FileInfo(longPathFilename);

            using (var fileStream = fi.Open(FileMode.Open))
            {
                Assert.IsNotNull(fileStream);
            }
        }
Exemplo n.º 4
0
        public void TestOpenCreateNew()
        {
            var fi = new FileInfo(filePath);

            using (var fileStream = fi.Open(FileMode.CreateNew))
            {
                Assert.IsNotNull(fileStream);
            }
        }
Exemplo n.º 5
0
        public void TestOpenCreateNew()
        {
            var fi = new FileInfo(longPathFilename);

            Assert.Throws <IOException>(() =>
            {
                using (var fileStream = fi.Open(FileMode.CreateNew))
                {
                    Assert.IsNotNull(fileStream);
                }
            });
        }
Exemplo n.º 6
0
        public void TestOpenReadWithWrite()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file31.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            try
            {
                using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read))
                {
                    fileStream.WriteByte(43);
                }
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Exemplo n.º 7
0
        public void TestOpenReadWithWrite()
        {
            var tempLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("file31.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            try
            {
                Assert.Throws <NotSupportedException>(() =>
                {
                    using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read))
                    {
                        fileStream.WriteByte(43);
                    }
                });
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Exemplo n.º 8
0
        public void TestOpenCreatesEmpty()
        {
            var tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());

            try
            {
                using (var writer = File.CreateText(tempLongPathFilename))
                {
                    writer.WriteLine("test");
                }

                var fi = new FileInfo(tempLongPathFilename);
                using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read, FileShare.Read))
                {
                    Assert.AreEqual(-1, fileStream.ReadByte());
                }
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
 public void TestOpenReadWithWrite()
 {
     var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file31.ext").ToString();
     var fi = new FileInfo(tempLongPathFilename);
     try
     {
         using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read))
         {
             fileStream.WriteByte(43);
         }
     }
     finally
     {
         File.Delete(tempLongPathFilename);
     }
 }
Exemplo n.º 11
0
 public void TestOpenOpen()
 {
     var fi = new FileInfo(longPathFilename);
     using (var fileStream = fi.Open(FileMode.Open))
     {
         Assert.IsNotNull(fileStream);
     }
 }
Exemplo n.º 12
0
        public void TestOpenHidden()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file25.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            using (fi.Create())
            {
            }
            try
            {
                File.SetAttributes(fi.FullName, File.GetAttributes(fi.FullName) | FileAttributes.Hidden);

                using (var fileStream = fi.Open(FileMode.Create))
                {
                    Assert.IsNotNull(fileStream);
                }

            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Exemplo n.º 13
0
        public void TestOpenCreatesEmpty()
        {
            var tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());
            try
            {
                using (var writer = File.CreateText(tempLongPathFilename))
                {
                    writer.WriteLine("test");
                }

                var fi = new FileInfo(tempLongPathFilename);
                using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read, FileShare.Read))
                {
                    Assert.AreEqual(-1, fileStream.ReadByte());
                }

            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Exemplo n.º 14
0
		public void TestOpenCreateNew()
		{
			var fi = new FileInfo(filePath);
			using (var fileStream = fi.Open(FileMode.CreateNew))
			{
				Assert.IsNotNull(fileStream);
			}
		}