mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Adds plugin upload from the web client
This commit is contained in:
1 parent
d84823f6d2
commit
b3ffb5dfab
57 files changed
+2774
-16
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Plugins.Commands.InstallPlugin;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Plugins.Commands.InstallPlugin;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="InstallPluginCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InstallPluginCommandFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid <see cref="InstallPluginCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="archive">Optional. The archive stream of the uploaded plugin.</param>
|
||||
/// <param name="fileName">Optional. The file name of the uploaded plugin.</param>
|
||||
/// <returns>The created <see cref="InstallPluginCommand"/>.</returns>
|
||||
public InstallPluginCommand Create(
|
||||
Stream? archive = null,
|
||||
string? fileName = null)
|
||||
{
|
||||
return new InstallPluginCommand(
|
||||
archive ?? new MemoryStream(_faker.Random.Bytes(64)),
|
||||
fileName ?? $"{_faker.Hacker.Noun()}.dll");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="InstallPluginCommand"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="InstallPluginCommand"/> instances.</returns>
|
||||
public List<InstallPluginCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Fixtures.Core.Endpoints.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for building plugin archives used by the plugin integration tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TestPluginArchiveFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds a ZIP archive in memory containing a single plugin assembly entry.
|
||||
/// </summary>
|
||||
/// <param name="dllName">Optional name of the plugin assembly entry; a unique name is generated when not supplied.</param>
|
||||
/// <returns>The bytes of the plugin ZIP archive.</returns>
|
||||
public byte[] CreateZip(string? dllName = null)
|
||||
{
|
||||
string resolvedDllName = dllName ?? $"test-plugin-{Guid.NewGuid():N}.dll";
|
||||
|
||||
using MemoryStream stream = new();
|
||||
using (ZipArchive archive = new(stream, ZipArchiveMode.Create, leaveOpen: true))
|
||||
{
|
||||
ZipArchiveEntry dllEntry = archive.CreateEntry(resolvedDllName);
|
||||
using Stream entryStream = dllEntry.Open();
|
||||
entryStream.Write(CreateAssemblyBytes());
|
||||
}
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a single plugin assembly file in memory.
|
||||
/// </summary>
|
||||
/// <returns>The bytes of the plugin assembly.</returns>
|
||||
public byte[] CreateDll()
|
||||
{
|
||||
return CreateAssemblyBytes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the arbitrary bytes of a plugin assembly file.
|
||||
/// </summary>
|
||||
/// <returns>The plugin assembly bytes.</returns>
|
||||
private static byte[] CreateAssemblyBytes()
|
||||
{
|
||||
return [0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00];
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,16 @@ public class StubApiHttpClient : IApiHttpClient
|
||||
_getResponseFactories[endpoint] = () => throw exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the exception thrown when the specified PUT endpoint is called.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint for which to register the exception.</param>
|
||||
/// <param name="exception">The exception to throw.</param>
|
||||
public void RegisterPutException(string endpoint, ApiException exception)
|
||||
{
|
||||
_putResponseFactories[endpoint] = _ => throw exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the response returned when the specified PUT endpoint is called.
|
||||
/// </summary>
|
||||
@@ -138,6 +148,16 @@ public class StubApiHttpClient : IApiHttpClient
|
||||
_putResponseFactories[endpoint] = _ => response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the response factory invoked when the specified PUT endpoint is called.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint for which to register the response factory.</param>
|
||||
/// <param name="responseFactory">The factory that produces the response from the request payload.</param>
|
||||
public void RegisterPutResponseFactory(string endpoint, Func<object, object> responseFactory)
|
||||
{
|
||||
_putResponseFactories[endpoint] = responseFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the specified DELETE endpoint as succeeding.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Plugins;
|
||||
using Lumina.Presentation.Web.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="PluginDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PluginDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional identifier of the plugin.</param>
|
||||
/// <param name="name">Optional name of the plugin.</param>
|
||||
/// <param name="author">Optional author of the plugin.</param>
|
||||
/// <param name="version">Optional version of the plugin.</param>
|
||||
/// <param name="loadStatus">Optional load status of the plugin.</param>
|
||||
/// <returns>A configured <see cref="PluginDto"/> instance.</returns>
|
||||
public PluginDto Create(Guid? id = null, string? name = null, string? author = null, string? version = null, PluginLoadStatus? loadStatus = null)
|
||||
{
|
||||
return new PluginDto
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
Name = name ?? _faker.Hacker.Noun(),
|
||||
Author = author ?? _faker.Name.FullName(),
|
||||
Version = version ?? _faker.System.Semver(),
|
||||
Description = _faker.Lorem.Sentence(),
|
||||
LoadStatus = loadStatus ?? PluginLoadStatus.Loaded,
|
||||
LoadError = null,
|
||||
Settings = null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="PluginDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="PluginDto"/> instances.</returns>
|
||||
public List<PluginDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user