Exemplo n.º 1
0
        public void ConstructionCreatesFileIfNotExistTest()
        {
            var wrapper = new FileWrapperStream(TemporaryFile);

            wrapper.Dispose();
            Assert.IsTrue(System.IO.File.Exists(TemporaryFile));
        }
Exemplo n.º 2
0
 internal void PositionSet([PexAssumeUnderTest] FileWrapperStream target, long value)
 {
     target.Position = value;
     // TODO: add assertions to method FileWrapperStreamTest.PositionSet(FileWrapperStream, Int64)
     Assert.IsTrue(target.Position >= 0);
     Assert.AreEqual(value, target.Position);
 }
Exemplo n.º 3
0
        public void FlushAllTest()
        {
            int    no = 4;
            string path;

            FileWrapperStream[] streams = new FileWrapperStream[no];
            string dataString           = "Blah";

            byte[] data = StrToByteArray(dataString);
            for (int i = 0; i < no; i++)
            {
                path       = System.IO.Path.Combine(AppContext.BaseTestDirectory, "Foo" + i + ".xml");
                streams[i] = (FileWrapperStream)AppContext.StreamManager.GetStream(path);
                Assert.IsFalse(streams[i].IsAwaitingDiskFlush);

                streams[i].Write(data, 0, data.Length);
                Assert.IsTrue(streams[i].IsAwaitingDiskFlush);
            }

            AppContext.StreamManager.FlushAll();
            for (int i = 0; i < no; i++)
            {
                Assert.IsFalse(streams[i].IsAwaitingDiskFlush);
            }

            //delete files after test
            for (int i = 0; i < no; i++)
            {
                path = System.IO.Path.Combine(AppContext.BaseTestDirectory, "Foo" + i + ".xml");
                (new FileInfo(path)).Delete();
            }
        }
Exemplo n.º 4
0
 public void ConstructionFailsIfFileIfCannotOpenFile()
 {
     using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(new System.IO.FileStream(TemporaryFile, System.IO.FileMode.OpenOrCreate)))
     {
         var wrapper = new FileWrapperStream(TemporaryFile);
         wrapper.Dispose();
         Assert.IsTrue(System.IO.File.Exists(TemporaryFile));
     }
 }
