mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Standardizes test conventions and documentation
This commit is contained in:
1 parent
7aeed04255
commit
f42dc709de
190 files changed
+2180
-2814
No files matched your search
+7
-28
@@ -3,11 +3,12 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Plugins;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Plugins;
|
||||
using Lumina.Infrastructure.Core.Plugins;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Plugins;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -40,6 +41,7 @@ public class PluginDetectionSyncJobTests
|
||||
private readonly IPluginManager _mockPluginManager;
|
||||
private readonly ILogger<PluginDetectionSyncJob> _mockLogger;
|
||||
private readonly PluginLoadErrorDtoFixture _pluginLoadErrorDtoFixture;
|
||||
private readonly PluginEntityFixture _pluginEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginDetectionSyncJobTests"/> class.
|
||||
@@ -166,8 +168,8 @@ public class PluginDetectionSyncJobTests
|
||||
_mockPluginManager.GetPlugins().Returns([loadedPlugin]);
|
||||
_mockPluginRepository.UpsertAsync(Arg.Any<PluginEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Updated));
|
||||
PluginEntity loadedPluginRow = CreatePluginEntity(loadedPlugin.Id, loadedPlugin.Name, PluginLoadStatus.Loaded);
|
||||
PluginEntity stalePluginRow = CreatePluginEntity(Guid.NewGuid(), "Stale Plugin", PluginLoadStatus.Loaded);
|
||||
PluginEntity loadedPluginRow = _pluginEntityFixture.Create(id: loadedPlugin.Id, name: loadedPlugin.Name, loadStatus: PluginLoadStatus.Loaded);
|
||||
PluginEntity stalePluginRow = _pluginEntityFixture.Create(name: "Stale Plugin", loadStatus: PluginLoadStatus.Loaded);
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((IEnumerable<PluginEntity>)[loadedPluginRow, stalePluginRow]));
|
||||
_mockPluginRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -194,7 +196,7 @@ public class PluginDetectionSyncJobTests
|
||||
PluginLoadErrorDto loadError = _pluginLoadErrorDtoFixture.Create(
|
||||
assemblyName: "MyPlugin",
|
||||
errorMessage: "Failed to load plugin assembly 'MyPlugin.dll': unexpected error");
|
||||
PluginEntity staleLoadedRow = CreatePluginEntity(previouslyLoadedPlugin.Id, previouslyLoadedPlugin.Name, PluginLoadStatus.Loaded);
|
||||
PluginEntity staleLoadedRow = _pluginEntityFixture.Create(id: previouslyLoadedPlugin.Id, name: previouslyLoadedPlugin.Name, loadStatus: PluginLoadStatus.Loaded);
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((IEnumerable<PluginEntity>)[staleLoadedRow]));
|
||||
_mockPluginRepository.DeleteByIdAsync(previouslyLoadedPlugin.Id, Arg.Any<CancellationToken>())
|
||||
@@ -254,29 +256,6 @@ public class PluginDetectionSyncJobTests
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a stored plugin row with the provided identity.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin row.</param>
|
||||
/// <param name="name">The name of the plugin row.</param>
|
||||
/// <param name="loadStatus">The load status of the plugin row.</param>
|
||||
/// <returns>The created plugin entity.</returns>
|
||||
private static PluginEntity CreatePluginEntity(Guid id, string name, PluginLoadStatus loadStatus)
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Author = "Test Author",
|
||||
Version = "1.0.0",
|
||||
Description = "Test plugin description",
|
||||
LoadStatus = loadStatus,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derives the stable plugin Id expected for a failing plugin assembly, mirroring the detection job logic.
|
||||
/// </summary>
|
||||
@@ -285,6 +264,6 @@ public class PluginDetectionSyncJobTests
|
||||
private static Guid DeriveExpectedId(string assemblyName)
|
||||
{
|
||||
byte[] hash = SHA256.HashData(Encoding.UTF8.GetBytes(assemblyName));
|
||||
return new Guid(hash.Take(16).ToArray());
|
||||
return new Guid([.. hash.Take(16)]);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Core.Plugins;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
@@ -27,6 +27,7 @@ public class PluginInstallerTests : IDisposable
|
||||
{
|
||||
private readonly string _pluginsDirectory;
|
||||
private readonly PluginInstaller _sut;
|
||||
private readonly PluginsSettingsDtoFixture _pluginsSettingsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginInstallerTests"/> class.
|
||||
@@ -36,7 +37,7 @@ public class PluginInstallerTests : IDisposable
|
||||
_pluginsDirectory = Path.Combine(AppContext.BaseDirectory, $".test-plugins-{Guid.NewGuid():N}");
|
||||
ILogger<PluginInstaller> mockLogger = Substitute.For<ILogger<PluginInstaller>>();
|
||||
IOptions<PluginsSettingsDto> mockOptions = Substitute.For<IOptions<PluginsSettingsDto>>();
|
||||
mockOptions.Value.Returns(new PluginsSettingsDto { Directory = Path.GetFileName(_pluginsDirectory) });
|
||||
mockOptions.Value.Returns(_pluginsSettingsDtoFixture.Create(directory: Path.GetFileName(_pluginsDirectory)));
|
||||
_sut = new PluginInstaller(mockOptions, mockLogger);
|
||||
}
|
||||
|
||||
|
||||
+4
-24
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Core.Plugins;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -26,6 +27,7 @@ public class PluginSettingsStoreTests
|
||||
private readonly IPluginRepository _mockPluginRepository;
|
||||
private readonly ILogger<PluginSettingsStore> _mockLogger;
|
||||
private readonly PluginSettingsStore _sut;
|
||||
private readonly PluginEntityFixture _pluginEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginSettingsStoreTests"/> class.
|
||||
@@ -46,7 +48,7 @@ public class PluginSettingsStoreTests
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
Dictionary<string, string> expectedSettings = new() { ["ApiKey"] = "test-key", ["Enabled"] = "true" };
|
||||
PluginEntity pluginEntity = CreatePluginEntity(pluginId, JsonSerializer.Serialize(expectedSettings));
|
||||
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, settingsJson: JsonSerializer.Serialize(expectedSettings));
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(pluginEntity));
|
||||
|
||||
@@ -63,7 +65,7 @@ public class PluginSettingsStoreTests
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
PluginEntity pluginEntity = CreatePluginEntity(pluginId, settingsJson: null);
|
||||
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, includeSettingsJson: false);
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(pluginEntity));
|
||||
|
||||
@@ -103,26 +105,4 @@ public class PluginSettingsStoreTests
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a plugin entity with the provided identity and serialized settings.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin.</param>
|
||||
/// <param name="settingsJson">The serialized settings of the plugin.</param>
|
||||
/// <returns>The created plugin entity.</returns>
|
||||
private static PluginEntity CreatePluginEntity(Guid id, string? settingsJson)
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = id,
|
||||
Name = "Test Plugin",
|
||||
Author = "Test Author",
|
||||
Version = "1.0.0",
|
||||
Description = "Test plugin description",
|
||||
SettingsJson = settingsJson,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user