Files
Nemera/tests/UnitTests/Nemera.Infrastructure.UnitTests/Core/Plugins/PluginManagerTests.cs
T
BinaryAlley b30cbd6b9e Adds bundled plugin trust and cross-platform native deployment
- embeds the append-only historical and deny trust lists in the API and marks matching bundled plugins as Official without blocking loading
- builds and records the current plugin manifest only for official release builds
- deploys the PDF native libraries for the supported Linux, macOS and Windows runtimes from the plugin dependency manifest
- records release hashes by appending only missing entries to master's manifest and rejects any diff that removes a line
- documents the release flow, the supported runtimes and the plugin installer limits
2026-11-28 18:00:00 +02:00

120 lines
3.5 KiB
C#

#region ========================================================================= USING =====================================================================================
using Nemera.Infrastructure.Core.Plugins;
using Nemera.Plugins.Contracts.Core.Plugins;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Nemera.Infrastructure.UnitTests.Core.Plugins;
/// <summary>
/// Contains unit tests for the <see cref="PluginManager"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginManagerTests
{
private PluginManager _sut = new([], [], new HashSet<Guid>());
[Fact]
public void GetPlugins_WhenCalled_ShouldReturnAllLoadedPlugins()
{
// Arrange
IPlugin firstPlugin = CreatePlugin(Guid.NewGuid(), "First Plugin");
IPlugin secondPlugin = CreatePlugin(Guid.NewGuid(), "Second Plugin");
_sut = new([firstPlugin, secondPlugin], [], new HashSet<Guid>());
// Act
IReadOnlyList<IPlugin> result = _sut.GetPlugins();
// Assert
Assert.Equal(2, result.Count);
Assert.Contains(firstPlugin, result);
Assert.Contains(secondPlugin, result);
}
[Fact]
public void GetPlugins_WhenNoPluginsWereLoaded_ShouldReturnEmptyList()
{
// Arrange
_sut = new([], [], new HashSet<Guid>());
// Act
IReadOnlyList<IPlugin> result = _sut.GetPlugins();
// Assert
Assert.Empty(result);
}
[Fact]
public void GetPlugin_WhenPluginWithIdWasLoaded_ShouldReturnThePlugin()
{
// Arrange
Guid pluginId = Guid.NewGuid();
IPlugin expectedPlugin = CreatePlugin(pluginId, "Expected Plugin");
_sut = new([expectedPlugin, CreatePlugin(Guid.NewGuid(), "Other Plugin")], [], new HashSet<Guid>());
// Act
IPlugin? result = _sut.GetPlugin(pluginId);
// Assert
Assert.Same(expectedPlugin, result);
}
[Fact]
public void GetPlugin_WhenPluginWithIdWasNotLoaded_ShouldReturnNull()
{
// Arrange
_sut = new([CreatePlugin(Guid.NewGuid(), "Loaded Plugin")], [], new HashSet<Guid>());
// Act
IPlugin? result = _sut.GetPlugin(Guid.NewGuid());
// Assert
Assert.Null(result);
}
[Fact]
public void IsOfficial_WhenPluginIsInTheOfficialSet_ShouldReturnTrue()
{
// Arrange
Guid pluginId = Guid.NewGuid();
_sut = new([CreatePlugin(pluginId, "Official Plugin")], [], new HashSet<Guid> { pluginId });
// Act
bool result = _sut.IsOfficial(pluginId);
// Assert
Assert.True(result);
}
[Fact]
public void IsOfficial_WhenPluginIsNotInTheOfficialSet_ShouldReturnFalse()
{
// Arrange
Guid pluginId = Guid.NewGuid();
_sut = new([CreatePlugin(pluginId, "Unofficial Plugin")], [], new HashSet<Guid>());
// Act
bool result = _sut.IsOfficial(pluginId);
// Assert
Assert.False(result);
}
/// <summary>
/// Creates a mocked plugin with the provided identity.
/// </summary>
/// <param name="id">The Id of the plugin.</param>
/// <param name="name">The name of the plugin.</param>
/// <returns>The created plugin mock.</returns>
private static IPlugin CreatePlugin(Guid id, string name)
{
IPlugin plugin = Substitute.For<IPlugin>();
plugin.Id.Returns(id);
plugin.Name.Returns(name);
return plugin;
}
}