public void CanReadPartsOfFileCorrectly()
        {
            //download file then read different parts of each
            string tempFile = Path.GetTempFileName();
            try
            {

                new WebClient().DownloadFile(Constants.TWENTY_MEG_FILE, tempFile);
                byte[] expected;
                using (var binaryReader = new BinaryReader(File.OpenRead(tempFile)))
                {
                    binaryReader.BaseStream.Position = 100;
                    expected = binaryReader.ReadBytes(5);
                }
                var stream = new SeekableNetworkStream(Constants.TWENTY_MEG_FILE);
                var actual = new byte[5];
                stream.Seek(100, SeekOrigin.Begin);
                stream.Read(actual, 0, 5);

                //make sure bytes are the same
                Assert.True(actual.SequenceEqual(expected));
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Ejemplo n.º 2
0
        public void CanReadPartsOfFileCorrectly()
        {
            //download file then read different parts of each
            string tempFile = Path.GetTempFileName();

            try
            {
                new WebClient().DownloadFile(Constants.TWENTY_MEG_FILE, tempFile);
                byte[] expected;
                using (var binaryReader = new BinaryReader(File.OpenRead(tempFile)))
                {
                    binaryReader.BaseStream.Position = 100;
                    expected = binaryReader.ReadBytes(5);
                }
                var stream = new SeekableNetworkStream(Constants.TWENTY_MEG_FILE);
                var actual = new byte[5];
                stream.Seek(100, SeekOrigin.Begin);
                stream.Read(actual, 0, 5);

                //make sure bytes are the same
                Assert.True(actual.SequenceEqual(expected));
            }
            finally
            {
                File.Delete(tempFile);
            }
        }