mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Formats code comments as sentences in the tests.
Capitalizes the first word and adds the terminal period in the unit, integration and security tests. The AAA markers stay bare, the TODO bodies stay lowercase, and no assertion, payload, expected status code or test signature changes.
This commit is contained in:
1 parent
727aa33318
commit
057f557791
540 files changed
+3888
-3888
No files matched your search
+3
-3
@@ -29,9 +29,9 @@ public static class TestHttpContextFactory
|
||||
public static DefaultHttpContext Create(string? culture = "en-US", ClaimsPrincipal? user = null, ISession? session = null)
|
||||
{
|
||||
DefaultHttpContext httpContext = new();
|
||||
// provide a writable response body, so that executed IResult instances can be inspected by the tests
|
||||
// Provide a writable response body, so that executed IResult instances can be inspected by the tests.
|
||||
httpContext.Features.Set<IHttpResponseBodyFeature>(new StreamResponseBodyFeature(new MemoryStream()));
|
||||
// provide the minimal services needed by the result execution machinery (logging, options, JSON options)
|
||||
// Provide the minimal services needed by the result execution machinery (logging, options, JSON options).
|
||||
httpContext.RequestServices = CreateServiceProvider();
|
||||
httpContext.Request.RouteValues["culture"] = culture;
|
||||
if (user is not null)
|
||||
@@ -91,7 +91,7 @@ public static class TestHttpContextFactory
|
||||
public static ISession CreateSession()
|
||||
{
|
||||
ISession session = Substitute.For<ISession>();
|
||||
#pragma warning disable CS8601 // possible null reference assignment in the NSubstitute out-argument stub
|
||||
#pragma warning disable CS8601 // Possible null reference assignment in the NSubstitute out-argument stub.
|
||||
session.TryGetValue(Arg.Any<string>(), out Arg.Any<byte[]>()).Returns(callInfo =>
|
||||
{
|
||||
callInfo[1] = null;
|
||||
|
||||
@@ -32,7 +32,7 @@ public static partial class WebTestHelpers
|
||||
|
||||
private const string LOGIN_PAGE_PATH = "/en-us/auth/login";
|
||||
private const string LOGIN_ENDPOINT_PATH = "/en-us/auth/api-login";
|
||||
// the change password page renders an antiforgery token for the authenticated user without calling the remote API
|
||||
// The change password page renders an antiforgery token for the authenticated user without calling the remote API.
|
||||
private const string AUTHENTICATED_TOKEN_PAGE_PATH = "/en-us/auth/change-password";
|
||||
|
||||
[GeneratedRegex("name=\"__RequestVerificationToken\"[^>]*value=\"([^\"]*)\"")]
|
||||
@@ -57,7 +57,7 @@ public static partial class WebTestHelpers
|
||||
/// <returns>An HTTP client authenticated with the application's authentication cookie, together with an antiforgery token.</returns>
|
||||
public static async Task<AuthenticatedWebClient> CreateAuthenticatedClientAsync(WebApplicationFactory<Program> factory, string? username = "testuser", string? password = "TestPass123!")
|
||||
{
|
||||
// the application marks its cookies as secure, so the test client must communicate over HTTPS for the cookies to be sent back
|
||||
// The application marks its cookies as secure, so the test client must communicate over HTTPS for the cookies to be sent back.
|
||||
HttpClient client = factory.CreateClient(new WebApplicationFactoryClientOptions
|
||||
{
|
||||
BaseAddress = new Uri("https://localhost"),
|
||||
@@ -65,9 +65,9 @@ public static partial class WebTestHelpers
|
||||
});
|
||||
string antiforgeryToken = await GetAntiforgeryTokenAsync(client);
|
||||
await LoginAsync(client, username!, password!, antiforgeryToken);
|
||||
// the antiforgery token is bound to the authenticated user, because the antiforgery middleware runs after
|
||||
// The antiforgery token is bound to the authenticated user, because the antiforgery middleware runs after
|
||||
// authentication; the token captured from the anonymous login page is rejected with a 400 for authenticated
|
||||
// mutating requests, so a fresh token must be captured after the login
|
||||
// mutating requests, so a fresh token must be captured after the login.
|
||||
string authenticatedAntiforgeryToken = await GetAntiforgeryTokenAsync(client, AUTHENTICATED_TOKEN_PAGE_PATH);
|
||||
return new AuthenticatedWebClient(client, authenticatedAntiforgeryToken);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user