Skip to content

Commit

Permalink
Seal all private classes that are not extended
Browse files Browse the repository at this point in the history
.NET 7 includes a new analyzer [1] that checks for internal types that
can be sealed. We therefore need to seal all private classes that don't
have derived types to avoid CA1852 compiler warnings on upgrading to
.NET 7.

There's probably a case for also sealing all public types that we don't
intend to extend, but that can be deferred to a separate branch.

[1] dotnet/roslyn-analyzers#5594
  • Loading branch information
smfeest committed Mar 5, 2023
1 parent 4230b3b commit 4052b5f
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Buttercup.Web.Tests/Api/MutationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task AuthenticateReturnsPayloadWithSuccessFlagAccessTokenAndUserOnS
public async Task AuthenticateReturnsPayloadWithNoAccessTokenOrUserOnFailure() =>
Assert.Equal(new(false, null, null), await new AuthenticateFixture().Authenticate(false));

private class AuthenticateFixture
private sealed class AuthenticateFixture
{
public string AccessToken { get; } = "access-token";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ await fixture.AuthenticationMailer.SendPasswordResetLink(

#endregion

private class AuthenticationMailerFixture
private sealed class AuthenticationMailerFixture
{
public AuthenticationMailerFixture() =>
this.AuthenticationMailer = new(this.MockEmailSender.Object, this.MockLocalizer.Object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task AuthenticateReturnsNullIfPasswordIsIncorrect()
Assert.Null(await fixture.Authenticate());
}

private class AuthenticateFixture : AuthenticationManagerFixture
private sealed class AuthenticateFixture : AuthenticationManagerFixture
{
private const string Password = "user-password";
private const string HashedPassword = "hashed-password";
Expand Down Expand Up @@ -299,7 +299,7 @@ public async Task ChangePasswordReturnsTrueOnSuccess()
Assert.True(await fixture.ChangePassword());
}

private class ChangePasswordFixture : AuthenticationManagerFixture
private sealed class ChangePasswordFixture : AuthenticationManagerFixture
{
private const string CurrentPassword = "current-password";
private const string HashedCurrentPassword = "hashed-current-password";
Expand Down Expand Up @@ -422,7 +422,7 @@ public async Task PasswordResetTokenIsValidReturnsFalseIfInvalid()
Assert.False(await fixture.PasswordResetTokenIsValid());
}

private class PasswordResetTokenFixture : AuthenticationManagerFixture
private sealed class PasswordResetTokenFixture : AuthenticationManagerFixture
{
private const string Token = "password-reset-token";

Expand Down Expand Up @@ -563,7 +563,7 @@ public async Task ResetPasswordReturnsUserWithNewSecurityStampOnSuccess()
Assert.Equal(fixture.User with { SecurityStamp = fixture.NewSecurityStamp }, actual);
}

private class ResetPasswordFixture : AuthenticationManagerFixture
private sealed class ResetPasswordFixture : AuthenticationManagerFixture
{
private const string NewPassword = "new-password";
private const string Token = "password-reset-token";
Expand Down Expand Up @@ -662,7 +662,7 @@ public async Task SendPasswordResetLinkLogsIfEmailIsUnrecognized()
"password_reset_failure:unrecognized_email", null, fixture.SuppliedEmail);
}

private class SendPasswordResetLinkFixture : AuthenticationManagerFixture
private sealed class SendPasswordResetLinkFixture : AuthenticationManagerFixture
{
private SendPasswordResetLinkFixture(User? user)
{
Expand Down Expand Up @@ -751,7 +751,7 @@ public async Task SignInLogsEvent()
fixture.AssertAuthenticationEventLogged("sign_in", fixture.User.Id);
}

private class SignInFixture : AuthenticationManagerFixture
private sealed class SignInFixture : AuthenticationManagerFixture
{
public SignInFixture() =>
this.MockUserPrincipalFactory
Expand Down Expand Up @@ -806,7 +806,7 @@ public async Task SignOutDoesNotLogsIfNoUserPreviouslySignedIn()
x => x.LogEvent(fixture.MySqlConnection, "sign_out", null, null), Times.Never);
}

private class SignOutFixture : AuthenticationManagerFixture
private sealed class SignOutFixture : AuthenticationManagerFixture
{
private SignOutFixture(long? userId) => this.UserId = userId;

Expand Down Expand Up @@ -919,7 +919,7 @@ public async Task ValidatePrincipalSignsUserOutWhenStampIsIncorrect()
null));
}

