Exemplo n.º 1
0
        public void MoveStreamNotTemporaryTest()
        {
            StreamManager_Accessor streamManager = new StreamManager_Accessor();

            Assert.IsTrue(streamManager.IsEmpty());

            string path1 = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testPath1.cache");
            string path2 = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testPath2.cache");

            //creates two streams in the stream manager
            Stream stream1 = streamManager.GetStream(path1);
            Stream stream2 = streamManager.GetStream(path2);

            //both streams exists
            Assert.AreEqual(2, streamManager.m_streams.Count);

            //stream2 is opened before moving
            Assert.IsTrue(stream2.CanWrite);
            Assert.IsTrue(stream2.CanRead);

            //file of the path1 and path2 should exist before move
            Assert.IsTrue(File.Exists(path1));
            Assert.IsTrue(File.Exists(path2));

            //move path1 over path2
            streamManager.MoveStream(path1, path2);

            //file of the old path1 should not exist anymore
            Assert.IsFalse(File.Exists(path1));

            //path2 should still exists, although it is different file
            Assert.IsTrue(File.Exists(path2));

            //stream manager should now have just one stream and it should be path2.
            Assert.AreEqual(1, streamManager.m_streams.Count);
            Assert.IsFalse(streamManager.m_streams.ContainsKey(path1));
            Assert.IsTrue(streamManager.m_streams.ContainsKey(path2));

            //the current stream for path2 should be equal to stream1
            Stream stream3 = streamManager.GetStream(path2);

            Assert.AreEqual(stream1, stream3);

            //the stream2 should be close
            Assert.IsFalse(stream2.CanWrite);
            Assert.IsFalse(stream2.CanRead);
        }
        public void MoveStreamTemporaryTest()
        {
            StreamManager_Accessor streamManager = new StreamManager_Accessor();

            Assert.IsTrue(streamManager.IsEmpty());

            string path1 = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testPath1.cache");
            string path2 = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testPath2.cache");

            //creates two streams in the stream manager
            Stream stream1 = streamManager.GetStream(path1, true);
            Stream stream2 = streamManager.GetStream(path2, true);

            //both streams exists
            Assert.AreEqual(2, streamManager.m_streams.Count);

            //stream2 is opened before moving
            Assert.IsTrue(stream2.CanWrite);
            Assert.IsTrue(stream2.CanRead);

            //move path1 over path2
            streamManager.MoveStream(path1, path2);

            //stream manager should now have just one stream and it should be path2. 
            Assert.AreEqual(1, streamManager.m_streams.Count);
            Assert.IsFalse(streamManager.m_streams.ContainsKey(path1));
            Assert.IsTrue(streamManager.m_streams.ContainsKey(path2));

            //the current stream for path2 should be equal to stream1
            Stream stream3 = streamManager.GetStream(path2);
            Assert.AreEqual(stream1, stream3);

            //the stream2 should be close
            Assert.IsFalse(stream2.CanWrite);
            Assert.IsFalse(stream2.CanRead);
        }