Skip to content
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
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<ItemGroup>
<PackageVersion Include="AutoFixture" Version="4.18.1" />
<PackageVersion Include="Backport.System.Threading.Lock" Version="3.1.4" />
<PackageVersion Include="Codebelt.Extensions.Xunit" Version="9.1.3" />
<PackageVersion Include="Codebelt.Extensions.Xunit.Hosting" Version="9.1.3" />
<PackageVersion Include="Codebelt.Extensions.Xunit.Hosting.AspNetCore" Version="9.1.3" />
<PackageVersion Include="Codebelt.Extensions.Xunit" Version="10.0.0" />
<PackageVersion Include="Codebelt.Extensions.Xunit.Hosting" Version="10.0.0" />
<PackageVersion Include="Codebelt.Extensions.Xunit.Hosting.AspNetCore" Version="10.0.0" />
<PackageVersion Include="Codebelt.Extensions.YamlDotNet" Version="9.0.0" />
<PackageVersion Include="Meziantou.Xunit.ParallelTestFramework" Version="2.3.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public async Task HandleAuthenticateAsync_ShouldReturnContent()
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
},
hostFixture: null))
}))
{
var client = webApp.Host.GetTestClient();
var bb = new BasicAuthorizationHeaderBuilder()
Expand Down Expand Up @@ -93,9 +92,9 @@ public async Task HandleAuthenticateAsync_ShouldReturn401WithUnauthorizedMessage
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var options = webApp.ServiceProvider.GetRequiredScopedService<IOptionsSnapshot<BasicAuthenticationOptions>>().Get(BasicAuthorizationHeader.Scheme);
var options = webApp.Host.Services.GetRequiredScopedService<IOptionsSnapshot<BasicAuthenticationOptions>>().Get(BasicAuthorizationHeader.Scheme);
var client = webApp.Host.GetTestClient();

var result = await client.GetAsync("/fake");
Expand Down Expand Up @@ -141,7 +140,7 @@ public async Task HandleAuthenticateAsync_EnsureAnonymousIsWorking()
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var client = webApp.Host.GetTestClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public async Task InvokeAsync_ShouldThrowUnauthorizedException_InvalidCredential
}, app =>
{
app.UseBasicAuthentication();
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<BasicAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<BasicAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down Expand Up @@ -78,10 +78,10 @@ public async Task InvokeAsync_ShouldCaptureUnauthorizedException_InvalidCredenti
{
app.UseFaultDescriptorExceptionHandler();
app.UseBasicAuthentication();
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<BasicAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<BasicAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var bb = new BasicAuthorizationHeaderBuilder()
Expand Down Expand Up @@ -130,10 +130,10 @@ public async Task InvokeAsync_ShouldAuthenticateWhenApplyingAuthorizationHeader(
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<BasicAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<BasicAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public async Task HandleAuthenticateAsync_ShouldReturnContent_WithQopAuthenticat
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{

var options = webApp.ServiceProvider.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var options = webApp.Host.Services.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var client = webApp.Host.GetTestClient();

var result = await client.GetAsync("/fake");
Expand Down Expand Up @@ -135,10 +135,10 @@ public async Task HandleAuthenticateAsync_ShouldReturnContent_QopAuthenticationI
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{

var options = webApp.ServiceProvider.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var options = webApp.Host.Services.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var client = webApp.Host.GetTestClient();

var result = await client.GetAsync("/fake");
Expand Down Expand Up @@ -214,10 +214,10 @@ public async Task HandleAuthenticateAsync_ShouldReturnContent_WithServerSideHa1S
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{

var options = webApp.ServiceProvider.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var options = webApp.Host.Services.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var client = webApp.Host.GetTestClient();

var result = await client.GetAsync("/fake");
Expand Down Expand Up @@ -289,9 +289,9 @@ public async Task HandleAuthenticateAsync_ShouldReturn401WithUnauthorizedMessage
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var options = webApp.ServiceProvider.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var options = webApp.Host.Services.GetRequiredScopedService<IOptionsSnapshot<DigestAuthenticationOptions>>().Get(DigestAuthorizationHeader.Scheme);
var client = webApp.Host.GetTestClient();

var result = await client.GetAsync("/fake");
Expand Down Expand Up @@ -331,7 +331,7 @@ public async Task HandleAuthenticateAsync_EnsureAnonymousIsWorking()
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var client = webApp.Host.GetTestClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public async Task InvokeAsync_ShouldNotBeAuthenticated()
{
app.UseExceptionMiddleware();
app.UseDigestAccessAuthentication();
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down Expand Up @@ -101,10 +101,10 @@ public async Task InvokeAsync_ShouldAuthenticateWhenApplyingAuthorizationHeader(
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down Expand Up @@ -178,10 +178,10 @@ public async Task InvokeAsync_ShouldAuthenticateWhenApplyingAuthorizationHeaderN
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down Expand Up @@ -253,10 +253,10 @@ public async Task InvokeAsync_ShouldAuthenticateWhenApplyingAuthorizationHeaderW
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<DigestAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task HandleAuthenticateAsync_ShouldReturnContent()
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var client = webApp.Host.GetTestClient();

Expand Down Expand Up @@ -126,9 +126,9 @@ public async Task HandleAuthenticateAsync_ShouldReturn401WithUnauthorizedMessage
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var options = webApp.ServiceProvider.GetRequiredScopedService<IOptionsSnapshot<HmacAuthenticationOptions>>().Get(AuthenticationScheme);
var options = webApp.Host.Services.GetRequiredScopedService<IOptionsSnapshot<HmacAuthenticationOptions>>().Get(AuthenticationScheme);
var client = webApp.Host.GetTestClient();

client.DefaultRequestHeaders.Add(HeaderNames.Date, DateTime.UtcNow.ToString("R"));
Expand Down Expand Up @@ -183,7 +183,7 @@ public async Task HandleAuthenticateAsync_EnsureAnonymousIsWorking()
app.UseAuthorization();

app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var client = webApp.Host.GetTestClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public async Task InvokeAsync_ShouldAuthenticateWhenApplyingAuthorizationHeader(
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
}, hostFixture: null))
}))
{
var context = middleware.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.ServiceProvider.GetRequiredService<IOptions<HmacAuthenticationOptions>>();
var context = middleware.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;
var options = middleware.Host.Services.GetRequiredService<IOptions<HmacAuthenticationOptions>>();
var pipeline = middleware.Application.Build();

var ue = await Assert.ThrowsAsync<UnauthorizedException>(async () => await pipeline(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public HmacAuthorizationHeaderBuilderTest(ITestOutputHelper output) : base(outpu
[Fact]
public void Build_ShouldGenerateValidAuthorizationHeader()
{
using var mw = WebHostTestFactory.Create(hostFixture: null);
var context = mw.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
using var mw = WebHostTestFactory.Create();
var context = mw.Host.Services.GetRequiredService<IHttpContextAccessor>().HttpContext;

var timestamp = DateTime.Parse("2022-07-10T12:50:42.2737531Z", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task UseFaultDescriptorExceptionHandler_ShouldCaptureException_Rend
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
return client.GetAsync("/");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();

Expand Down Expand Up @@ -342,7 +342,7 @@ public async Task UseFaultDescriptorExceptionHandler_ShouldCaptureException_Rend
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
return client.GetAsync("/");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();

Expand Down Expand Up @@ -600,7 +600,7 @@ public async Task UseFaultDescriptorExceptionHandler_ShouldCaptureException_Rend
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml"));
return client.GetAsync("/");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();

Expand Down Expand Up @@ -690,7 +690,7 @@ public async Task UseFaultDescriptorExceptionHandler_ShouldCaptureException_Rend
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml"));
return client.GetAsync("/");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task OnException_ShouldCaptureException_RenderAsProblemDetails_Usin
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
return client.GetAsync("/statuscodes/XXX/serverError");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();
TestOutput.WriteLine(body);
Expand Down Expand Up @@ -311,7 +311,7 @@ public async Task OnException_ShouldCaptureException_RenderAsDefault_UsingJson(F
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
return client.GetAsync("/statuscodes/XXX/serverError");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();
TestOutput.WriteLine(body);
Expand Down Expand Up @@ -584,7 +584,7 @@ public async Task OnException_ShouldCaptureException_RenderAsProblemDetails_Usin
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml"));
return client.GetAsync("/statuscodes/XXX/serverError");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();
TestOutput.WriteLine(body);
Expand Down Expand Up @@ -831,7 +831,7 @@ public async Task OnException_ShouldCaptureException_RenderAsDefault_UsingXml(Fa
{
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml"));
return client.GetAsync("/statuscodes/XXX/serverError");
}, hostFixture: null);
});

var body = await response.Content.ReadAsStringAsync();
TestOutput.WriteLine(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task GetEtag_ShouldReturnOkWithEtagAndSubsequentlyNotModified(strin
{
app.UseRouting();
app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var client = filter.Host.GetTestClient();
var result = await client.GetAsync(relativeEndpoint);
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task GetLastModified_ShouldReturnOkWithLastModifiedAndSubsequentlyN
{
app.UseRouting();
app.UseEndpoints(routes => { routes.MapControllers(); });
}, hostFixture: null))
}))
{
var client = filter.Host.GetTestClient();
var result = await client.GetAsync("/fake/getCacheByLastModified");
Expand Down
Loading
Loading