コード例 #1
0
        public void TestCounter()
        {
            using (MemoryStream memoryStream = new MemoryStream())
                using (DataCounterStream dataCounterStream = new DataCounterStream(memoryStream))
                {
                    using (FileStream fileStream = readFileInfo.OpenRead())
                    {
                        fileStream.CopyTo(dataCounterStream);
                    }
                    Assert.AreEqual(readFileInfo.Length, dataCounterStream.WritedBytes.Bytes);

                    dataCounterStream.Seek(0, SeekOrigin.Begin);
                    dataCounterStream.CopyTo(Stream.Null);
                    Assert.AreEqual(readFileInfo.Length, dataCounterStream.ReadedBytes.Bytes);
                }
        }
コード例 #2
0
        public void TestCounterByteByByte()
        {
            using (MemoryStream memoryStream = new MemoryStream())
                using (DataCounterStream dataCounterStream = new DataCounterStream(memoryStream))
                {
                    using (FileStream fileStream = readFileInfo.OpenRead())
                    {
                        for (int i = 0; i < readFileInfo.Length; i++)
                        {
                            dataCounterStream.WriteByte((byte)fileStream.ReadByte());
                        }
                    }
                    Assert.AreEqual(readFileInfo.Length, dataCounterStream.WritedBytes.Bytes);

                    dataCounterStream.Seek(0, SeekOrigin.Begin);
                    for (int i = 0; i < readFileInfo.Length; i++)
                    {
                        Assert.AreNotEqual(-1, dataCounterStream.ReadByte());
                    }
                    Assert.AreEqual(readFileInfo.Length, dataCounterStream.ReadedBytes.Bytes);
                    Assert.AreEqual(-1, dataCounterStream.ReadByte());
                    Assert.AreEqual(readFileInfo.Length, dataCounterStream.ReadedBytes.Bytes);
                }
        }