mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 15:11:10 +00:00
Centralizes and standardizes test fixtures.
This commit is contained in:
1 parent
dfc513da4f
commit
b648e2f054
294 files changed
+3807
-4437
No files matched your search
-38
@@ -1,38 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for the <see cref="Faker"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class BogusExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> random data generation support to the <see cref="Faker"/> class.
|
||||
/// </summary>
|
||||
/// <param name="faker">The faker instance to extend.</param>
|
||||
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
|
||||
public static DateOnly DateOnly(this Faker faker)
|
||||
{
|
||||
return System.DateOnly.FromDateTime(faker.Date.Past());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> random data generation within a specified interval support to the <see cref="Faker"/> class.
|
||||
/// </summary>
|
||||
/// <param name="faker">The faker instance to extend.</param>
|
||||
/// <param name="start">The start of the interval.</param>
|
||||
/// <param name="end">The end of the interval.</param>
|
||||
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
|
||||
public static DateOnly DateOnlyBetween(this Faker faker, DateOnly start, DateOnly end)
|
||||
{
|
||||
DateTime startDateTime = start.ToDateTime(TimeOnly.MinValue);
|
||||
DateTime endDateTime = end.ToDateTime(TimeOnly.MinValue);
|
||||
return System.DateOnly.FromDateTime(faker.Date.Between(startDateTime, endDateTime));
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DateOnlySpecimenBuilder : ISpecimenBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> support to the AutoFixture library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to process.</param>
|
||||
/// <param name="context">The context within which the specimen is created.</param>
|
||||
/// <returns>A specimen based on the request.</returns>
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (request is Type type && type == typeof(DateOnly))
|
||||
return DateOnly.FromDateTime(DateTime.Now);
|
||||
return new NoSpecimen();
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly?"/> support to the AutoFixture library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to process.</param>
|
||||
/// <param name="context">The context within which the specimen is created.</param>
|
||||
/// <returns>A specimen based on the request.</returns>
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (request is Type type && type == typeof(DateOnly?))
|
||||
return (DateOnly?)DateOnly.FromDateTime(DateTime.Now);
|
||||
return new NoSpecimen();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Fixtures.Core.Endpoints.FileSystemManagement;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Presentation.Api.Fixtures.Core.Endpoints.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -145,7 +145,7 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
|
||||
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -171,7 +171,7 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
|
||||
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
|
||||
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
|
||||
Assert.NotNull(errors);
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Presentation.Api.Fixtures.Core.Endpoints.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -185,7 +185,7 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -211,7 +211,7 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
|
||||
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
|
||||
Assert.NotNull(errors);
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Fixtures.Core.Endpoints.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -185,7 +185,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -211,7 +211,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
|
||||
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
|
||||
Assert.NotNull(errors);
|
||||
|
||||
-135
@@ -1,135 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for creating and managing a file system structure for integration testing purposes.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemStructureFixture
|
||||
{
|
||||
private static readonly bool s_hiddenAttributeIsSupported = DetectHiddenAttributeSupport();
|
||||
private readonly string _rootPath;
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the fixture can create hidden elements on the current platform and file system.
|
||||
/// </summary>
|
||||
internal static bool HiddenAttributeIsSupported => s_hiddenAttributeIsSupported;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemStructureFixture"/> class.
|
||||
/// </summary>
|
||||
public FileSystemStructureFixture()
|
||||
{
|
||||
_rootPath = System.IO.Path.Combine(AppContext.BaseDirectory, "TestFileSystemStructure_" + Guid.NewGuid());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a file system structure with three nested directories, each containing two text files.
|
||||
/// Makes the second nested directory and the first file in each directory hidden.
|
||||
/// </summary>
|
||||
/// <returns>The path to the root directory of the created file system structure.</returns>
|
||||
public string CreateFileSystemStructure()
|
||||
{
|
||||
// create the root directory
|
||||
Directory.CreateDirectory(_rootPath);
|
||||
string currentPath = _rootPath;
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
// create a nested subdirectory
|
||||
currentPath = System.IO.Path.Combine(currentPath, $"NestedDirectory_{i}");
|
||||
Directory.CreateDirectory(currentPath);
|
||||
|
||||
// create two text files in the current directory
|
||||
for (int j = 1; j <= 2; j++)
|
||||
{
|
||||
string filePath = System.IO.Path.Combine(currentPath, $"TestFile_{j}.txt");
|
||||
File.WriteAllText(filePath, _faker.Lorem.Paragraph());
|
||||
// make the first file in each directory hidden
|
||||
if (j == 1)
|
||||
SetHidden(filePath);
|
||||
}
|
||||
// make the second nested directory hidden
|
||||
if (i == 2)
|
||||
currentPath = SetHidden(currentPath);
|
||||
}
|
||||
return currentPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects whether the fixture can create hidden elements on the current platform and file system.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> when hidden elements can be created, otherwise <see langword="false"/>.</returns>
|
||||
private static bool DetectHiddenAttributeSupport()
|
||||
{
|
||||
// on Unix-like systems the fixture hides elements with the dot-prefix convention, which the file system always supports
|
||||
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
return true;
|
||||
// on Windows the fixture relies on the hidden file attribute, which some file systems (for example network drives) do not persist
|
||||
string probePath = System.IO.Path.Combine(AppContext.BaseDirectory, "lumina_hidden_attribute_probe_" + Guid.NewGuid());
|
||||
try
|
||||
{
|
||||
File.WriteAllText(probePath, string.Empty);
|
||||
File.SetAttributes(probePath, File.GetAttributes(probePath) | FileAttributes.Hidden);
|
||||
return (File.GetAttributes(probePath) & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(probePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.SetAttributes(probePath, FileAttributes.Normal);
|
||||
File.Delete(probePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the hidden attribute for a file or directory.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file or directory.</param>
|
||||
/// <returns>The path to the hidden file or directory.</returns>
|
||||
private static string SetHidden(string path)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
// On Unix-like systems, rename the file/directory to start with a dot
|
||||
string directory = System.IO.Path.GetDirectoryName(path)!;
|
||||
string name = System.IO.Path.GetFileName(path);
|
||||
string newPath = System.IO.Path.Combine(directory, "." + name);
|
||||
if (Directory.Exists(path))
|
||||
Directory.Move(path, newPath);
|
||||
else if (File.Exists(path))
|
||||
File.Move(path, newPath);
|
||||
path = newPath;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the file system structure created for testing purposes.
|
||||
/// </summary>
|
||||
public void CleanupFileSystemStructure()
|
||||
{
|
||||
if (Directory.Exists(_rootPath))
|
||||
Directory.Delete(_rootPath, recursive: true);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemTreeNodeResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeNodeResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single <see cref="FileSystemTreeNodeResponse"/> with a nested structure.
|
||||
/// </summary>
|
||||
/// <param name="currentDepth">The current depth in the tree structure. Default is 0 (root level).</param>
|
||||
/// <param name="maxDepth">The maximum depth of the tree structure. Default is 2.</param>
|
||||
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
|
||||
/// <returns>A <see cref="FileSystemTreeNodeResponse"/> with a nested structure.</returns>
|
||||
public FileSystemTreeNodeResponse Create(int currentDepth = 0, int maxDepth = 2, int maxChildren = 3)
|
||||
{
|
||||
FileSystemTreeNodeResponse response = new()
|
||||
{
|
||||
Path = _faker.System.FilePath(),
|
||||
Name = _faker.System.FileName(),
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = _faker.Random.Bool(),
|
||||
ChildrenLoaded = true,
|
||||
Children = []
|
||||
};
|
||||
if (currentDepth < maxDepth)
|
||||
{
|
||||
int childCount = _faker.Random.Int(1, maxChildren);
|
||||
for (int i = 0; i < childCount; i++)
|
||||
response.Children.Add(Create(currentDepth + 1, maxDepth, maxChildren));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FileSystemTreeNodeResponse"/> objects, each with a nested structure.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of root-level nodes to create. Default is 2.</param>
|
||||
/// <param name="maxDepth">The maximum depth of the tree structure for each root node. Default is 2.</param>
|
||||
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
|
||||
/// <returns>A list of <see cref="FileSystemTreeNodeResponse"/> objects with nested structures.</returns>
|
||||
public List<FileSystemTreeNodeResponse> CreateMany(int count = 2, int maxDepth = 2, int maxChildren = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create(0, maxDepth, maxChildren)).ToList();
|
||||
}
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for creating and managing a test image for integration testing purposes.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TestImageFixture : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the path of the created test image.
|
||||
/// </summary>
|
||||
public string ImagePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TestImageFixture"/> class.
|
||||
/// </summary>
|
||||
public TestImageFixture()
|
||||
{
|
||||
ImagePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"TestImage_{Guid.NewGuid()}.jpg");
|
||||
CreateTestImage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a test image file.
|
||||
/// </summary>
|
||||
private void CreateTestImage()
|
||||
{
|
||||
using (Image image = new Image<Rgba32>(100, 100))
|
||||
image.Save(ImagePath, new JpegEncoder());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the fixture, ensuring the test image is deleted.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (File.Exists(ImagePath))
|
||||
File.Delete(ImagePath);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.Fixtures.Core.Endpoints.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -89,7 +89,7 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -114,7 +114,7 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
|
||||
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
|
||||
Assert.NotNull(errors);
|
||||
@@ -143,7 +143,7 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
|
||||
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
|
||||
Assert.NotNull(errors);
|
||||
|
||||
+126
-126
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Converters;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.WrittenContentLibrary.BookLibrary.Books.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -64,7 +64,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithValidData_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
|
||||
@@ -128,7 +128,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
// ISBNs checks
|
||||
Assert.Equal(bookRequest.ISBNs!.Count, bookResponse.ISBNs.Count);
|
||||
var requestIsbnData = bookRequest.ISBNs.Select(isbn => new { isbn.Value, isbn.Format }).OrderBy(x => x.Value).ToList();
|
||||
var responseIsbnData = bookResponse.ISBNs.Select(isbn => new { Value = isbn.Value, Format = isbn.Format }).OrderBy(x => x.Value).ToList();
|
||||
var responseIsbnData = bookResponse.ISBNs.Select(isbn => new { isbn.Value, isbn.Format }).OrderBy(x => x.Value).ToList();
|
||||
Assert.Equal(requestIsbnData.Count, responseIsbnData.Count);
|
||||
for (int i = 0; i < requestIsbnData.Count; i++)
|
||||
{
|
||||
@@ -138,7 +138,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
|
||||
// ratings checks
|
||||
Assert.Equal(bookRequest.Ratings!.Count, bookResponse.Ratings.Count);
|
||||
var requestRatingData = bookRequest.Ratings.Select(r => new { Source = r.Source, r.Value, r.MaxValue, r.VoteCount }).OrderBy(x => x.Source).ToList();
|
||||
var requestRatingData = bookRequest.Ratings.Select(r => new { r.Source, r.Value, r.MaxValue, r.VoteCount }).OrderBy(x => x.Source).ToList();
|
||||
var responseRatingData = bookResponse.Ratings.Select(r => new { Source = r.Source.Value, r.Value, r.MaxValue, VoteCount = r.VoteCount.Value }).OrderBy(x => x.Source).ToList();
|
||||
Assert.Equal(requestRatingData.Count, responseRatingData.Count);
|
||||
for (int i = 0; i < requestRatingData.Count; i++)
|
||||
@@ -169,7 +169,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyTitle_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Title = null! } };
|
||||
|
||||
// Act
|
||||
@@ -183,7 +183,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthTitle_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Title = new Faker().Random.String2(300) } };
|
||||
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOriginalTitle_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { OriginalTitle = null! } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -208,7 +208,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthOriginalTitle_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { OriginalTitle = new Faker().Random.String2(300) } };
|
||||
|
||||
// Act
|
||||
@@ -222,7 +222,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyDescription_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Description = null! } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -233,7 +233,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthDescription_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Description = new Faker().Random.String2(2001) } };
|
||||
|
||||
// Act
|
||||
@@ -247,7 +247,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullReleaseInfo_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { ReleaseInfo = null! } };
|
||||
|
||||
// Act
|
||||
@@ -261,7 +261,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOriginalReleaseYear_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { ReleaseInfo = bookRequest.Metadata.ReleaseInfo! with { OriginalReleaseYear = null! } } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -272,7 +272,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidValueOriginalReleaseYear_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { ReleaseInfo = bookRequest.Metadata.ReleaseInfo! with { OriginalReleaseYear = 10000 } } };
|
||||
|
||||
// Act
|
||||
@@ -286,7 +286,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyReReleaseYear_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { ReleaseInfo = bookRequest.Metadata.ReleaseInfo! with { ReReleaseYear = null!, ReReleaseDate = null } } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -297,7 +297,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidValueReReleaseYear_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -319,7 +319,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyReleaseCountry_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { ReleaseInfo = bookRequest.Metadata.ReleaseInfo! with { ReleaseCountry = null! } } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -330,7 +330,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidValueReleaseCountry_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -350,7 +350,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyReleaseVersion_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { ReleaseInfo = bookRequest.Metadata.ReleaseInfo! with { ReleaseVersion = null! } } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -361,7 +361,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidValueReleasVersion_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -381,7 +381,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenReReleaseYearIsAfterOriginalReleaseYear_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -400,7 +400,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenReReleaseYearIsBeforeReleaseYear_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -422,7 +422,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenReReleaseDateIsAfterOriginalReleaseDate_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -441,7 +441,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenReReleaseDateIsBeforeReleaseDate_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -463,7 +463,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullGenres_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Genres = null! } };
|
||||
|
||||
// Act
|
||||
@@ -477,12 +477,12 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyGenreName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
{
|
||||
Genres = bookRequest.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = null } : genre).ToList()
|
||||
Genres = [.. bookRequest.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = null } : genre)]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -497,12 +497,12 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthGenreName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
{
|
||||
Genres = bookRequest.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(100) } : genre).ToList()
|
||||
Genres = [.. bookRequest.Metadata.Genres!.Select((genre, index) => index == 0 ? genre with { Name = new Faker().Random.String2(100) } : genre)]
|
||||
}
|
||||
};
|
||||
// Act
|
||||
@@ -516,7 +516,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullTags_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Tags = null! } };
|
||||
|
||||
// Act
|
||||
@@ -530,12 +530,12 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyTagName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
{
|
||||
Tags = bookRequest.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = null } : tag).ToList()
|
||||
Tags = [.. bookRequest.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = null } : tag)]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -550,12 +550,12 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthTagName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
{
|
||||
Tags = bookRequest.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(100) } : tag).ToList()
|
||||
Tags = [.. bookRequest.Metadata.Tags!.Select((tag, index) => index == 0 ? tag with { Name = new Faker().Random.String2(100) } : tag)]
|
||||
}
|
||||
};
|
||||
// Act
|
||||
@@ -569,7 +569,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyLanguage_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Language = null! } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -580,7 +580,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyLanguageCode_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Language = bookRequest.Metadata.Language! with { LanguageCode = null } } };
|
||||
|
||||
// Act
|
||||
@@ -594,7 +594,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthLanguageCode_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -617,7 +617,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyLanguageName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Language = bookRequest.Metadata.Language! with { LanguageName = null } } };
|
||||
|
||||
// Act
|
||||
@@ -631,7 +631,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthLanguageName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -654,7 +654,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyLanguageNativeName_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Language = bookRequest.Metadata.Language! with { NativeName = null } } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -665,7 +665,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthNativeLanguageName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -688,7 +688,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOriginalLanguage_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { OriginalLanguage = null! } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -699,7 +699,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOriginalLanguageCode_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { OriginalLanguage = bookRequest.Metadata.Language! with { LanguageCode = null } } };
|
||||
|
||||
// Act
|
||||
@@ -713,7 +713,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthOriginalLanguageCode_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -736,7 +736,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOriginalLanguageName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { OriginalLanguage = bookRequest.Metadata.Language! with { LanguageName = null } } };
|
||||
|
||||
// Act
|
||||
@@ -750,7 +750,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthOriginalLanguageName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -773,7 +773,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthOriginalNativeLanguageName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Metadata = bookRequest.Metadata! with
|
||||
@@ -796,7 +796,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOriginalLanguageNativeName_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { OriginalLanguage = bookRequest.Metadata.Language! with { NativeName = null } } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -807,7 +807,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyPublisher_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Publisher = null } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -818,7 +818,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthPublisher_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { Publisher = new Faker().Random.String2(150) } };
|
||||
|
||||
// Act
|
||||
@@ -832,7 +832,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyPageCount_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { PageCount = null } };
|
||||
|
||||
// Act & Assert
|
||||
@@ -843,7 +843,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNegativePageCount_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Metadata = bookRequest.Metadata! with { PageCount = -1 } };
|
||||
|
||||
// Act
|
||||
@@ -857,7 +857,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyFormat_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Format = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -868,7 +868,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidFormat_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Format = (BookFormat)99 };
|
||||
|
||||
// Act
|
||||
@@ -882,7 +882,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyEdition_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Edition = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -893,7 +893,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthEdition_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Edition = new Faker().Random.String2(100) };
|
||||
|
||||
// Act
|
||||
@@ -907,7 +907,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyVolumeNumber_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { VolumeNumber = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -918,7 +918,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNegativeVolumeNumber_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { VolumeNumber = -1 };
|
||||
|
||||
// Act
|
||||
@@ -932,7 +932,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptySeries_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Series = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -943,7 +943,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
//public async Task AddBook_WhenCalledWithEmptySeriesTitle_ShouldReturnUnprocessableEntity()
|
||||
//{
|
||||
// // Arrange
|
||||
// var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
// var bookRequest = _requestBookFixture.Create();
|
||||
// bookRequest = bookRequest with
|
||||
// {
|
||||
// Series = bookRequest.Series! with { Title = null }
|
||||
@@ -960,7 +960,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
//public async Task AddBook_WhenCalledWithInvalidLengthSeriesTitle_ShouldReturnUnprocessableEntity()
|
||||
//{
|
||||
// // Arrange
|
||||
// var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
// var bookRequest = _requestBookFixture.Create();
|
||||
// bookRequest = bookRequest with { Series = bookRequest.Series! with { Title = new Faker().Random.String2(300) } };
|
||||
|
||||
// // Act
|
||||
@@ -974,7 +974,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyAsin_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { ASIN = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -985,7 +985,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthAsin_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { ASIN = new Faker().Random.String2(15) };
|
||||
|
||||
// Act
|
||||
@@ -999,7 +999,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyGoodreadsId_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { GoodreadsId = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1010,7 +1010,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidGoodreadsId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { GoodreadsId = new Faker().Random.String2(2) };
|
||||
|
||||
// Act
|
||||
@@ -1024,7 +1024,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyLccn_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { LCCN = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1035,7 +1035,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLccn_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { LCCN = new Faker().Random.String2(200) };
|
||||
|
||||
// Act
|
||||
@@ -1049,7 +1049,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOclcNumber_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { OCLCNumber = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1060,7 +1060,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidOclcNumber_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { OCLCNumber = new Faker().Random.String2(200) };
|
||||
|
||||
// Act
|
||||
@@ -1074,7 +1074,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyOpenLibraryId_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { OpenLibraryId = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1085,7 +1085,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidOpenLibraryId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { OpenLibraryId = new Faker().Random.String2(200) };
|
||||
|
||||
// Act
|
||||
@@ -1099,7 +1099,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyLibraryThingId_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { LibraryThingId = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1110,7 +1110,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthLibraryThingId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { LibraryThingId = new Faker().Random.String2(200) };
|
||||
|
||||
// Act
|
||||
@@ -1124,7 +1124,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyGoogleBooksId_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { GoogleBooksId = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1135,7 +1135,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthGoogleBooksId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { GoogleBooksId = new Faker().Random.String2(20) };
|
||||
|
||||
// Act
|
||||
@@ -1149,7 +1149,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidGoogleBooksId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { GoogleBooksId = new Faker().Random.String2(11) + " " };
|
||||
|
||||
// Act
|
||||
@@ -1163,7 +1163,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyBarnesAndNobleId_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { BarnesAndNobleId = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1174,7 +1174,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthBarnesAndNobleId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { BarnesAndNobleId = new Faker().Random.String2(20) };
|
||||
|
||||
// Act
|
||||
@@ -1188,7 +1188,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidBarnesAndNobleId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { BarnesAndNobleId = new Faker().Random.String2(10) };
|
||||
|
||||
// Act
|
||||
@@ -1202,7 +1202,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyAppleBooksId_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { AppleBooksId = null };
|
||||
|
||||
// Act & Assert
|
||||
@@ -1213,7 +1213,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidAppleBooksId_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { AppleBooksId = new Faker().Random.String2(10) };
|
||||
|
||||
// Act
|
||||
@@ -1227,7 +1227,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullIsbns_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { ISBNs = null! };
|
||||
|
||||
// Act
|
||||
@@ -1241,10 +1241,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyIsbnValue_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
ISBNs = bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = null } : isbn).ToList()
|
||||
ISBNs = [.. bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = null } : isbn)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1258,10 +1258,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidIsbn10Value_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
ISBNs = bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn10 } : isbn).ToList()
|
||||
ISBNs = [.. bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn10 } : isbn)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1275,10 +1275,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidIsbn13Value_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
ISBNs = bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn13 } : isbn).ToList()
|
||||
ISBNs = [.. bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Value = new Faker().Random.String2(5), Format = IsbnFormat.Isbn13 } : isbn)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1292,10 +1292,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidIsbnFormat_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
ISBNs = bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Format = (IsbnFormat)99 } : isbn).ToList()
|
||||
ISBNs = [.. bookRequest.ISBNs!.Select((isbn, index) => index == 0 ? isbn with { Format = (IsbnFormat)99 } : isbn)]
|
||||
};
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
|
||||
@@ -1308,7 +1308,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullContributors_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Contributors = null! };
|
||||
|
||||
// Act
|
||||
@@ -1322,10 +1322,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullContributorName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1339,10 +1339,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyContributorDisplayName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = string.Empty } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = string.Empty } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1356,10 +1356,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullContributorDisplayName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1373,10 +1373,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorDisplayName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(150) } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(150) } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1390,10 +1390,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorLegalName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(150) } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(150) } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1407,10 +1407,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyContributorRole_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = null } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Role = null } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1424,11 +1424,11 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyContributorRoleName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Name = null } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Name = null } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1442,11 +1442,11 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorRoleName_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Name = new Faker().Random.String2(100) } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Name = new Faker().Random.String2(100) } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1460,11 +1460,11 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyContributorRoleCategory_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Category = null } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Category = null } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1478,11 +1478,11 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorRoleCategory_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Category = new Faker().Random.String2(100) } } : contributor).ToList()
|
||||
Contributors = [.. bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with
|
||||
{ Role = contributor.Role! with { Category = new Faker().Random.String2(100) } } : contributor)]
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1496,7 +1496,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNullRatings_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with { Ratings = null! };
|
||||
|
||||
// Act
|
||||
@@ -1510,10 +1510,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNegativeRatingValue_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Ratings = bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = -3 } : rating).ToList()
|
||||
Ratings = [.. bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = -3 } : rating)]
|
||||
};
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
|
||||
@@ -1526,10 +1526,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithRatingValueGreaterThanMaxValue_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Ratings = bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = 3, MaxValue = 2 } : rating).ToList()
|
||||
Ratings = [.. bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { Value = 3, MaxValue = 2 } : rating)]
|
||||
};
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
|
||||
@@ -1542,10 +1542,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNegativeMaxRatingValue_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Ratings = bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { MaxValue = -3 } : rating).ToList()
|
||||
Ratings = [.. bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { MaxValue = -3 } : rating)]
|
||||
};
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
|
||||
@@ -1558,10 +1558,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithEmptyRatingVoteCount_ShouldAddBook()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Ratings = bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = null } : rating).ToList()
|
||||
Ratings = [.. bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = null } : rating)]
|
||||
};
|
||||
// Act & Assert
|
||||
await AssertCreated(bookRequest);
|
||||
@@ -1571,10 +1571,10 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddBook_WhenCalledWithNegativeVoteCount_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
AddBookRequest bookRequest = _requestBookFixture.Create();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Ratings = bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = -3 } : rating).ToList()
|
||||
Ratings = [.. bookRequest.Ratings!.Select((rating, index) => index == 0 ? rating with { VoteCount = -3 } : rating)]
|
||||
};
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
|
||||
@@ -1597,7 +1597,7 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
|
||||
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
|
||||
Assert.NotNull(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString());
|
||||
Assert.NotEmpty(problemDetails["traceId"].GetString()!);
|
||||
|
||||
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
|
||||
Assert.NotNull(errors);
|
||||
|
||||
-278
@@ -1,278 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.WrittenContentLibrary.BookLibrary.Books.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AddBookRequest"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookRequestFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookRequestFixture"/> class.
|
||||
/// </summary>
|
||||
public AddBookRequestFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid request to add a book.
|
||||
/// </summary>
|
||||
/// <returns>The created request to add a book.</returns>
|
||||
public AddBookRequest CreateRequestBook()
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
ReleaseInfoDto releaseInfo = new Faker<ReleaseInfoDto>()
|
||||
.CustomInstantiator(f => new ReleaseInfoDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
|
||||
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
|
||||
.RuleFor(x => x.ReReleaseDate, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)))
|
||||
.RuleFor(x => x.ReReleaseYear, reReleaseYear)
|
||||
.RuleFor(x => x.ReleaseCountry, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.Generate();
|
||||
|
||||
Faker<GenreDto> genre = new Faker<GenreDto>()
|
||||
.CustomInstantiator(f => new GenreDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagDto> tag = new Faker<TagDto>()
|
||||
.CustomInstantiator(f => new TagDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorRoleDto> mediaContributorRole = new Faker<MediaContributorRoleDto>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
|
||||
.CustomInstantiator(f => new MediaContributorNameDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorDto> mediaContributor = new Faker<MediaContributorDto>()
|
||||
.CustomInstantiator(f => new MediaContributorDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
Faker<BookRatingDto> rating = new Faker<BookRatingDto>()
|
||||
.CustomInstantiator(f => new BookRatingDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.Value, _random.Next(1, 5))
|
||||
.RuleFor(e => e.MaxValue, 5)
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<LanguageInfoDto> originalLanguage = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<WrittenContentMetadataDto> metadata = new Faker<WrittenContentMetadataDto>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataDto(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.ReleaseInfo, releaseInfo)
|
||||
.RuleFor(p => p.Genres, f => genre.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Tags, f => tag.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Language, language)
|
||||
.RuleFor(x => x.OriginalLanguage, originalLanguage)
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300));
|
||||
|
||||
Faker<IsbnDto> isbn = new Faker<IsbnDto>()
|
||||
.CustomInstantiator(f => new IsbnDto(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(i => i.Value, f =>
|
||||
{
|
||||
bool isIsbn13 = f.Random.Bool();
|
||||
if (isIsbn13)
|
||||
{
|
||||
string prefix = f.Random.Bool() ? "978" : "979";
|
||||
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = f.Random.Number(0, 9);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
})
|
||||
.RuleFor(i => i.Format, (f, i) => i.Value!.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
|
||||
|
||||
return new Faker<AddBookRequest>()
|
||||
.CustomInstantiator(f => new AddBookRequest(
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!,
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.LibraryId, _fixture.Create<Guid>())
|
||||
.RuleFor(x => x.Path, f => f.System.FilePath())
|
||||
.RuleFor(x => x.Metadata, metadata)
|
||||
.RuleFor(x => x.Format, _fixture.Create<BookFormat>())
|
||||
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
|
||||
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
|
||||
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
|
||||
.RuleFor(x => x.LCCN, f =>
|
||||
{
|
||||
string letters = new(Enumerable.Range(0, f.Random.Number(0, 3))
|
||||
.Select(_ => f.Random.Char('a', 'z'))
|
||||
.ToArray());
|
||||
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
return letters + digits;
|
||||
})
|
||||
.RuleFor(x => x.OCLCNumber, f =>
|
||||
{
|
||||
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
|
||||
string prefix = f.Random.ArrayElement(prefixes);
|
||||
string number;
|
||||
switch (prefix)
|
||||
{
|
||||
case "ocm":
|
||||
number = f.Random.String2(8, "0123456789");
|
||||
break;
|
||||
case "ocn":
|
||||
number = f.Random.String2(f.Random.Number(9, 11), "0123456789");
|
||||
break;
|
||||
case "on":
|
||||
number = f.Random.String2(10, "0123456789");
|
||||
break;
|
||||
case "(OCoLC)":
|
||||
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
break;
|
||||
default:
|
||||
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
return number;
|
||||
}
|
||||
return prefix + number;
|
||||
})
|
||||
.RuleFor(x => x.OpenLibraryId, f =>
|
||||
{
|
||||
int firstDigit = f.Random.Number(1, 9);
|
||||
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
|
||||
char suffix = f.Random.ArrayElement(new[] { 'A', 'M', 'W' });
|
||||
return $"OL{firstDigit}{remainingDigits}{suffix}";
|
||||
})
|
||||
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.GoogleBooksId, f =>
|
||||
{
|
||||
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
return new string(Enumerable.Repeat(VALID_CHARS, 12)
|
||||
.Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])
|
||||
.ToArray());
|
||||
})
|
||||
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
|
||||
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
|
||||
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
|
||||
.RuleFor(p => p.ISBNs, f => isbn.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(p => p.Ratings, f => rating.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Contributors, f => mediaContributor.Generate(f.Random.Number(1, 5)));
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.WrittenContentLibrary.BookLibrary.Books.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Book"/> domain entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DomainBookFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DomainBookFixture"/> class.
|
||||
/// </summary>
|
||||
public DomainBookFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
ConfigureCustomDomainTypes();
|
||||
}
|
||||
|
||||
public Book CreateDomainBook()
|
||||
{
|
||||
return Book.Create(
|
||||
LibraryId.Create(_fixture.Create<Guid>()),
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<WrittenContentMetadata>(),
|
||||
_fixture.Create<BookFormat>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<BookSeries>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<List<Isbn>>(),
|
||||
_fixture.Create<List<MediaContributorId>>(),
|
||||
_fixture.Create<List<BookRating>>()
|
||||
).Value;
|
||||
}
|
||||
|
||||
private void ConfigureCustomDomainTypes()
|
||||
{
|
||||
_fixture.Register(() => Optional<string>.Some(_fixture.Create<string>()));
|
||||
_fixture.Register(() => Optional<int>.Some(_fixture.Create<int>()));
|
||||
|
||||
_fixture.Register(() => ReleaseInfo.Create(
|
||||
_fixture.Create<Optional<DateOnly>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<DateOnly>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Genre.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Tag.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => WrittenContentMetadata.Create(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<ReleaseInfo>(),
|
||||
_fixture.Create<List<Genre>>(),
|
||||
_fixture.Create<List<Tag>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Isbn.Create(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<IsbnFormat>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => BookRating.Create(
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<Optional<BookRatingSource>>(),
|
||||
_fixture.Create<Optional<int>>()
|
||||
).Value);
|
||||
}
|
||||
}
|
||||
+2
@@ -41,5 +41,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Presentation.Api\Lumina.Presentation.Api.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Lumina.Contracts.Fixtures\Lumina.Contracts.Fixtures.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Lumina.Presentation.Api.Fixtures\Lumina.Presentation.Api.Fixtures.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user