Improve naming

pull/5580/head
Bond_009 4 years ago
parent c5079ebed5
commit 5253483ce4

@ -16,7 +16,7 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
public sealed class StartupControllerTests : IClassFixture<JellyfinApplicationFactory> public sealed class StartupControllerTests : IClassFixture<JellyfinApplicationFactory>
{ {
private readonly JellyfinApplicationFactory _factory; private readonly JellyfinApplicationFactory _factory;
private readonly JsonSerializerOptions _jsonOpions = JsonDefaults.Options; private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
public StartupControllerTests(JellyfinApplicationFactory factory) public StartupControllerTests(JellyfinApplicationFactory factory)
{ {
@ -24,93 +24,96 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
} }
[Fact] [Fact]
[Priority(0)] [Priority(-2)]
public async Task Configuration_EditConfig_Success() public async Task Configuration_EditConfig_Success()
{ {
var client = _factory.CreateClient(); var client = _factory.CreateClient();
using var res0 = await client.GetAsync("/Startup/Configuration").ConfigureAwait(false); var config = new StartupConfigurationDto()
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", UICulture = "NewCulture",
MetadataCountryCode = "be", MetadataCountryCode = "be",
PreferredMetadataLanguage = "nl" PreferredMetadataLanguage = "nl"
}; };
var req1 = JsonSerializer.SerializeToUtf8Bytes(newConfig, _jsonOpions); using var postContent = new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(config, _jsonOptions));
using var reqContent1 = new ByteArrayContent(req1); postContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json);
reqContent1.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json); using var postResponse = await client.PostAsync("/Startup/Configuration", postContent).ConfigureAwait(false);
var res1 = await client.PostAsync("/Startup/Configuration", reqContent1).ConfigureAwait(false); Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
Assert.Equal(HttpStatusCode.NoContent, res1.StatusCode);
using var getResponse = await client.GetAsync("/Startup/Configuration").ConfigureAwait(false);
var res2 = await client.GetAsync("/Startup/Configuration").ConfigureAwait(false); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
Assert.Equal(HttpStatusCode.OK, res2.StatusCode); Assert.Equal(MediaTypeNames.Application.Json, getResponse.Content.Headers.ContentType?.MediaType);
Assert.Equal(MediaTypeNames.Application.Json, res2.Content.Headers.ContentType?.MediaType);
using var responseStream = await getResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
var content2 = await res2.Content.ReadAsStreamAsync().ConfigureAwait(false); var newConfig = await JsonSerializer.DeserializeAsync<StartupConfigurationDto>(responseStream, _jsonOptions).ConfigureAwait(false);
var config2 = await JsonSerializer.DeserializeAsync<StartupConfigurationDto>(content2, _jsonOpions).ConfigureAwait(false); Assert.Equal(config.UICulture, newConfig!.UICulture);
Assert.Equal(newConfig.UICulture, config2!.UICulture); Assert.Equal(config.MetadataCountryCode, newConfig.MetadataCountryCode);
Assert.Equal(newConfig.MetadataCountryCode, config2.MetadataCountryCode); Assert.Equal(config.PreferredMetadataLanguage, newConfig.PreferredMetadataLanguage);
Assert.Equal(newConfig.PreferredMetadataLanguage, config2.PreferredMetadataLanguage);
} }
[Fact] [Fact]
[Priority(0)] [Priority(-2)]
public async Task User_EditUser_Success() public async Task User_DefaultUser_NameWithoutPassword()
{ {
var client = _factory.CreateClient(); var client = _factory.CreateClient();
using var res0 = await client.GetAsync("/Startup/User").ConfigureAwait(false); using var response = await client.GetAsync("/Startup/User").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, res0.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(MediaTypeNames.Application.Json, res0.Content.Headers.ContentType?.MediaType); Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
using var contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var user = await JsonSerializer.DeserializeAsync<StartupUserDto>(contentStream, _jsonOptions).ConfigureAwait(false);
Assert.NotEmpty(user!.Name);
Assert.Null(user.Password);
}
var content0 = await res0.Content.ReadAsStreamAsync().ConfigureAwait(false); [Fact]
var user = await JsonSerializer.DeserializeAsync<StartupUserDto>(content0, _jsonOpions).ConfigureAwait(false); [Priority(-1)]
public async Task User_EditUser_Success()
{
var client = _factory.CreateClient();
user!.Name = "NewName"; var user = new StartupUserDto()
user.Password = "NewPassword"; {
Name = "NewName",
Password = "NewPassword"
};
var req1 = JsonSerializer.SerializeToUtf8Bytes(user, _jsonOpions); using var postContent = new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(user, _jsonOptions));
using var reqContent1 = new ByteArrayContent(req1); postContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json);
reqContent1.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json); var postResponse = await client.PostAsync("/Startup/User", postContent).ConfigureAwait(false);
var res1 = await client.PostAsync("/Startup/User", reqContent1).ConfigureAwait(false); Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
Assert.Equal(HttpStatusCode.NoContent, res1.StatusCode);
var res2 = await client.GetAsync("/Startup/User").ConfigureAwait(false); var getResponse = await client.GetAsync("/Startup/User").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, res2.StatusCode); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
Assert.Equal(MediaTypeNames.Application.Json, res2.Content.Headers.ContentType?.MediaType); Assert.Equal(MediaTypeNames.Application.Json, getResponse.Content.Headers.ContentType?.MediaType);
var content2 = await res2.Content.ReadAsStreamAsync().ConfigureAwait(false); var contentStream = await getResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
var user2 = await JsonSerializer.DeserializeAsync<StartupUserDto>(content2, _jsonOpions).ConfigureAwait(false); var newUser = await JsonSerializer.DeserializeAsync<StartupUserDto>(contentStream, _jsonOptions).ConfigureAwait(false);
Assert.Equal(user.Name, user2!.Name); Assert.Equal(user.Name, newUser!.Name);
Assert.NotEmpty(user2.Password); Assert.NotEmpty(newUser.Password);
Assert.NotEqual(user.Password, user2.Password); Assert.NotEqual(user.Password, newUser.Password);
} }
[Fact] [Fact]
[Priority(1)] [Priority(0)]
public async Task CompleteWizard_Success() public async Task CompleteWizard_Success()
{ {
var client = _factory.CreateClient(); var client = _factory.CreateClient();
var res = await client.PostAsync("/Startup/Complete", new ByteArrayContent(Array.Empty<byte>())).ConfigureAwait(false); var response = await client.PostAsync("/Startup/Complete", new ByteArrayContent(Array.Empty<byte>())).ConfigureAwait(false);
Assert.Equal(HttpStatusCode.NoContent, res.StatusCode); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
} }
[Fact] [Fact]
[Priority(2)] [Priority(1)]
public async Task GetFirstUser_CompleteWizard_Unauthorized() public async Task GetFirstUser_CompleteWizard_Unauthorized()
{ {
var client = _factory.CreateClient(); var client = _factory.CreateClient();
using var res0 = await client.GetAsync("/Startup/User").ConfigureAwait(false); using var response = await client.GetAsync("/Startup/User").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.Unauthorized, res0.StatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
} }
} }
} }

Loading…
Cancel
Save