115 lines
3.0 KiB
C#
115 lines
3.0 KiB
C#
using FluentAssertions;
|
|
using FreeCode.Plugins;
|
|
using Xunit;
|
|
|
|
namespace FreeCode.Tests.Integration;
|
|
|
|
public sealed class PluginLoadingTests
|
|
{
|
|
[Fact]
|
|
public async Task LoadPluginsAsync_NoPluginDir_NoThrow()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
var act = () => sut.LoadPluginsAsync();
|
|
|
|
await act.Should().NotThrowAsync();
|
|
sut.GetLoadedPlugins().Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void GetLoadedPlugins_InitiallyEmpty()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
sut.GetLoadedPlugins().Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void GetLoadedPluginDetails_InitiallyEmpty()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
sut.GetLoadedPluginDetails().Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UnloadPluginAsync_UnknownId_NoThrow()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
var act = () => sut.UnloadPluginAsync("missing-plugin");
|
|
|
|
await act.Should().NotThrowAsync();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task EnablePluginAsync_UnknownId_NoThrow()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
var act = () => sut.EnablePluginAsync("missing-plugin");
|
|
|
|
await act.Should().NotThrowAsync();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DisablePluginAsync_UnknownId_NoThrow()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
var act = () => sut.DisablePluginAsync("missing-plugin");
|
|
|
|
await act.Should().NotThrowAsync();
|
|
}
|
|
|
|
[Fact]
|
|
public void GetPluginCommands_InitiallyEmpty()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
sut.GetPluginCommands().Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task InstallPluginAsync_InvalidSource_Throws()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
var missingPath = Path.Combine(Path.GetTempPath(), "free-code-plugin-missing-" + Guid.NewGuid().ToString("N"));
|
|
|
|
var act = () => sut.InstallPluginAsync(missingPath);
|
|
|
|
await act.Should().ThrowAsync<DirectoryNotFoundException>();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task InstallPluginAsync_EmptySource_ThrowsArgumentException()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
var act = () => sut.InstallPluginAsync(string.Empty);
|
|
|
|
await act.Should().ThrowAsync<ArgumentException>();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RefreshAsync_CompletesWithoutError()
|
|
{
|
|
using var testHome = new TestHomeDirectoryScope();
|
|
var sut = new PluginManager();
|
|
|
|
var act = () => sut.RefreshAsync();
|
|
|
|
await act.Should().NotThrowAsync();
|
|
}
|
|
}
|