public async Task TestHandleResponseAsync() { using (MemoryStream blobContent = new MemoryStream(Encoding.UTF8.GetBytes("some BLOB content"))) { BlobDescriptor descriptor = await Digests.ComputeDigestAsync(blobContent).ConfigureAwait(false); DescriptorDigest testBlobDigest = descriptor.GetDigest(); blobContent.Position = 0; using (HttpResponseMessage mockResponse = new HttpResponseMessage() { Content = new StringContent("some BLOB content") }) { LongAdder byteCount = new LongAdder(); BlobPuller blobPuller = new BlobPuller( fakeRegistryEndpointRequestProperties, testBlobDigest, layerOutputStream, size => Assert.AreEqual("some BLOB content".Length, size), byteCount.Add); await blobPuller.HandleResponseAsync(mockResponse).ConfigureAwait(false); Assert.AreEqual( "some BLOB content", Encoding.UTF8.GetString(layerContentOutputStream.ToArray())); Assert.AreEqual(testBlobDigest, layerOutputStream.ComputeDigest().GetDigest()); Assert.AreEqual("some BLOB content".Length, byteCount.Sum()); } } }
public void SetUpFakes() { layerContentOutputStream = new MemoryStream(); layerOutputStream = new CountingDigestOutputStream(layerContentOutputStream); fakeDigest = DescriptorDigest.FromHash( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); testBlobPuller = new BlobPuller( fakeRegistryEndpointRequestProperties, fakeDigest, layerOutputStream, _ => { }, _ => { }); }