public void ConstructionCreatesFileIfNotExistTest()
 {
     var wrapper = new FileWrapperStream(TemporaryFile);
     wrapper.Dispose();
     Assert.IsTrue(System.IO.File.Exists(TemporaryFile));
 }
 public void PathNullConstructionTest()
 {
     var wrapper = new FileWrapperStream(null);
     wrapper.Dispose();
 }
 public void PathRelativeConstructionTest()
 {
     var wrapper = new FileWrapperStream(System.IO.Path.Combine("..", "..", "Place", "Foo"));
     wrapper.Dispose();
 }
        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);
            }
        }
 public void PathEmptyConstructionTest()
 {
     var wrapper = new FileWrapperStream(string.Empty);
     wrapper.Dispose();
 }
 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);
     }
 }
        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);
            }
        }
        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();
        }
        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);
        }
 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));
     }
 }
 public void CanSetLength()
 {
     var wrapper = new FileWrapperStream(TemporaryFile);
     Assert.AreEqual(0, wrapper.Length);
     wrapper.SetLength(200);
     Assert.AreEqual(200, wrapper.Length);
     wrapper.Dispose();
 }
        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();
            }
        }