close streams for moked context with email in HttpContentHelper

This commit is contained in:
xiaoyushi 2023-11-01 11:46:28 +00:00
Родитель 347982e0b5
Коммит 37bd5be007
2 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -34,6 +34,9 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.UnitTests
byte[] hash1 = await GetIdentityAsync(provider, context1);
byte[] hash2 = await GetIdentityAsync(provider, context2);
context1.Request.Body.Close();
context2.Request.Body.Close();
CollectionAssert.AreNotEqual(hash1, hash2);
HttpContext context3 = HttpContextHelper.GetContextWithEmail("Abc123@outlook.com");
@ -41,6 +44,9 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.UnitTests
CollectionAssert.AreEqual(hash1, await GetIdentityAsync(provider, context3));
CollectionAssert.AreEqual(hash2, await GetIdentityAsync(provider, context4));
context3.Request.Body.Close();
context4.Request.Body.Close();
}
private async Task<byte[]> GetIdentityAsync(IUserIdentityProvider provider, HttpContext context)

Просмотреть файл

@ -17,6 +17,7 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.UnitTests
{
(HttpContext context, HttpConnectionFeature feature) = CreateHttpContext();
feature.RemoteIpAddress = IPAddress.Parse(address);
context.Request.Body.Close();
return context;
}
@ -35,7 +36,7 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.UnitTests
FeatureCollection features = new();
features.Set<IHttpConnectionFeature>(feature);
using Stream requestBody = new MemoryStream();
Stream requestBody = new MemoryStream();
Mock<HttpContext> contextMock = new();
contextMock.SetupGet(c => c.Features).Returns(features);