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();
|
||||
|
||||
Assert.False(authenticateResult.Succeeded);
|
||||
Assert.Equal(errorMessage, authenticateResult.Failure.Message);
|
||||
Assert.Equal(errorMessage, authenticateResult.Failure?.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -100,7 +100,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||
var authorizationInfo = SetupUser();
|
||||
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]
|
||||
|
@ -112,7 +112,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||
var authenticateResult = await _sut.AuthenticateAsync();
|
||||
|
||||
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]
|
||||
|
@ -121,7 +121,7 @@ namespace Jellyfin.Api.Tests.Auth
|
|||
SetupUser();
|
||||
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)
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Jellyfin.Api.Tests
|
|||
|
||||
// Assert
|
||||
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();
|
||||
_ = await JsonSerializer.DeserializeAsync<BrandingOptions>(responseBody);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ namespace Jellyfin.Api.Tests
|
|||
|
||||
// Assert
|
||||
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()
|
||||
{
|
||||
var queryParamName = "test";
|
||||
var queryParamValues = new[] { "lol", "xd" };
|
||||
IReadOnlyList<string> queryParamValues = new[] { "lol", "xd" };
|
||||
var queryParamString = "lol,xd";
|
||||
var queryParamType = typeof(string[]);
|
||||
|
||||
|
@ -35,14 +35,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||
|
||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||
Assert.Equal((string[])bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
Assert.Equal((IReadOnlyList<string>?)bindingContextMock.Object?.Result.Model, queryParamValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedIntArrayQuery()
|
||||
{
|
||||
var queryParamName = "test";
|
||||
var queryParamValues = new[] { 42, 0 };
|
||||
IReadOnlyList<int> queryParamValues = new[] { 42, 0 };
|
||||
var queryParamString = "42,0";
|
||||
var queryParamType = typeof(int[]);
|
||||
|
||||
|
@ -60,14 +60,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||
|
||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||
Assert.Equal((int[])bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
Assert.Equal((IReadOnlyList<int>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedEnumArrayQuery()
|
||||
{
|
||||
var queryParamName = "test";
|
||||
var queryParamValues = new[] { TestType.How, TestType.Much };
|
||||
IReadOnlyList<TestType> queryParamValues = new[] { TestType.How, TestType.Much };
|
||||
var queryParamString = "How,Much";
|
||||
var queryParamType = typeof(TestType[]);
|
||||
|
||||
|
@ -85,14 +85,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||
|
||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindModelAsync_CorrectlyBindsValidCommaDelimitedEnumArrayQueryWithDoubleCommas()
|
||||
{
|
||||
var queryParamName = "test";
|
||||
var queryParamValues = new[] { TestType.How, TestType.Much };
|
||||
IReadOnlyList<TestType> queryParamValues = new[] { TestType.How, TestType.Much };
|
||||
var queryParamString = "How,,Much";
|
||||
var queryParamType = typeof(TestType[]);
|
||||
|
||||
|
@ -110,14 +110,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||
|
||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindModelAsync_CorrectlyBindsValidEnumArrayQuery()
|
||||
{
|
||||
var queryParamName = "test";
|
||||
var queryParamValues = new[] { TestType.How, TestType.Much };
|
||||
IReadOnlyList<TestType> queryParamValues = new[] { TestType.How, TestType.Much };
|
||||
var queryParamString1 = "How";
|
||||
var queryParamString2 = "Much";
|
||||
var queryParamType = typeof(TestType[]);
|
||||
|
@ -140,14 +140,14 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||
|
||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindModelAsync_CorrectlyBindsEmptyEnumArrayQuery()
|
||||
{
|
||||
var queryParamName = "test";
|
||||
var queryParamValues = Array.Empty<TestType>();
|
||||
IReadOnlyList<TestType> queryParamValues = Array.Empty<TestType>();
|
||||
var queryParamType = typeof(TestType[]);
|
||||
|
||||
var modelBinder = new CommaDelimitedArrayModelBinder();
|
||||
|
@ -168,7 +168,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|||
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
||||
|
||||
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
||||
Assert.Equal((TestType[])bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
Assert.Equal((IReadOnlyList<TestType>?)bindingContextMock.Object.Result.Model, queryParamValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Jellyfin.Api.Tests
|
|||
|
||||
// Assert
|
||||
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
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace Jellyfin.Api.Tests
|
|||
.Returns(user);
|
||||
|
||||
httpContextAccessorMock
|
||||
.Setup(h => h.HttpContext.Connection.RemoteIpAddress)
|
||||
.Setup(h => h.HttpContext!.Connection.RemoteIpAddress)
|
||||
.Returns(new IPAddress(0));
|
||||
|
||||
return new ClaimsPrincipal(identity);
|
||||
|
|
Loading…
Reference in New Issue
Block a user