mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
Fix nullability errors in Jellyfin.Api.Tests
This commit is contained in:
parent
01355e0498
commit
445eec7f5f
@ -81,7 +81,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||||||
var authenticateResult = await _sut.AuthenticateAsync();
|
var authenticateResult = await _sut.AuthenticateAsync();
|
||||||
|
|
||||||
Assert.False(authenticateResult.Succeeded);
|
Assert.False(authenticateResult.Succeeded);
|
||||||
Assert.Equal(errorMessage, authenticateResult.Failure.Message);
|
Assert.Equal(errorMessage, authenticateResult.Failure?.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -100,7 +100,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||||||
var authorizationInfo = SetupUser();
|
var authorizationInfo = SetupUser();
|
||||||
var authenticateResult = await _sut.AuthenticateAsync();
|
var authenticateResult = await _sut.AuthenticateAsync();
|
||||||
|
|
||||||
Assert.True(authenticateResult.Principal.HasClaim(ClaimTypes.Name, authorizationInfo.User.Username));
|
Assert.True(authenticateResult.Principal?.HasClaim(ClaimTypes.Name, authorizationInfo.User.Username));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -112,7 +112,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||||||
var authenticateResult = await _sut.AuthenticateAsync();
|
var authenticateResult = await _sut.AuthenticateAsync();
|
||||||
|
|
||||||
var expectedRole = authorizationInfo.User.HasPermission(PermissionKind.IsAdministrator) ? UserRoles.Administrator : UserRoles.User;
|
var expectedRole = authorizationInfo.User.HasPermission(PermissionKind.IsAdministrator) ? UserRoles.Administrator : UserRoles.User;
|
||||||
Assert.True(authenticateResult.Principal.HasClaim(ClaimTypes.Role, expectedRole));
|
Assert.True(authenticateResult.Principal?.HasClaim(ClaimTypes.Role, expectedRole));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -121,7 +121,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||||||
SetupUser();
|
SetupUser();
|
||||||
var authenticatedResult = await _sut.AuthenticateAsync();
|
var authenticatedResult = await _sut.AuthenticateAsync();
|
||||||
|
|
||||||
Assert.Equal(_scheme.Name, authenticatedResult.Ticket.AuthenticationScheme);
|
Assert.Equal(_scheme.Name, authenticatedResult.Ticket?.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthorizationInfo SetupUser(bool isAdmin = false)
|
private AuthorizationInfo SetupUser(bool isAdmin = false)
|
||||||
|
@ -25,7 +25,7 @@ namespace Jellyfin.Api.Tests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());
|
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType?.ToString());
|
||||||
var responseBody = await response.Content.ReadAsStreamAsync();
|
var responseBody = await response.Content.ReadAsStreamAsync();
|
||||||
_ = await JsonSerializer.DeserializeAsync<BrandingOptions>(responseBody);
|
_ = await JsonSerializer.DeserializeAsync<BrandingOptions>(responseBody);
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ namespace Jellyfin.Api.Tests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
Assert.Equal("text/css; charset=utf-8", response.Content.Headers.ContentType.ToString());
|
Assert.Equal("text/css; charset=utf-8", response.Content.Headers.ContentType?.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedStringArrayQuery()
|
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedStringArrayQuery()
|
||||||
{
|
{
|
||||||
var queryParamName = "test";
|
var queryParamName = "test";
|
||||||
var queryParamValues = new[] { "lol", "xd" };
|
IReadOnlyList<string> queryParamValues = new[] { "lol", "xd" };
|
||||||
var queryParamString = "lol,xd";
|
var queryParamString = "lol,xd";
|
||||||
var queryParamType = typeof(string[]);
|
var queryParamType = typeof(string[]);
|
||||||
|
|
||||||
@ -35,14 +35,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||||
|
|
||||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||||
Assert.Equal((string[])bindingContextMock.Object.Result.Model, queryParamValues);
|
Assert.Equal((IReadOnlyList<string>?)bindingContextMock.Object?.Result.Model, queryParamValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedIntArrayQuery()
|
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedIntArrayQuery()
|
||||||
{
|
{
|
||||||
var queryParamName = "test";
|
var queryParamName = "test";
|
||||||
var queryParamValues = new[] { 42, 0 };
|
IReadOnlyList<int> queryParamValues = new[] { 42, 0 };
|
||||||
var queryParamString = "42,0";
|
var queryParamString = "42,0";
|
||||||
var queryParamType = typeof(int[]);
|
var queryParamType = typeof(int[]);
|
||||||
|
|
||||||
@ -60,14 +60,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||||
|
|
||||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||||
Assert.Equal((int[])bindingContextMock.Object.Result.Model, queryParamValues);
|
Assert.Equal((IReadOnlyList<int>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedEnumArrayQuery()
|
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedEnumArrayQuery()
|
||||||
{
|
{
|
||||||
var queryParamName = "test";
|
var queryParamName = "test";
|
||||||
var queryParamValues = new[] { TestType.How, TestType.Much };
|
IReadOnlyList<TestType> queryParamValues = new[] { TestType.How, TestType.Much };
|
||||||
var queryParamString = "How,Much";
|
var queryParamString = "How,Much";
|
||||||
var queryParamType = typeof(TestType[]);
|
var queryParamType = typeof(TestType[]);
|
||||||
|
|
||||||
@ -85,14 +85,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||||
|
|
||||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedEnumArrayQueryWithDoubleCommas()
|
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedEnumArrayQueryWithDoubleCommas()
|
||||||
{
|
{
|
||||||
var queryParamName = "test";
|
var queryParamName = "test";
|
||||||
var queryParamValues = new[] { TestType.How, TestType.Much };
|
IReadOnlyList<TestType> queryParamValues = new[] { TestType.How, TestType.Much };
|
||||||
var queryParamString = "How,,Much";
|
var queryParamString = "How,,Much";
|
||||||
var queryParamType = typeof(TestType[]);
|
var queryParamType = typeof(TestType[]);
|
||||||
|
|
||||||
@ -110,14 +110,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||||
|
|
||||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BindModelAsync_CorrectlyBindsValidEnumArrayQuery()
|
public async Task BindModelAsync_CorrectlyBindsValidEnumArrayQuery()
|
||||||
{
|
{
|
||||||
var queryParamName = "test";
|
var queryParamName = "test";
|
||||||
var queryParamValues = new[] { TestType.How, TestType.Much };
|
IReadOnlyList<TestType> queryParamValues = new[] { TestType.How, TestType.Much };
|
||||||
var queryParamString1 = "How";
|
var queryParamString1 = "How";
|
||||||
var queryParamString2 = "Much";
|
var queryParamString2 = "Much";
|
||||||
var queryParamType = typeof(TestType[]);
|
var queryParamType = typeof(TestType[]);
|
||||||
@ -140,14 +140,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||||
|
|
||||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BindModelAsync_CorrectlyBindsEmptyEnumArrayQuery()
|
public async Task BindModelAsync_CorrectlyBindsEmptyEnumArrayQuery()
|
||||||
{
|
{
|
||||||
var queryParamName = "test";
|
var queryParamName = "test";
|
||||||
var queryParamValues = Array.Empty<TestType>();
|
IReadOnlyList<TestType> queryParamValues = Array.Empty<TestType>();
|
||||||
var queryParamType = typeof(TestType[]);
|
var queryParamType = typeof(TestType[]);
|
||||||
|
|
||||||
var modelBinder = new CommaDelimitedArrayModelBinder();
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
||||||
@ -168,7 +168,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||||||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||||
|
|
||||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -30,7 +30,7 @@ namespace Jellyfin.Api.Tests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());
|
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType?.ToString());
|
||||||
|
|
||||||
// Write out for publishing
|
// Write out for publishing
|
||||||
var responseBody = await response.Content.ReadAsStringAsync();
|
var responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
@ -60,7 +60,7 @@ namespace Jellyfin.Api.Tests
|
|||||||
.Returns(user);
|
.Returns(user);
|
||||||
|
|
||||||
httpContextAccessorMock
|
httpContextAccessorMock
|
||||||
.Setup(h => h.HttpContext.Connection.RemoteIpAddress)
|
.Setup(h => h.HttpContext!.Connection.RemoteIpAddress)
|
||||||
.Returns(new IPAddress(0));
|
.Returns(new IPAddress(0));
|
||||||
|
|
||||||
return new ClaimsPrincipal(identity);
|
return new ClaimsPrincipal(identity);
|
||||||
|
Loading…
Reference in New Issue
Block a user