public async Task ComputeMD5Hash_SimpleText_ComputesHash() { var input = "test"; var expected = "CY9rzUYh03PK3k6DJie09g=="; var hash = await ContentHashHelper.ComputeMD5Hash(new MemoryStream(Encoding.UTF8.GetBytes(input))); Assert.AreEqual(expected, hash); }
public void RemoveHash(string url, string expected) { var configuration = Substitute.For <IUniqueUrlFolderPresetsConfiguration>(); configuration.BaseSegment.Returns("optimized"); var sut = new ContentHashHelper(configuration); var actual = sut.RemoveHash(url); actual.ShouldBe(expected); }
async Task AppendBody(HttpRequestMessage requestMessage, Stream body, CancellationToken cancellationToken) { if (!body.CanSeek) { // we need to compute the ContentHash for this body meaning that we need to have seekable version, hence copy to a memory stream first var memoryStream = new MemoryStream(); await body.CopyToAsync(memoryStream, 81920, cancellationToken); memoryStream.Position = 0; body = memoryStream; } var bodyStartPosition = body.Position; var contentHashBytes = await ContentHashHelper.ComputeMD5HashBytes(body, cancellationToken); body.Position = bodyStartPosition; requestMessage.Content = new StreamContent(body); requestMessage.Content.Headers.ContentMD5 = contentHashBytes; }