private class ValidatePrincipalFixture : AuthenticationManagerFixture
private sealed class ValidatePrincipalFixture : AuthenticationManagerFixture
{
private const long UserId = 34;
private const string UserSecurityStamp = "user-security-stamp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void GenerateReturnsUrlSafeBase64()

#endregion

private class RandomTokenGeneratorFixture
private sealed class RandomTokenGeneratorFixture
{
public RandomTokenGeneratorFixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task IssueAccessTokenReturnsToken()
Assert.Equal(fixture.AccessToken, await fixture.IssueAccessToken());
}

private class IssueAccessTokenFixture : TokenAuthenticationServiceFixture
private sealed class IssueAccessTokenFixture : TokenAuthenticationServiceFixture
{
public IssueAccessTokenFixture() =>
this.MockAccessTokenEncoder
Expand Down Expand Up @@ -149,7 +149,7 @@ public async Task ValidateAccessTokenLogsAndReturnsUserOnSuccess()
LogLevel.Information, $"Access token successfully validated for user {fixture.User.Id}");
}

private class ValidateAccessTokenFixture : TokenAuthenticationServiceFixture
private sealed class ValidateAccessTokenFixture : TokenAuthenticationServiceFixture
{
private const string AccessToken = "sample-access-token";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public async Task ChangePasswordPostRedirectsToYourAccountOnSuccess()
Assert.Equal(nameof(AccountController.Show), redirectResult.ActionName);
}

private class ChangePasswordPostFixture : AccountControllerFixture
private sealed class ChangePasswordPostFixture : AccountControllerFixture
{
public ChangePasswordPostFixture() =>
this.MockLocalizer.SetupLocalizedString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public async Task SignInPostRedirectsDoesNotRedirectToExternalUrl()
Assert.Equal(nameof(HomeController.Index), redirectResult.ActionName);
}

private class SignInPostFixture : AuthenticationControllerFixture
private sealed class SignInPostFixture : AuthenticationControllerFixture
{
public SignInPostFixture() =>
this.MockLocalizer.SetupLocalizedString(
Expand Down
2 changes: 1 addition & 1 deletion src/Buttercup.Web.Tests/Controllers/HomeControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task IndexReturnsViewResultWithRecentlyAddedRecipes()

#endregion

private class HomeControllerFixture : IDisposable
private sealed class HomeControllerFixture : IDisposable
{
public HomeControllerFixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public async Task DeletePostDeletesRecipeAndRedirectsToIndexPage()

#endregion

private class RecipesControllerFixture : IDisposable
private sealed class RecipesControllerFixture : IDisposable
{
public RecipesControllerFixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void ProductionManifestCachesResult()

#endregion

private class AssetManifestSourceFixture
private sealed class AssetManifestSourceFixture
{
public AssetManifestSourceFixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public TimeZoneOptionsHelperFixture() =>
public TimeZoneOptionsHelper TimeZoneOptionsHelper { get; }
}

private class AllOptionsFixture : TimeZoneOptionsHelperFixture
private sealed class AllOptionsFixture : TimeZoneOptionsHelperFixture
{
private readonly List<TimeZoneInfo> timeZones = new();

Expand All @@ -153,7 +153,7 @@ public AllOptionsFixture AddFakeTimeZone(
}
}

private class OptionForTimeZoneFixture : TimeZoneOptionsHelperFixture
private sealed class OptionForTimeZoneFixture : TimeZoneOptionsHelperFixture
{
public string TimeZoneId { get; } = "Sample/Time_Zone";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void SetsTitleAttributeToUtcDateTime()
Assert.Equal("2001-02-03 21:22:23Z", (string)fixture.Output.Attributes["Title"].Value);
}

private class UserDateTimeTagHelperFixture
private sealed class UserDateTimeTagHelperFixture
{
public UserDateTimeTagHelperFixture()
{
Expand Down

0 comments on commit 4052b5f

Please sign in to comment.