|
|
|
@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
|
|
|
|
using Jellyfin.Api.ModelBinders;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Xunit;
|
|
|
|
@ -21,7 +22,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
var queryParamString = "lol,xd";
|
|
|
|
|
var queryParamType = typeof(string[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
|
new QueryCollection(new Dictionary<string, StringValues> { { queryParamName, new StringValues(queryParamString) } }),
|
|
|
|
@ -46,7 +47,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
var queryParamString = "42,0";
|
|
|
|
|
var queryParamType = typeof(int[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
|
new QueryCollection(new Dictionary<string, StringValues> { { queryParamName, new StringValues(queryParamString) } }),
|
|
|
|
@ -71,7 +72,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
var queryParamString = "How,Much";
|
|
|
|
|
var queryParamType = typeof(TestType[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
|
new QueryCollection(new Dictionary<string, StringValues> { { queryParamName, new StringValues(queryParamString) } }),
|
|
|
|
@ -96,7 +97,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
var queryParamString = "How,,Much";
|
|
|
|
|
var queryParamType = typeof(TestType[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
|
new QueryCollection(new Dictionary<string, StringValues> { { queryParamName, new StringValues(queryParamString) } }),
|
|
|
|
@ -122,7 +123,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
var queryParamString2 = "Much";
|
|
|
|
|
var queryParamType = typeof(TestType[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
@ -150,7 +151,7 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
var queryParamValues = Array.Empty<TestType>();
|
|
|
|
|
var queryParamType = typeof(TestType[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
@ -172,13 +173,13 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task BindModelAsync_ThrowsIfCommaDelimitedEnumArrayQueryIsInvalid()
|
|
|
|
|
public async Task BindModelAsync_EnumArrayQuery_BindValidOnly()
|
|
|
|
|
{
|
|
|
|
|
var queryParamName = "test";
|
|
|
|
|
var queryParamString = "🔥,😢";
|
|
|
|
|
var queryParamType = typeof(TestType[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
|
new QueryCollection(new Dictionary<string, StringValues> { { queryParamName, new StringValues(queryParamString) } }),
|
|
|
|
@ -189,20 +190,20 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
bindingContextMock.Setup(b => b.ModelType).Returns(queryParamType);
|
|
|
|
|
bindingContextMock.SetupProperty(b => b.Result);
|
|
|
|
|
|
|
|
|
|
Func<Task> act = async () => await modelBinder.BindModelAsync(bindingContextMock.Object);
|
|
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<FormatException>(act);
|
|
|
|
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
|
|
|
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
|
|
|
|
Assert.Empty((TestType[])bindingContextMock.Object.Result.Model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task BindModelAsync_ThrowsIfCommaDelimitedEnumArrayQueryIsInvalid2()
|
|
|
|
|
public async Task BindModelAsync_EnumArrayQuery_BindValidOnly_2()
|
|
|
|
|
{
|
|
|
|
|
var queryParamName = "test";
|
|
|
|
|
var queryParamString1 = "How";
|
|
|
|
|
var queryParamString2 = "😱";
|
|
|
|
|
var queryParamType = typeof(TestType[]);
|
|
|
|
|
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder();
|
|
|
|
|
var modelBinder = new CommaDelimitedArrayModelBinder(new NullLogger<CommaDelimitedArrayModelBinder>());
|
|
|
|
|
|
|
|
|
|
var valueProvider = new QueryStringValueProvider(
|
|
|
|
|
new BindingSource(string.Empty, string.Empty, false, false),
|
|
|
|
@ -217,9 +218,9 @@ namespace Jellyfin.Api.Tests.ModelBinders
|
|
|
|
|
bindingContextMock.Setup(b => b.ModelType).Returns(queryParamType);
|
|
|
|
|
bindingContextMock.SetupProperty(b => b.Result);
|
|
|
|
|
|
|
|
|
|
Func<Task> act = async () => await modelBinder.BindModelAsync(bindingContextMock.Object);
|
|
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<FormatException>(act);
|
|
|
|
|
await modelBinder.BindModelAsync(bindingContextMock.Object);
|
|
|
|
|
Assert.True(bindingContextMock.Object.Result.IsModelSet);
|
|
|
|
|
Assert.Single((TestType[])bindingContextMock.Object.Result.Model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|