mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Merge pull request #74 from BinaryAlley/feature/update-forms-to-accept-enter-key-submit
Updates forms to accept Enter key submit
This commit is contained in:
12 files changed
+106
-47
No files matched your search
+4
-2
@@ -2,6 +2,7 @@
|
|||||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||||
|
using System;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||||
@@ -15,11 +16,12 @@ public static class AddMediaLibraryRequestMapping
|
|||||||
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
|
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">The request to be converted.</param>
|
/// <param name="request">The request to be converted.</param>
|
||||||
|
/// <param name="userId">The Id of the user owning the media library. Required.</param>
|
||||||
/// <returns>The converted command.</returns>
|
/// <returns>The converted command.</returns>
|
||||||
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
|
public static AddLibraryCommand ToCommand(this AddLibraryRequest request, Guid userId)
|
||||||
{
|
{
|
||||||
return new AddLibraryCommand(
|
return new AddLibraryCommand(
|
||||||
request.UserId,
|
userId,
|
||||||
request.Title,
|
request.Title,
|
||||||
request.LibraryType,
|
request.LibraryType,
|
||||||
request.ContentLocations
|
request.ContentLocations
|
||||||
|
|||||||
@@ -9,13 +9,11 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a request to add a media library.
|
/// Represents a request to add a media library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="UserId">The Id of the user owning the media library. Required.</param>
|
|
||||||
/// <param name="Title">The title of the media library. Required.</param>
|
/// <param name="Title">The title of the media library. Required.</param>
|
||||||
/// <param name="LibraryType">The type of the media library. Required.</param>
|
/// <param name="LibraryType">The type of the media library. Required.</param>
|
||||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
||||||
[DebuggerDisplay("Title: {Title}")]
|
[DebuggerDisplay("Title: {Title}")]
|
||||||
public record AddLibraryRequest(
|
public record AddLibraryRequest(
|
||||||
Guid UserId,
|
|
||||||
string? Title,
|
string? Title,
|
||||||
LibraryType? LibraryType,
|
LibraryType? LibraryType,
|
||||||
string[]? ContentLocations
|
string[]? ContentLocations
|
||||||
|
|||||||
+4
-1
@@ -8,6 +8,8 @@ using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
|||||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||||
using Mediator;
|
using Mediator;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -48,7 +50,8 @@ public class AddLibraryEndpoint : BaseEndpoint<AddLibraryRequest, IResult>
|
|||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
public override async Task<IResult> ExecuteAsync(AddLibraryRequest request, CancellationToken cancellationToken)
|
public override async Task<IResult> ExecuteAsync(AddLibraryRequest request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
string? user = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
|
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToCommand(Guid.Parse(user!)), cancellationToken).ConfigureAwait(false);
|
||||||
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Libraries.ADD_LIBRARY}/{result.Value.Id}", result.Value), Problem);
|
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Libraries.ADD_LIBRARY}/{result.Value.Id}", result.Value), Problem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-2
@@ -27,7 +27,6 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
|||||||
Description = "Creates a new media library and returns its details, including the location of the newly created resource.";
|
Description = "Creates a new media library and returns its details, including the location of the newly created resource.";
|
||||||
|
|
||||||
ExampleRequest = new AddLibraryRequest(
|
ExampleRequest = new AddLibraryRequest(
|
||||||
UserId: Guid.NewGuid(),
|
|
||||||
Title: "TV Shows",
|
Title: "TV Shows",
|
||||||
LibraryType: LibraryType.TvShow,
|
LibraryType: LibraryType.TvShow,
|
||||||
ContentLocations: [
|
ContentLocations: [
|
||||||
@@ -36,7 +35,6 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestParam(r => r.UserId, "The Id of the user owning the media library. Required.");
|
|
||||||
RequestParam(r => r.Title, "The title of the media library. Required.");
|
RequestParam(r => r.Title, "The title of the media library. Required.");
|
||||||
RequestParam(r => r.LibraryType, "The type of the media library. Required.");
|
RequestParam(r => r.LibraryType, "The type of the media library. Required.");
|
||||||
RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located. Required.");
|
RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located. Required.");
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Presentation.Web.Common.Enums.Library;
|
using Lumina.Presentation.Web.Common.Enums.Library;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -31,5 +31,5 @@ public class LibraryModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the collection of directories that contain the library files.
|
/// Gets or sets the collection of directories that contain the library files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Paths { get; set; } = [];
|
public List<string> ContentLocations { get; set; } = [];
|
||||||
}
|
}
|
||||||
+2
-1
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ public class LibraryManagementController : Controller
|
|||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
LibraryType = LibraryType.Book,
|
LibraryType = LibraryType.Book,
|
||||||
Paths = ["a", "b", "c"],
|
ContentLocations = ["a", "b", "c"],
|
||||||
Title = ""
|
Title = ""
|
||||||
};
|
};
|
||||||
return View("/Views/Library/Management/Item.cshtml", libraryModel);
|
return View("/Views/Library/Management/Item.cshtml", libraryModel);
|
||||||
|
|||||||
@@ -60,9 +60,20 @@
|
|||||||
</div>
|
</div>
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script type="text/javascript" defer>
|
<script type="text/javascript" defer>
|
||||||
|
document.getElementById('change-password-form').addEventListener('keypress', async (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target.closest('form');
|
||||||
|
await handleChangePassword(form);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('change-password-form').addEventListener('submit', async (event) => {
|
document.getElementById('change-password-form').addEventListener('submit', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.target;
|
await handleChangePassword(event.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleChangePassword(form) {
|
||||||
const txtCurrentPassword = form.querySelector('[name="CurrentPassword"]');
|
const txtCurrentPassword = form.querySelector('[name="CurrentPassword"]');
|
||||||
const txtNewPassword = form.querySelector('[name="NewPassword"]');
|
const txtNewPassword = form.querySelector('[name="NewPassword"]');
|
||||||
const txtNewPasswordConfirm = form.querySelector('[name="NewPasswordConfirm"]');
|
const txtNewPasswordConfirm = form.querySelector('[name="NewPasswordConfirm"]');
|
||||||
@@ -86,6 +97,8 @@
|
|||||||
divNewPasswordConfirm.classList.add('hidden');
|
divNewPasswordConfirm.classList.add('hidden');
|
||||||
divChangePasswordSubmit.classList.add('hidden');
|
divChangePasswordSubmit.classList.add('hidden');
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
@@ -54,9 +54,20 @@
|
|||||||
</div>
|
</div>
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script type="text/javascript" defer>
|
<script type="text/javascript" defer>
|
||||||
|
document.getElementById('login-form').addEventListener('keypress', async (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target.closest('form');
|
||||||
|
await handleLogin(form);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.target;
|
await handleLogin(event.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleLogin(form) {
|
||||||
const returnUrlInput = form.querySelector('[name="ReturnUrl"]');
|
const returnUrlInput = form.querySelector('[name="ReturnUrl"]');
|
||||||
const txtUsername = form.querySelector('[name="Username"]');
|
const txtUsername = form.querySelector('[name="Username"]');
|
||||||
const txtPassword = form.querySelector('[name="Password"]');
|
const txtPassword = form.querySelector('[name="Password"]');
|
||||||
@@ -83,7 +94,7 @@
|
|||||||
}
|
}
|
||||||
else if (data)
|
else if (data)
|
||||||
window.location.href = data;
|
window.location.href = data;
|
||||||
});
|
}
|
||||||
document.getElementById('btn-recover-password').addEventListener('click', () => {
|
document.getElementById('btn-recover-password').addEventListener('click', () => {
|
||||||
window.location.href = '@_urlService.GetAbsoluteUrl("RecoverPassword", "Auth")';
|
window.location.href = '@_urlService.GetAbsoluteUrl("RecoverPassword", "Auth")';
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,9 +48,20 @@
|
|||||||
</div>
|
</div>
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script type="text/javascript" defer>
|
<script type="text/javascript" defer>
|
||||||
|
document.getElementById('recover-password-form').addEventListener('keypress', async (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target.closest('form');
|
||||||
|
await handleRecoverPassword(form);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('recover-password-form').addEventListener('submit', async (event) => {
|
document.getElementById('recover-password-form').addEventListener('submit', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.target;
|
await handleRecoverPassword(event.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleRecoverPassword(form) {
|
||||||
const txtUsername = form.querySelector('[name="Username"]');
|
const txtUsername = form.querySelector('[name="Username"]');
|
||||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||||
const recoverPasswordSuccess = document.getElementById('recover-password-success');
|
const recoverPasswordSuccess = document.getElementById('recover-password-success');
|
||||||
@@ -73,7 +84,7 @@
|
|||||||
btnRedirectLogin.classList.replace('hidden', 'inline');
|
btnRedirectLogin.classList.replace('hidden', 'inline');
|
||||||
recoverPasswordSuccess.classList.replace('hidden', 'block');
|
recoverPasswordSuccess.classList.replace('hidden', 'block');
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
document.getElementById('btn-login').addEventListener('click', () => {
|
document.getElementById('btn-login').addEventListener('click', () => {
|
||||||
window.location.href = '@_urlService.GetAbsoluteUrl("Login", "Auth")';
|
window.location.href = '@_urlService.GetAbsoluteUrl("Login", "Auth")';
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -92,9 +92,20 @@
|
|||||||
</div>
|
</div>
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script type="text/javascript" defer>
|
<script type="text/javascript" defer>
|
||||||
|
document.getElementById('register-account-form').addEventListener('keypress', async (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target.closest('form');
|
||||||
|
await handleRegisterAccount(form);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('register-account-form').addEventListener('submit', async (event) => {
|
document.getElementById('register-account-form').addEventListener('submit', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.target;
|
await handleRegisterAccount(event.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleRegisterAccount(form) {
|
||||||
const txtUsername = form.querySelector('[name="Username"]');
|
const txtUsername = form.querySelector('[name="Username"]');
|
||||||
const txtPassword = form.querySelector('[name="Password"]');
|
const txtPassword = form.querySelector('[name="Password"]');
|
||||||
const txtPasswordConfirm = form.querySelector('[name="PasswordConfirm"]');
|
const txtPasswordConfirm = form.querySelector('[name="PasswordConfirm"]');
|
||||||
@@ -127,7 +138,7 @@
|
|||||||
totpImage.setAttribute('src', data.totpSecret);
|
totpImage.setAttribute('src', data.totpSecret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
document.querySelector('[name="Use2fa"]').addEventListener('change', function () {
|
document.querySelector('[name="Use2fa"]').addEventListener('change', function () {
|
||||||
const isChecked = this.checked;
|
const isChecked = this.checked;
|
||||||
document.getElementById('#register-two-fa-attention').classList.replace(
|
document.getElementById('#register-two-fa-attention').classList.replace(
|
||||||
|
|||||||
@@ -60,17 +60,17 @@
|
|||||||
<!-- Directories -->
|
<!-- Directories -->
|
||||||
<div class="form-row mt-10">
|
<div class="form-row mt-10">
|
||||||
<div class="form-label">
|
<div class="form-label">
|
||||||
<label asp-for="Paths">Directories</label>
|
<label asp-for="ContentLocations">Directories</label>
|
||||||
<span class="mandatory-field">*</span>:
|
<span class="mandatory-field">*</span>:
|
||||||
<img src="~/images/ui/add-directory.svg" alt="Add directory" id="add-media-directory" title="Add directory" class="add-form-table-row-icon ml-5" />
|
<img src="~/images/ui/add-directory.svg" alt="Add directory" id="add-media-directory" title="Add directory" class="add-form-table-row-icon ml-5" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-table w-100">
|
<div class="form-table w-100">
|
||||||
@for (int i = 0; i < Model.Paths.Count; i++)
|
@for (int i = 0; i < Model.ContentLocations.Count; i++)
|
||||||
{
|
{
|
||||||
<div class="form-table-row">
|
<div class="form-table-row">
|
||||||
<span title="@Model.Paths[i]">@Model.Paths[i]</span>
|
<span title="@Model.ContentLocations[i]">@Model.ContentLocations[i]</span>
|
||||||
<img src="~/images/ui/delete.svg" alt="Remove" title="Remove" class="remove-form-table-row-icon" />
|
<img src="~/images/ui/delete.svg" alt="Remove" title="Remove" class="remove-form-table-row-icon" />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,35 @@
|
|||||||
</div>
|
</div>
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script type="text/javascript" defer>
|
<script type="text/javascript" defer>
|
||||||
|
document.getElementById('add-media-library-form').addEventListener('keypress', async (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target.closest('form');
|
||||||
|
await handleAddMediaLibrary(form);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('add-media-library-form').addEventListener('submit', async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
await handleAddMediaLibrary(event.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleAddMediaLibrary(form) {
|
||||||
|
const formData = {
|
||||||
|
Id: form.querySelector('[name="Id"]').value || null,
|
||||||
|
Title: form.querySelector('[name="Title"]').value,
|
||||||
|
LibraryType: form.querySelector('.enlightenment-selected-text').textContent,
|
||||||
|
ContentLocations: Array.from(form.querySelectorAll('.form-table-row span'))
|
||||||
|
.map(span => span.textContent)
|
||||||
|
};
|
||||||
|
const result = await callApiPostAsync('/library/manage/item', formData);
|
||||||
|
if (result) {
|
||||||
|
// Optional: Handle successful response
|
||||||
|
// For example, redirect after success
|
||||||
|
// window.location.href = '/library/manage';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('add-media-directory').addEventListener('click', function () {
|
document.getElementById('add-media-directory').addEventListener('click', function () {
|
||||||
showFileSystemBrowserDialogAsync('C:\\Users\\', true, false, addNewPaths); // TODO: take path and include hidden elements from settings
|
showFileSystemBrowserDialogAsync('C:\\Users\\', true, false, addNewPaths); // TODO: take path and include hidden elements from settings
|
||||||
});
|
});
|
||||||
@@ -108,23 +137,5 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('add-media-library-form').addEventListener('submit', async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
const form = event.target;
|
|
||||||
const formData = {
|
|
||||||
Id: form.querySelector('[name="Id"]').value || null,
|
|
||||||
Title: form.querySelector('[name="Title"]').value,
|
|
||||||
LibraryType: form.querySelector('.enlightenment-selected-text').textContent,
|
|
||||||
Paths: Array.from(form.querySelectorAll('.form-table-row span'))
|
|
||||||
.map(span => span.textContent)
|
|
||||||
};
|
|
||||||
const result = await callApiPostAsync('/library/manage/item', formData);
|
|
||||||
if (result) {
|
|
||||||
// Optional: Handle successful response
|
|
||||||
// For example, redirect after success
|
|
||||||
// window.location.href = '/library/manage';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
+8
-8
@@ -20,19 +20,19 @@ public class AddMediaLibraryRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
Guid userId = Guid.NewGuid();
|
||||||
AddLibraryRequest request = new(
|
AddLibraryRequest request = new(
|
||||||
Guid.NewGuid(),
|
|
||||||
"My Library",
|
"My Library",
|
||||||
LibraryType.Book,
|
LibraryType.Book,
|
||||||
["C:/Books", "D:/Media/Books"]
|
["C:/Books", "D:/Media/Books"]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
AddLibraryCommand result = request.ToCommand();
|
AddLibraryCommand result = request.ToCommand(userId);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.UserId.Should().Be(request.UserId);
|
result.UserId.Should().Be(userId);
|
||||||
result.Title.Should().Be(request.Title);
|
result.Title.Should().Be(request.Title);
|
||||||
result.LibraryType.Should().Be(request.LibraryType);
|
result.LibraryType.Should().Be(request.LibraryType);
|
||||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||||
@@ -46,19 +46,19 @@ public class AddMediaLibraryRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
Guid userId = Guid.NewGuid();
|
||||||
AddLibraryRequest request = new(
|
AddLibraryRequest request = new(
|
||||||
Guid.NewGuid(),
|
|
||||||
"My Library",
|
"My Library",
|
||||||
libraryType,
|
libraryType,
|
||||||
["C:/Media"]
|
["C:/Media"]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
AddLibraryCommand result = request.ToCommand();
|
AddLibraryCommand result = request.ToCommand(userId);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.UserId.Should().Be(request.UserId);
|
result.UserId.Should().Be(userId);
|
||||||
result.Title.Should().Be(request.Title);
|
result.Title.Should().Be(request.Title);
|
||||||
result.LibraryType.Should().Be(libraryType);
|
result.LibraryType.Should().Be(libraryType);
|
||||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||||
@@ -76,15 +76,15 @@ public class AddMediaLibraryRequestMappingTests
|
|||||||
"F:/Reading Material"
|
"F:/Reading Material"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Guid userId = Guid.NewGuid();
|
||||||
AddLibraryRequest request = new(
|
AddLibraryRequest request = new(
|
||||||
Guid.NewGuid(),
|
|
||||||
"My Library",
|
"My Library",
|
||||||
LibraryType.Book,
|
LibraryType.Book,
|
||||||
contentLocations
|
contentLocations
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
AddLibraryCommand result = request.ToCommand();
|
AddLibraryCommand result = request.ToCommand(userId);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
|
|||||||
Reference in new issue
Block a user