diff options
Diffstat (limited to 'tests/Jellyfin.Api.Tests/Controllers')
3 files changed, 58 insertions, 139 deletions
diff --git a/tests/Jellyfin.Api.Tests/Controllers/BrandingControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/BrandingControllerTests.cs deleted file mode 100644 index 40933562d..000000000 --- a/tests/Jellyfin.Api.Tests/Controllers/BrandingControllerTests.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Net.Mime; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; -using MediaBrowser.Model.Branding; -using Xunit; - -namespace Jellyfin.Api.Tests -{ - public sealed class BrandingControllerTests : IClassFixture<JellyfinApplicationFactory> - { - private readonly JellyfinApplicationFactory _factory; - - public BrandingControllerTests(JellyfinApplicationFactory factory) - { - _factory = factory; - } - - [Fact] - public async Task GetConfiguration_ReturnsCorrectResponse() - { - // Arrange - var client = _factory.CreateClient(); - - // Act - var response = await client.GetAsync("/Branding/Configuration"); - - // Assert - 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 responseBody = await response.Content.ReadAsStreamAsync(); - _ = await JsonSerializer.DeserializeAsync<BrandingOptions>(responseBody); - } - - [Theory] - [InlineData("/Branding/Css")] - [InlineData("/Branding/Css.css")] - public async Task GetCss_ReturnsCorrectResponse(string url) - { - // Arrange - var client = _factory.CreateClient(); - - // Act - var response = await client.GetAsync(url); - - // Assert - Assert.True(response.IsSuccessStatusCode); - Assert.Equal("text/css", response.Content.Headers.ContentType?.MediaType); - Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet); - } - } -} diff --git a/tests/Jellyfin.Api.Tests/Controllers/DashboardControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/DashboardControllerTests.cs deleted file mode 100644 index 300b2697f..000000000 --- a/tests/Jellyfin.Api.Tests/Controllers/DashboardControllerTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -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); - } - } -} diff --git a/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs new file mode 100644 index 000000000..117083815 --- /dev/null +++ b/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using AutoFixture; +using AutoFixture.AutoMoq; +using Jellyfin.Api.Controllers; +using Jellyfin.Api.Helpers; +using Jellyfin.Api.Models.StreamingDtos; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; +using Moq; +using Xunit; + +namespace Jellyfin.Api.Tests.Controllers +{ + public class DynamicHlsControllerTests + { + [Theory] + [MemberData(nameof(GetSegmentLengths_Success_TestData))] + public void GetSegmentLengths_Success(long runtimeTicks, int segmentlength, double[] expected) + { + var res = DynamicHlsController.GetSegmentLengthsInternal(runtimeTicks, segmentlength); + Assert.Equal(expected.Length, res.Length); + for (int i = 0; i < expected.Length; i++) + { + Assert.Equal(expected[i], res[i]); + } + } + + public static IEnumerable<object[]> GetSegmentLengths_Success_TestData() + { + yield return new object[] { 0, 6, Array.Empty<double>() }; + yield return new object[] + { + TimeSpan.FromSeconds(3).Ticks, + 6, + new double[] { 3 } + }; + yield return new object[] + { + TimeSpan.FromSeconds(6).Ticks, + 6, + new double[] { 6 } + }; + yield return new object[] + { + TimeSpan.FromSeconds(3.3333333).Ticks, + 6, + new double[] { 3.3333333 } + }; + yield return new object[] + { + TimeSpan.FromSeconds(9.3333333).Ticks, + 6, + new double[] { 6, 3.3333333 } + }; + } + } +} |
