// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.ObjectPool; using Microsoft.Extensions.Options; using Xunit; namespace Microsoft.AspNetCore.Http { public class HttpContextFactoryTests { [Fact] public void CreateHttpContextSetsHttpContextAccessor() { // Arrange var accessor = new HttpContextAccessor(); var contextFactory = new HttpContextFactory(new DefaultObjectPoolProvider(), Options.Create(new FormOptions()), accessor); // Act var context = contextFactory.Create(new FeatureCollection()); // Assert Assert.True(ReferenceEquals(context, accessor.HttpContext)); } [Fact] public void AllowsCreatingContextWithoutSettingAccessor() { // Arrange var contextFactory = new HttpContextFactory(new DefaultObjectPoolProvider(), Options.Create(new FormOptions())); // Act & Assert var context = contextFactory.Create(new FeatureCollection()); contextFactory.Dispose(context); } } }