Ejemplo n.º 1
0
        public void OpenWriteWithNotExistingFile()
        {
            // Setup
            var file = new TestFile(@"x:\directory\File.xml");

            // Execute
            using (var stream = file.OpenWrite())
            {
                var writer = new StreamWriter(stream);
                writer.Write("Some data.");
                writer.Flush();

                // Assert
                Assert.IsTrue(file.Exists); // File was created on write.
                Assert.IsNotNull(stream);
                Assert.IsTrue(stream.Length > 0);
            }

            // Assert
            using (var stream = file.OpenRead())
            {
                var reader = new StreamReader(stream);
                Assert.AreEqual("Some data.", reader.ReadToEnd());
            }
        }
Ejemplo n.º 2
0
        public void OpenWriteWithNotExistingFile()
        {
            // Setup
            var file = new TestFile(@"x:\directory\File.xml");

            // Execute
            using (var stream = file.OpenWrite())
            {
                var writer = new StreamWriter(stream);
                writer.Write("Some data.");
                writer.Flush();

                // Assert
                Assert.IsTrue(file.Exists); // File was created on write.
                Assert.IsNotNull(stream);
                Assert.IsTrue(stream.Length > 0);
            }

            // Assert
            using (var stream = file.OpenRead())
            {
                var reader = new StreamReader(stream);
                Assert.AreEqual("Some data.", reader.ReadToEnd());
            }
        }