Exemplo n.º 5
0
        public void CanSetLength()
        {
            var wrapper = new FileWrapperStream(TemporaryFile);

            Assert.AreEqual(0, wrapper.Length);
            wrapper.SetLength(200);
            Assert.AreEqual(200, wrapper.Length);
            wrapper.Dispose();
        }
        public static FileWrapperStream Create(string path_s)
        {
            FileWrapperStream fileWrapperStream = new FileWrapperStream(path_s);
            return fileWrapperStream;

            // TODO: Edit factory method of FileWrapperStream
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
Exemplo n.º 7
0
 public void WriteSetsDiskFlushFlag()
 {
     using (var wrapper = new FileWrapperStream(TemporaryFile))
     {
         wrapper.Seek(0, System.IO.SeekOrigin.Begin);
         Assert.IsFalse(wrapper.IsAwaitingDiskFlush);
         wrapper.WriteByte(4);
         Assert.IsTrue(wrapper.IsAwaitingDiskFlush);
     }
 }
Exemplo n.º 8
0
        public static FileWrapperStream Create(string path_s)
        {
            FileWrapperStream fileWrapperStream = new FileWrapperStream(path_s);

            return(fileWrapperStream);

            // TODO: Edit factory method of FileWrapperStream
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
Exemplo n.º 9
0
        public void FlushTest()
        {
            FileWrapperStream stream = (FileWrapperStream)AppContext.StreamManager.GetStream(TmpPath);

            Assert.IsFalse(stream.IsAwaitingDiskFlush);

            string dataString = "Blah";

            byte[] data = StrToByteArray(dataString);
            stream.Write(data, 0, data.Length);

            Assert.IsTrue(stream.IsAwaitingDiskFlush);
            AppContext.StreamManager.Flush(TmpPath); //this should pass... file exists
            Assert.IsFalse(stream.IsAwaitingDiskFlush);
        }
Exemplo n.º 10
0
        public void ConstructionDoesNotEraseFileIfExistTest()
        {
            System.IO.StreamWriter writer = System.IO.File.CreateText(TemporaryFile);
            writer.Write("blah");
            writer.Close();

            System.IO.FileInfo preInfo = new System.IO.FileInfo(TemporaryFile);
            Assert.IsTrue(preInfo.Length != 0);

            var wrapper = new FileWrapperStream(TemporaryFile);

            wrapper.Dispose();
            Assert.IsTrue(System.IO.File.Exists(TemporaryFile));

            System.IO.FileInfo postInfo = new System.IO.FileInfo(TemporaryFile);
            Assert.IsTrue(postInfo.Length != 0);
        }
Exemplo n.º 11
0
        public void WriteToNonExistingFileTest()
        {
            Assert.IsFalse(System.IO.File.Exists(TemporaryFile));

            using (var wrapper = new FileWrapperStream(TemporaryFile))
            {
                Assert.IsFalse(wrapper.IsAwaitingDiskFlush);
                System.IO.StreamWriter writer = new System.IO.StreamWriter(wrapper);
                writer.AutoFlush = true;
                writer.Write("test");
            }

            using (System.IO.StreamReader reader = new System.IO.StreamReader(TemporaryFile))
            {
                string data = reader.ReadToEnd();
                Assert.AreEqual("test", data);
            }
        }
Exemplo n.º 12
0
        public void LoadExistingFileTest()
        {
            System.IO.StreamWriter writer = System.IO.File.CreateText(TemporaryFile);
            writer.Write("blah");
            writer.Close();

            var wrapper = new FileWrapperStream(TemporaryFile);

            // Ensure that new FileWrappers start at the beginning
            Assert.AreEqual(0, wrapper.Position);

            Assert.AreEqual(4, wrapper.Length);
            wrapper.Position = 0;
            System.IO.StreamReader reader = new System.IO.StreamReader(wrapper);

            string data = reader.ReadToEnd();

            Assert.AreEqual("blah", data);

            wrapper.Dispose();
        }
Exemplo n.º 13
0
        public void WriteToExistingFileTest()
        {
            using (System.IO.StreamWriter writer = System.IO.File.CreateText(TemporaryFile))
            {
                writer.Write("blah");
                writer.Close();
            }

            using (var wrapper = new FileWrapperStream(TemporaryFile))
            {
                wrapper.Seek(0, System.IO.SeekOrigin.End);

                Assert.IsFalse(wrapper.IsAwaitingDiskFlush);
                System.IO.StreamWriter writer = new System.IO.StreamWriter(wrapper);
                writer.AutoFlush = true;
                writer.Write("test");
            }

            using (System.IO.StreamReader reader = new System.IO.StreamReader(TemporaryFile))
            {
                string data = reader.ReadToEnd();
                Assert.AreEqual("blahtest", data);
            }
        }
Exemplo n.º 14
0
 internal void WriteByte([PexAssumeUnderTest] FileWrapperStream target, byte value)
 {
     target.WriteByte(value);
     // TODO: add assertions to method FileWrapperStreamTest.WriteByte(FileWrapperStream, Byte)
 }
Exemplo n.º 15
0
        public void PathRelativeConstructionTest()
        {
            var wrapper = new FileWrapperStream(System.IO.Path.Combine("..", "..", "Place", "Foo"));

            wrapper.Dispose();
        }
Exemplo n.º 16
0
        public void PathNullConstructionTest()
        {
            var wrapper = new FileWrapperStream(null);

            wrapper.Dispose();
        }
Exemplo n.º 17
0
        public void PathEmptyConstructionTest()
        {
            var wrapper = new FileWrapperStream(string.Empty);

            wrapper.Dispose();
        }