Merge pull request #5291 from Bond-009/tests12
commit
da55462d92
@ -0,0 +1,86 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Api.Models;
|
||||||
|
using MediaBrowser.Common.Json;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Tests.Controllers
|
||||||
|
{
|
||||||
|
public sealed class DashboardControllerTests : IClassFixture<JellyfinApplicationFactory>
|
||||||
|
{
|
||||||
|
private readonly JellyfinApplicationFactory _factory;
|
||||||
|
private readonly JsonSerializerOptions _jsonOpions = JsonDefaults.GetOptions();
|
||||||
|
|
||||||
|
public DashboardControllerTests(JellyfinApplicationFactory factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetDashboardConfigurationPage_NonExistingPage_NotFound()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("web/ConfigurationPage?name=ThisPageDoesntExists").ConfigureAwait(false);
|
||||||
|
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetDashboardConfigurationPage_ExistingPage_CorrectPage()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("/web/ConfigurationPage?name=TestPlugin").ConfigureAwait(false);
|
||||||
|
|
||||||
|
Assert.True(response.IsSuccessStatusCode);
|
||||||
|
Assert.Equal(MediaTypeNames.Text.Html, response.Content.Headers.ContentType?.MediaType);
|
||||||
|
StreamReader reader = new StreamReader(typeof(TestPlugin).Assembly.GetManifestResourceStream("Jellyfin.Api.Tests.TestPage.html")!);
|
||||||
|
Assert.Equal(await response.Content.ReadAsStringAsync(), reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetDashboardConfigurationPage_BrokenPage_NotFound()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("/web/ConfigurationPage?name=BrokenPage").ConfigureAwait(false);
|
||||||
|
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetConfigurationPages_NoParams_AllConfigurationPages()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("/web/ConfigurationPages").ConfigureAwait(false);
|
||||||
|
|
||||||
|
Assert.True(response.IsSuccessStatusCode);
|
||||||
|
|
||||||
|
var res = await response.Content.ReadAsStreamAsync();
|
||||||
|
_ = await JsonSerializer.DeserializeAsync<ConfigurationPageInfo[]>(res, _jsonOpions);
|
||||||
|
// TODO: check content
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetConfigurationPages_True_MainMenuConfigurationPages()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("/web/ConfigurationPages?enableInMainMenu=true").ConfigureAwait(false);
|
||||||
|
|
||||||
|
Assert.True(response.IsSuccessStatusCode);
|
||||||
|
Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
|
||||||
|
Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet);
|
||||||
|
|
||||||
|
var res = await response.Content.ReadAsStreamAsync();
|
||||||
|
var data = await JsonSerializer.DeserializeAsync<ConfigurationPageInfo[]>(res, _jsonOpions);
|
||||||
|
Assert.Empty(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using Emby.Server.Implementations;
|
||||||
|
using Jellyfin.Server;
|
||||||
|
using MediaBrowser.Controller;
|
||||||
|
using MediaBrowser.Model.IO;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Tests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implementation of the abstract <see cref="ApplicationHost" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public class TestAppHost : CoreAppHost
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TestAppHost" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationPaths">The <see cref="ServerApplicationPaths" /> to be used by the <see cref="CoreAppHost" />.</param>
|
||||||
|
/// <param name="loggerFactory">The <see cref="ILoggerFactory" /> to be used by the <see cref="CoreAppHost" />.</param>
|
||||||
|
/// <param name="options">The <see cref="StartupOptions" /> to be used by the <see cref="CoreAppHost" />.</param>
|
||||||
|
/// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param>
|
||||||
|
/// <param name="collection">The <see cref="IServiceCollection"/> to be used by the <see cref="CoreAppHost"/>.</param>
|
||||||
|
public TestAppHost(
|
||||||
|
IServerApplicationPaths applicationPaths,
|
||||||
|
ILoggerFactory loggerFactory,
|
||||||
|
IStartupOptions options,
|
||||||
|
IFileSystem fileSystem,
|
||||||
|
IServiceCollection collection)
|
||||||
|
: base(
|
||||||
|
applicationPaths,
|
||||||
|
loggerFactory,
|
||||||
|
options,
|
||||||
|
fileSystem,
|
||||||
|
collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
|
||||||
|
{
|
||||||
|
foreach (var a in base.GetAssembliesWithPartsInternal())
|
||||||
|
{
|
||||||
|
yield return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return typeof(TestPlugin).Assembly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>TestPlugin</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>This is a Test Page.</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,43 @@
|
|||||||
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
|
using MediaBrowser.Common.Plugins;
|
||||||
|
using MediaBrowser.Model.Plugins;
|
||||||
|
using MediaBrowser.Model.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Tests
|
||||||
|
{
|
||||||
|
public class TestPlugin : BasePlugin<BasePluginConfiguration>, IHasWebPages
|
||||||
|
{
|
||||||
|
public TestPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
||||||
|
: base(applicationPaths, xmlSerializer)
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestPlugin? Instance { get; private set; }
|
||||||
|
|
||||||
|
public override Guid Id => new Guid("2d350a13-0bf7-4b61-859c-d5e601b5facf");
|
||||||
|
|
||||||
|
public override string Name => nameof(TestPlugin);
|
||||||
|
|
||||||
|
public override string Description => "Server test Plugin.";
|
||||||
|
|
||||||
|
public IEnumerable<PluginPageInfo> GetPages()
|
||||||
|
{
|
||||||
|
yield return new PluginPageInfo
|
||||||
|
{
|
||||||
|
Name = Name,
|
||||||
|
EmbeddedResourcePath = GetType().Namespace + ".TestPage.html"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new PluginPageInfo
|
||||||
|
{
|
||||||
|
Name = "BrokenPage",
|
||||||
|
EmbeddedResourcePath = GetType().Namespace + ".foobar"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue