Skip to content

Commit

Permalink
Upgrade and clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Mar 18, 2024
1 parent e6e5748 commit 73cf1f3
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 76 deletions.
28 changes: 14 additions & 14 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
<ItemGroup>
<!-- Source -->
<PackageVersion Include="Microsoft.Extensions.Http" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.3.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="System.Net.Http.Json" Version="$(RuntimeVersion)" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="MinVer" Version="5.0.0" />
<!-- Samples -->
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.Authentication.WebAssembly.Msal" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.Identity.Web" Version="1.25.10" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.3" />
<PackageVersion Include="Microsoft.Authentication.WebAssembly.Msal" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.3" />
<PackageVersion Include="Microsoft.Identity.Web" Version="2.17.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<!-- Tests -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
</Project>
7 changes: 0 additions & 7 deletions samples/HaveIBeenPwned.BlazorApp/Server/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ public class ErrorModel : PageModel

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
Expand Down
19 changes: 7 additions & 12 deletions samples/HaveIBeenPwned.WebApi/Controllers/BreachesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@ namespace HaveIBeenPwned.WebApi.Controllers;

[ApiController]
[Route("api/breaches")]
public class BreachesController : ControllerBase
{
private readonly IPwnedBreachesClient _pwnedBreachesClient;

public BreachesController(IPwnedBreachesClient pwnedBreachesClient) =>
_pwnedBreachesClient = pwnedBreachesClient;

public class BreachesController(IPwnedBreachesClient pwnedBreachesClient) : ControllerBase
{
[HttpGet, Route("{breachName}")]
public Task<BreachDetails?> GetBreach([FromRoute] string breachName) =>
_pwnedBreachesClient.GetBreachAsync(breachName);
pwnedBreachesClient.GetBreachAsync(breachName);

[HttpGet, Route("headers/{domain}")]
public Task<BreachHeader[]> GetBreaches([FromRoute] string? domain) =>
_pwnedBreachesClient.GetBreachesAsync(domain);
pwnedBreachesClient.GetBreachesAsync(domain);

[HttpGet, Route("{account}/breaches")]
public Task<BreachDetails[]> GetBreachesForAccount([FromRoute] string account) =>
_pwnedBreachesClient.GetBreachesForAccountAsync(account);
pwnedBreachesClient.GetBreachesForAccountAsync(account);

[HttpGet, Route("{account}/headers")]
public Task<BreachHeader[]> GetBreachHeadersForAccount([FromRoute] string account) =>
_pwnedBreachesClient.GetBreachHeadersForAccountAsync(account);
pwnedBreachesClient.GetBreachHeadersForAccountAsync(account);

[HttpGet, Route("dataclasses")]
public Task<string[]> GetDataClasses() =>
_pwnedBreachesClient.GetDataClassesAsync();
pwnedBreachesClient.GetDataClassesAsync();
}
11 changes: 3 additions & 8 deletions samples/HaveIBeenPwned.WebApi/Controllers/PasswordsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ namespace HaveIBeenPwned.WebApi.Controllers;

[ApiController]
[Route("api/passwords")]
public class PasswordsController : ControllerBase
{
private readonly IPwnedPasswordsClient _pwnedPasswordsClient;

public PasswordsController(IPwnedPasswordsClient pwnedPasswordsClient) =>
_pwnedPasswordsClient = pwnedPasswordsClient;

public class PasswordsController(IPwnedPasswordsClient pwnedPasswordsClient) : ControllerBase
{
[HttpGet, Route("{plainTextPassword}")]
public Task<PwnedPassword> GetPwnedPassword([FromRoute] string plainTextPassword) =>
_pwnedPasswordsClient.GetPwnedPasswordAsync(plainTextPassword);
pwnedPasswordsClient.GetPwnedPasswordAsync(plainTextPassword);
}
11 changes: 3 additions & 8 deletions samples/HaveIBeenPwned.WebApi/Controllers/PastesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ namespace HaveIBeenPwned.WebApi.Controllers;

[ApiController]
[Route("api/pastes")]
public class PastesController : ControllerBase
{
private readonly IPwnedPastesClient _pwnedPastesClient;

public PastesController(IPwnedPastesClient pwnedPastesClient) =>
_pwnedPastesClient = pwnedPastesClient;

public class PastesController(IPwnedPastesClient pwnedPastesClient) : ControllerBase
{
[HttpGet, Route("{account}")]
public Task<Pastes[]> GetPaste([FromRoute] string account) =>
_pwnedPastesClient.GetPastesAsync(account);
pwnedPastesClient.GetPastesAsync(account);
}
11 changes: 3 additions & 8 deletions samples/HaveIBeenPwned.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@

namespace HaveIBeenPwned.WebApi;

public class Startup
{
readonly IConfiguration _configuration;

public Startup(IConfiguration configuration) =>
_configuration = configuration;

public class Startup(IConfiguration configuration)
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IPwnedClient>(
services => new PwnedClient(_configuration["HibpOptions:ApiKey"]!));
services => new PwnedClient(configuration["HibpOptions:ApiKey"]!));

services.AddControllers();
services.AddSwaggerGen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PwnedPasswordTests
InlineData("someValue", false)
]
public void PwnedPasswordReturnsCorrectValidityStateWhenConstructed(
string value, bool expected)
string? value, bool expected)
{
PwnedPassword pwnedPassword = new() { PlainTextPassword = value };
Assert.Equal(expected, pwnedPassword.IsInvalid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace HaveIBeenPwned.Client.AcceptanceTests;
[Trait("Category", "AcceptanceTests")]
public sealed class PwnedBreachesClientTests
{
private readonly IPwnedBreachesClient _breachesClient;

public PwnedBreachesClientTests() =>
_breachesClient = new PwnedClient(
private readonly IPwnedBreachesClient _breachesClient = new PwnedClient(
Environment.GetEnvironmentVariable("HibpOptions__ApiKey")!);

[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace HaveIBeenPwned.Client.AcceptanceTests;
[Trait("Category", "AcceptanceTests")]
public class PwnedClientTests
{
private readonly IPwnedClient _pwnedClient;

public PwnedClientTests() =>
_pwnedClient = new PwnedClient(
private readonly IPwnedClient _pwnedClient = new PwnedClient(
Environment.GetEnvironmentVariable("HibpOptions__ApiKey")!);

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace HaveIBeenPwned.Client.AcceptanceTests;
[Trait("Category", "AcceptanceTests")]
public sealed class PwnedPasswordsClientTests
{
private readonly IPwnedPasswordsClient _passwordsClient;

public PwnedPasswordsClientTests() =>
_passwordsClient = new PwnedClient(
private readonly IPwnedPasswordsClient _passwordsClient = new PwnedClient(
Environment.GetEnvironmentVariable("HibpOptions__ApiKey")!);

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ namespace HaveIBeenPwned.Client.AcceptanceTests;
[Trait("Category", "AcceptanceTests")]
public sealed class PwnedPastesClientTests
{
private readonly IPwnedPastesClient _pastesClient;

public PwnedPastesClientTests() =>
_pastesClient = new PwnedClient(
Environment.GetEnvironmentVariable("HibpOptions__ApiKey")!);
private readonly IPwnedPastesClient _pastesClient = new PwnedClient(
Environment.GetEnvironmentVariable("HibpOptions__ApiKey")!);

[Fact]
public async Task GetPastesAsyncReturnsNoPastes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class StringExtensionsTests
InlineData("", "")
]
public void ToSha1Hash_Returns_UselessValues_WhenGiven_UselessValues(
string value, string expected)
string? value, string? expected)
{
var actual = value.ToSha1Hash();
Assert.Equal(expected, actual);
Expand Down

0 comments on commit 73cf1f3

Please sign in to comment.