public async Task TestHashCalculationAsync() { FileInfo fileInfo = new FileInfo(GetType().Assembly.Location); byte[] hash; using (FileStream fileStream = fileInfo.OpenRead()) using (HashAlgorithm hashCalculator = HashAlgorithm.Create(HashAlgorithmName.Name)) { hash = hashCalculator.ComputeHash(fileStream); } HashStream hashStream; using (FileStream fileStream = fileInfo.OpenRead()) using (RandomReadNumberStream randomReadStream = new RandomReadNumberStream(fileStream)) using (hashStream = new HashStream(randomReadStream, CryptoStreamMode.Read, HashAlgorithmName)) { await hashStream.CopyToAsync(Stream.Null); } Assert.AreEqual(hash, hashStream.HashResult.HashBytes); using (FileStream fileStream = fileInfo.OpenRead()) using (RandomReadNumberStream randomReadStream = new RandomReadNumberStream(fileStream)) using (hashStream = new HashStream(Stream.Null, CryptoStreamMode.Write, HashAlgorithmName)) { await randomReadStream.CopyToAsync(hashStream); } Assert.AreEqual(hash, hashStream.HashResult.HashBytes); }
public async Task TestWriteAsync() { byte[] wrapContent, plainContent; using (FileStream fileStream = readFileInfo.OpenRead()) using (RandomReadNumberStream randomReadNumberStream = new RandomReadNumberStream(fileStream)) { using (MemoryStream memoryStream = new MemoryStream()) using (WrapStream wrapStream = new WrapStreamImpl(memoryStream)) { await randomReadNumberStream.CopyToAsync(wrapStream); wrapContent = memoryStream.ToArray(); } fileStream.Seek(0, SeekOrigin.Begin); using (MemoryStream memoryStream = new MemoryStream()) { await randomReadNumberStream.CopyToAsync(memoryStream); plainContent = memoryStream.ToArray(); } } Assert.AreEqual(plainContent, wrapContent); }
public void TestRead() { using (FileStream fileStream = readFileInfo.OpenRead()) using (RandomReadNumberStream randomReadNumberStream = new RandomReadNumberStream(fileStream)) using (WrapStream wrapStream = new WrapStreamImpl(randomReadNumberStream)) { byte[] wrapContent = wrapStream.ReadToEnd(); fileStream.Seek(0, SeekOrigin.Begin); byte[] fileContent = fileStream.ReadToEnd(); Assert.AreEqual(wrapContent, fileContent); } }
public async Task TestReadAsync() { using (FileStream fileStream = readFileInfo.OpenRead()) using (RandomReadNumberStream randomReadNumberStream = new RandomReadNumberStream(fileStream)) using (WrapStream wrapStream = new WrapStreamImpl(randomReadNumberStream)) { byte[] wrapContent = await wrapStream.ReadToEndAsync(); fileStream.Seek(0, SeekOrigin.Begin); byte[] plainContent = await fileStream.ReadToEndAsync(); Assert.AreEqual(plainContent, wrapContent); } }