mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
Capitalizes the first word and adds the terminal period in the unit, integration and security tests. The AAA markers stay bare, the TODO bodies stay lowercase, and no assertion, payload, expected status code or test signature changes.
126 lines
4.7 KiB
C#
126 lines
4.7 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
|
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
|
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
|
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
|
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
#endregion
|
|
|
|
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="FileMapping"/> class.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class FileMappingTests
|
|
{
|
|
private readonly FileFixture _fileFixture = new();
|
|
|
|
[Theory]
|
|
[InlineData(true)] // Hidden file.
|
|
[InlineData(false)] // Visible file.
|
|
public void ToFileSystemTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly(bool isHidden)
|
|
{
|
|
// Arrange
|
|
File domainModel = _fileFixture.Create(isHidden: isHidden);
|
|
|
|
// Act
|
|
FileSystemTreeNodeResponse result = domainModel.ToFileSystemTreeNodeResponse();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(domainModel.Name, result.Name);
|
|
Assert.Equal(domainModel.Id.Path, result.Path);
|
|
Assert.Equal(domainModel.Type, result.ItemType);
|
|
Assert.Equal(domainModel.IsHidden, result.IsHidden);
|
|
Assert.False(result.IsExpanded);
|
|
Assert.False(result.ChildrenLoaded);
|
|
}
|
|
|
|
[Fact]
|
|
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
|
|
{
|
|
// Arrange
|
|
IEnumerable<File> domainModels =
|
|
[
|
|
_fileFixture.Create(isHidden: true),
|
|
_fileFixture.Create(isHidden: false)
|
|
];
|
|
|
|
// Act
|
|
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToFileSystemTreeNodeResponses();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(domainModels.Count(), result.Count());
|
|
|
|
List<FileSystemTreeNodeResponse> resultList = [.. result];
|
|
List<File> domainModelsList = [.. domainModels];
|
|
for (int i = 0; i < resultList.Count; i++)
|
|
{
|
|
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
|
|
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
|
|
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
|
|
Assert.Equal(domainModelsList[i].IsHidden, resultList[i].IsHidden);
|
|
Assert.False(resultList[i].IsExpanded);
|
|
Assert.False(resultList[i].ChildrenLoaded);
|
|
Assert.Empty(resultList[i].Children);
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)] // Hidden file.
|
|
[InlineData(false)] // Visible file.
|
|
public void ToResponse_WhenMappingFile_ShouldMapCorrectly(bool isHidden)
|
|
{
|
|
// Arrange
|
|
File domainModel = _fileFixture.Create(isHidden: isHidden);
|
|
|
|
// Act
|
|
FileResponse result = domainModel.ToResponse();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(domainModel.Id.Path, result.Path);
|
|
Assert.Equal(domainModel.Name, result.Name);
|
|
Assert.Equal(domainModel.DateCreated.Value, result.DateCreated);
|
|
Assert.Equal(domainModel.DateModified.Value, result.DateModified);
|
|
Assert.Equal(domainModel.Size, result.Size);
|
|
Assert.Equal(domainModel.IsHidden, result.IsHidden);
|
|
}
|
|
|
|
[Fact]
|
|
public void ToResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
|
|
{
|
|
// Arrange
|
|
IEnumerable<File> domainModels =
|
|
[
|
|
_fileFixture.Create(isHidden: true),
|
|
_fileFixture.Create(isHidden: false)
|
|
];
|
|
|
|
// Act
|
|
IEnumerable<FileResponse> result = domainModels.ToResponses();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(domainModels.Count(), result.Count());
|
|
|
|
List<FileResponse> resultList = [.. result];
|
|
List<File> domainModelsList = [.. domainModels];
|
|
for (int i = 0; i < resultList.Count; i++)
|
|
{
|
|
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
|
|
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
|
|
Assert.Equal(domainModelsList[i].Size, resultList[i].Size);
|
|
Assert.Equal(domainModelsList[i].DateCreated.Value, resultList[i].DateCreated);
|
|
Assert.Equal(domainModelsList[i].DateModified.Value, resultList[i].DateModified);
|
|
Assert.Equal(domainModelsList[i].IsHidden, resultList[i].IsHidden);
|
|
}
|
|
}
|
|
}
|