diff options
| author | Bond_009 <bond.009@outlook.com> | 2021-03-21 03:26:51 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2021-03-21 03:26:51 +0100 |
| commit | 849ced470adf3ae122713e870e476b835c57d5ad (patch) | |
| tree | 1cf437b0b9707e88a2004570d04b150264109da6 | |
| parent | 1a0ce16f4d18b9a7850b52b299b4e6da15d40c53 (diff) | |
Add StartupControllerTests
| -rw-r--r-- | tests/Jellyfin.Server.Integration.Tests/Controllers/StartupControllerTests.cs | 61 | ||||
| -rw-r--r-- | tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj | 1 |
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/Jellyfin.Server.Integration.Tests/Controllers/StartupControllerTests.cs b/tests/Jellyfin.Server.Integration.Tests/Controllers/StartupControllerTests.cs new file mode 100644 index 000000000..cf4b9dd71 --- /dev/null +++ b/tests/Jellyfin.Server.Integration.Tests/Controllers/StartupControllerTests.cs @@ -0,0 +1,61 @@ +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Mime; +using System.Text.Json; +using System.Threading.Tasks; +using Jellyfin.Api.Models.StartupDtos; +using MediaBrowser.Common.Json; +using Xunit; +using Xunit.Priority; + +namespace Jellyfin.Server.Integration.Tests.Controllers +{ + public sealed class StartupControllerTests : IClassFixture<JellyfinApplicationFactory> + { + private readonly JellyfinApplicationFactory _factory; + private readonly JsonSerializerOptions _jsonOpions = JsonDefaults.Options; + + public StartupControllerTests(JellyfinApplicationFactory factory) + { + _factory = factory; + } + + [Fact] + [Priority(0)] + public async Task GetStartupConfiguration_EditConfig_Success() + { + var client = _factory.CreateClient(); + + using var res0 = await client.GetAsync("/Startup/Configuration").ConfigureAwait(false); + Assert.Equal(HttpStatusCode.OK, res0.StatusCode); + Assert.Equal(MediaTypeNames.Application.Json, res0.Content.Headers.ContentType?.MediaType); + + var content0 = await res0.Content.ReadAsStreamAsync().ConfigureAwait(false); + _ = await JsonSerializer.DeserializeAsync<StartupConfigurationDto>(content0, _jsonOpions).ConfigureAwait(false); + + var newConfig = new StartupConfigurationDto() + { + UICulture = "NewCulture", + MetadataCountryCode = "be", + PreferredMetadataLanguage = "nl" + }; + + var req1 = JsonSerializer.SerializeToUtf8Bytes(newConfig, _jsonOpions); + using var reqContent1 = new ByteArrayContent(req1); + reqContent1.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json); + var res1 = await client.PostAsync("/Startup/Configuration", reqContent1).ConfigureAwait(false); + Assert.Equal(HttpStatusCode.NoContent, res1.StatusCode); + + var res2 = await client.GetAsync("/Startup/Configuration").ConfigureAwait(false); + Assert.Equal(HttpStatusCode.OK, res2.StatusCode); + Assert.Equal(MediaTypeNames.Application.Json, res2.Content.Headers.ContentType?.MediaType); + + var content2 = await res2.Content.ReadAsStreamAsync().ConfigureAwait(false); + var config2 = await JsonSerializer.DeserializeAsync<StartupConfigurationDto>(content2, _jsonOpions).ConfigureAwait(false); + Assert.Equal(newConfig.UICulture, config2!.UICulture); + Assert.Equal(newConfig.MetadataCountryCode, config2.MetadataCountryCode); + Assert.Equal(newConfig.PreferredMetadataLanguage, config2.PreferredMetadataLanguage); + } + } +} diff --git a/tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj b/tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj index b0a38736a..34cef9005 100644 --- a/tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj +++ b/tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj @@ -17,6 +17,7 @@ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> <PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" /> + <PackageReference Include="Xunit.Priority" Version="1.1.6" /> <PackageReference Include="coverlet.collector" Version="3.0.3" /> <PackageReference Include="Moq" Version="4.16.0" /> </ItemGroup> |
