Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove HttpContextStub and HttpRequestStub from AspNetCore tests (prep FrameworkReference) #2414

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public static HttpContextAccessor CreateHttpContextAccessor(RequestTelemetry req
return contextAccessor;
}

public static HttpContextAccessor CreateHttpContextAccessorWithoutRequest(HttpContextStub httpContextStub, RequestTelemetry requestTelemetry = null)
public static HttpContextAccessor CreateHttpContextAccessorWithoutRequest(HttpContext httpContext, RequestTelemetry requestTelemetry = null)
{
var services = new ServiceCollection();

var contextAccessor = new HttpContextAccessor { HttpContext = httpContextStub };
var contextAccessor = new HttpContextAccessor { HttpContext = httpContext };

services.AddSingleton<IHttpContextAccessor>(contextAccessor);

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static IHttpContextAccessor GetHttpContextAccessor(string name, bool isA
{
return new HttpContextAccessor
{
HttpContext = new HttpContextStub
HttpContext = new DefaultHttpContext
{
User = new GenericPrincipal(new IdentityStub() { Name = name, IsAuthenticated = isAuthenticated }, new string[0])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<!-- TargetFrameworks are defined in Test.props, but can be overridden here if needed. -->
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void InitializeDoesNotThrowIfRequestServicesAreUnavailable()
[Fact]
public void InitializeDoesNotThrowIfRequestIsUnavailable()
{
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessorWithoutRequest(new HttpContextStub(), new RequestTelemetry());
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessorWithoutRequest(new DefaultHttpContext(), new RequestTelemetry());

var initializer = new ClientIpHeaderTelemetryInitializer(contextAccessor);

Expand All @@ -51,10 +51,7 @@ public void InitializeDoesNotThrowIfRequestIsUnavailable()
[Fact]
public void InitializeDoesNotThrowIfHeaderCollectionIsUnavailable()
{
var httpContext = new HttpContextStub();
httpContext.OnRequestGetter = () => new HttpRequestStub(httpContext);

var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessorWithoutRequest(httpContext, new RequestTelemetry());
var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessorWithoutRequest(new DefaultHttpContext(), new RequestTelemetry());

var initializer = new ClientIpHeaderTelemetryInitializer(contextAccessor);

Expand Down