mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Refactors the test fixtures and their consumers to compose other fixtures instead of instantiating models inline
This commit is contained in:
1 parent
0abda472c6
commit
3aadd6de84
157 files changed
+1312
-597
No files matched your search
+7
-3
@@ -24,20 +24,24 @@ public class ProblemDetailsDtoFixture
|
||||
/// <param name="status">Optional. The HTTP status code generated by the server.</param>
|
||||
/// <param name="detail">Optional. A detailed explanation specific to this occurrence of the problem.</param>
|
||||
/// <param name="instance">Optional. A URI reference that identifies the specific occurrence of the problem.</param>
|
||||
/// <param name="includeType">Whether the problem type should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeDetail">Whether the problem detail should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="ProblemDetailsDto"/>.</returns>
|
||||
public ProblemDetailsDto Create(
|
||||
string? type = null,
|
||||
string? title = null,
|
||||
int? status = null,
|
||||
string? detail = null,
|
||||
string? instance = null)
|
||||
string? instance = null,
|
||||
bool includeType = true,
|
||||
bool includeDetail = true)
|
||||
{
|
||||
return new ProblemDetailsDto
|
||||
{
|
||||
Type = type ?? "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
Type = includeType ? (type ?? "https://tools.ietf.org/html/rfc4918#section-11.2") : null,
|
||||
Title = title ?? _faker.Lorem.Word(),
|
||||
Status = status ?? _faker.Random.Int(400, 599),
|
||||
Detail = detail ?? _faker.Lorem.Sentence(),
|
||||
Detail = includeDetail ? (detail ?? _faker.Lorem.Sentence()) : null,
|
||||
Instance = instance
|
||||
};
|
||||
}
|
||||
|
||||
+3
-8
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,12 +9,12 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="MediaContributorDto"/> test data.
|
||||
/// Fixture class for the <see cref="MediaContributorDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MediaContributorDto"/> instance with randomized test data.
|
||||
@@ -31,11 +30,7 @@ public class MediaContributorDtoFixture
|
||||
{
|
||||
return new MediaContributorDto
|
||||
{
|
||||
Name = new MediaContributorNameDto
|
||||
{
|
||||
DisplayName = displayName ?? _faker.Name.FullName(),
|
||||
LegalName = legalName ?? _faker.Name.FullName()
|
||||
},
|
||||
Name = _mediaContributorNameDtoFixture.Create(displayName, legalName),
|
||||
Role = role ?? MediaContributorRole.Author
|
||||
};
|
||||
}
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaContributorNameDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorNameDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MediaContributorNameDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="displayName">Optional. The name by which the contributor is popularly known.</param>
|
||||
/// <param name="legalName">Optional. The legal name of the contributor.</param>
|
||||
/// <returns>A configured <see cref="MediaContributorNameDto"/> instance.</returns>
|
||||
public MediaContributorNameDto Create(
|
||||
string? displayName = null,
|
||||
string? legalName = null)
|
||||
{
|
||||
return new MediaContributorNameDto
|
||||
{
|
||||
DisplayName = displayName ?? _faker.Name.FullName(),
|
||||
LegalName = legalName ?? _faker.Name.FullName()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="MediaContributorNameDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaContributorNameDto"/> instances.</returns>
|
||||
public List<MediaContributorNameDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="AddRoleRequest"/> test data.
|
||||
/// Fixture class for the <see cref="AddRoleRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddRoleRequestFixture
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="DeleteRoleRequest"/> test data.
|
||||
/// Fixture class for the <see cref="DeleteRoleRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteRoleRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="UpdateUserRoleAndPermissionsRequest"/> test data.
|
||||
/// Fixture class for the <see cref="UpdateUserRoleAndPermissionsRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserRoleAndPermissionsRequestFixture
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="UpdatePluginSettingsRequest"/> test data.
|
||||
/// Fixture class for the <see cref="UpdatePluginSettingsRequest"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdatePluginSettingsRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="DeleteThemeRequest"/> test data.
|
||||
/// Fixture class for the <see cref="DeleteThemeRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteThemeRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="GetThemeArchiveRequest"/> test data.
|
||||
/// Fixture class for the <see cref="GetThemeArchiveRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeArchiveRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="GetThemeAssetRequest"/> test data.
|
||||
/// Fixture class for the <see cref="GetThemeAssetRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeAssetRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="SetCurrentThemeRequest"/> test data.
|
||||
/// Fixture class for the <see cref="SetCurrentThemeRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetCurrentThemeRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ChangePasswordRequest"/> test data.
|
||||
/// Fixture class for the <see cref="ChangePasswordRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="LoginRequest"/> test data.
|
||||
/// Fixture class for the <see cref="LoginRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="RecoverPasswordRequest"/> test data.
|
||||
/// Fixture class for the <see cref="RecoverPasswordRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordRequestFixture
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web;
|
||||
using Lumina.Presentation.Web.Common.Requests.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -28,6 +28,8 @@ public record AuthenticatedWebClient(HttpClient Client, string AntiforgeryToken)
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static partial class WebTestHelpers
|
||||
{
|
||||
private static readonly LoginRequestFixture s_loginRequestFixture = new();
|
||||
|
||||
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
|
||||
@@ -81,7 +83,7 @@ public static partial class WebTestHelpers
|
||||
{
|
||||
HttpRequestMessage loginRequest = new(HttpMethod.Post, LOGIN_ENDPOINT_PATH)
|
||||
{
|
||||
Content = JsonContent.Create(new LoginRequest(Username: username, Password: password))
|
||||
Content = JsonContent.Create(s_loginRequestFixture.Create(username: username, password: password))
|
||||
};
|
||||
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted
|
||||
loginRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support placeholder options type used as the validated options in validation options tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidationOptionsFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValidationOptionsFixture"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>A configured <see cref="ValidationOptionsFixture"/> instance.</returns>
|
||||
public ValidationOptionsFixture Create()
|
||||
{
|
||||
return new ValidationOptionsFixture();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user