Skip to content

Commit df80dcc

Browse files
committed
Ported Authentication.Test package (#326)
1 parent 3e30f99 commit df80dcc

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Http/HttpContextMock.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Http.Features;
55
using System;
66
using System.Collections.Generic;
7+
using System.IO;
78
using System.Security.Claims;
89
using System.Threading;
910
using Utilities.Validators;
@@ -130,6 +131,11 @@ private void PrepareFeatures()
130131
this.Features.Set<IHttpResponseFeature>(new HttpResponseFeature());
131132
}
132133

134+
if (this.Features.Get<IHttpResponseBodyFeature>() == null)
135+
{
136+
this.Features.Set<IHttpResponseBodyFeature>(new StreamResponseBodyFeature(Stream.Null));
137+
}
138+
133139
if (this.Features.Get<IServiceProvidersFeature>() == null)
134140
{
135141
this.Features.Set<IServiceProvidersFeature>(new RequestServicesFeatureMock());

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Http/HttpResponseMock.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,26 @@ public override int StatusCode
5353
set => this.httpResponse.StatusCode = value;
5454
}
5555

56-
public static HttpResponseMock From(HttpContext httpContext, HttpResponse httpResponse)
57-
{
58-
return new HttpResponseMock(httpContext)
56+
public static HttpResponseMock From(HttpContext httpContext, HttpResponse httpResponse)
57+
=> new HttpResponseMock(httpContext)
5958
{
6059
Body = httpResponse.Body,
6160
ContentLength = httpResponse.ContentLength,
6261
ContentType = httpResponse.ContentType,
6362
StatusCode = httpResponse.StatusCode
6463
};
65-
}
6664

6765
public override void OnCompleted(Func<object, Task> callback, object state)
68-
=> this.httpResponse.OnCompleted(callback, state);
66+
=> this.httpResponse
67+
.OnCompleted(callback, state);
6968

7069
public override void OnStarting(Func<object, Task> callback, object state)
71-
=> this.httpResponse.OnStarting(callback, state);
70+
=> this.httpResponse
71+
.OnStarting(callback, state);
7272

7373
public override void Redirect(string location, bool permanent)
74-
=> this.httpResponse.Redirect(location, permanent);
74+
=> this.httpResponse
75+
.Redirect(location, permanent);
7576

7677
/// <summary>
7778
/// Does nothing. Intentionally left empty, otherwise some HTTP features are not working correctly.

test/MyTested.AspNetCore.Mvc.Abstractions.Test/MyTested.AspNetCore.Mvc.Abstractions.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
56
<AssemblyName>MyTested.AspNetCore.Mvc.Test</AssemblyName>
67
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
78
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>

test/MyTested.AspNetCore.Mvc.Authentication.Test/MyTested.AspNetCore.Mvc.Authentication.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<AssemblyName>MyTested.AspNetCore.Mvc.Test</AssemblyName>
77
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>

test/MyTested.AspNetCore.Mvc.Authentication.Test/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System.Reflection;
22
using System.Runtime.InteropServices;
3+
using Microsoft.AspNetCore.Mvc.ApplicationParts;
34
using Xunit;
45

6+
[assembly: ApplicationPart("MyTested.AspNetCore.Mvc.Test.Setups")]
7+
58
[assembly: AssemblyProduct("MyTested.AspNetCore.Mvc.Authentication.Test")]
69
[assembly: ComVisible(false)]
710

0 commit comments

Comments
 (0)