Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66bd5f6d74 |
No files matched your search
@@ -1,46 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using KinopoiskUnofficialInfo.ApiClient;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Kinopoisk.Tests
|
|
||||||
{
|
|
||||||
public class ApiModelExtensionsTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void ToPersonInfosShouldSkipPersonsWithoutNames()
|
|
||||||
{
|
|
||||||
var staff = new List<StaffResponse>
|
|
||||||
{
|
|
||||||
CreateStaff(1, "Иван Иванов", string.Empty),
|
|
||||||
CreateStaff(2, string.Empty, string.Empty),
|
|
||||||
CreateStaff(3, " ", " "),
|
|
||||||
CreateStaff(4, string.Empty, "John Smith")
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = staff.ToPersonInfos().ToArray();
|
|
||||||
|
|
||||||
Assert.Equal(2, result.Length);
|
|
||||||
Assert.Equal("Иван Иванов", result[0].Name);
|
|
||||||
Assert.Equal(1, result[0].SortOrder);
|
|
||||||
Assert.Equal("John Smith", result[1].Name);
|
|
||||||
Assert.Equal(2, result[1].SortOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static StaffResponse CreateStaff(
|
|
||||||
int id,
|
|
||||||
string nameRu,
|
|
||||||
string nameEn)
|
|
||||||
{
|
|
||||||
return new StaffResponse
|
|
||||||
{
|
|
||||||
StaffId = id,
|
|
||||||
NameRu = nameRu,
|
|
||||||
NameEn = nameEn,
|
|
||||||
PosterUrl = string.Empty,
|
|
||||||
ProfessionText = "Актёр",
|
|
||||||
ProfessionKey = StaffResponseProfessionKey.ACTOR
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Kinopoisk.Tests
|
|
||||||
{
|
|
||||||
public class RemoteImageUrlSanitizerTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public async Task SanitizeRemoteImageUrlDisposesRequestAndResponse()
|
|
||||||
{
|
|
||||||
using var handler = new TrackingHandler();
|
|
||||||
using var httpClient = new HttpClient(handler);
|
|
||||||
|
|
||||||
var sanitizer = new RemoteImageUrlSanitizer(httpClient);
|
|
||||||
|
|
||||||
var result = await sanitizer.SanitizeRemoteImageUrl(
|
|
||||||
"https://example.com/image.jpg");
|
|
||||||
|
|
||||||
Assert.Equal("https://example.com/image.jpg", result);
|
|
||||||
Assert.True(handler.RequestContent.IsDisposed);
|
|
||||||
Assert.True(handler.ResponseContent.IsDisposed);
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class TrackingHandler : HttpMessageHandler
|
|
||||||
{
|
|
||||||
public TrackingContent RequestContent { get; } = new TrackingContent();
|
|
||||||
|
|
||||||
public TrackingContent ResponseContent { get; } = new TrackingContent();
|
|
||||||
|
|
||||||
protected override Task<HttpResponseMessage> SendAsync(
|
|
||||||
HttpRequestMessage request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
request.Content = RequestContent;
|
|
||||||
|
|
||||||
return Task.FromResult(
|
|
||||||
new HttpResponseMessage(HttpStatusCode.OK)
|
|
||||||
{
|
|
||||||
Content = ResponseContent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class TrackingContent : HttpContent
|
|
||||||
{
|
|
||||||
public bool IsDisposed { get; private set; }
|
|
||||||
|
|
||||||
protected override Task SerializeToStreamAsync(
|
|
||||||
Stream stream,
|
|
||||||
TransportContext context)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool TryComputeLength(out long length)
|
|
||||||
{
|
|
||||||
length = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
IsDisposed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -257,7 +257,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
|||||||
public static IEnumerable<PersonInfo> ToPersonInfos(this ICollection<StaffResponse> src)
|
public static IEnumerable<PersonInfo> ToPersonInfos(this ICollection<StaffResponse> src)
|
||||||
{
|
{
|
||||||
var res = src.Select(s => s.ToPersonInfo())
|
var res = src.Select(s => s.ToPersonInfo())
|
||||||
.Where(s => s != null && !string.IsNullOrWhiteSpace(s.Name))
|
.Where(s => s != null)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ namespace Jellyfin.Plugin.Kinopoisk
|
|||||||
var currentUrl = url;
|
var currentUrl = url;
|
||||||
while (!currentUrl.Contains("no-poster"))
|
while (!currentUrl.Contains("no-poster"))
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, currentUrl);
|
var response = await _httpClient.SendAsync(
|
||||||
using var response = await _httpClient.SendAsync(
|
new HttpRequestMessage(HttpMethod.Get, currentUrl), HttpCompletionOption.ResponseHeadersRead);
|
||||||
request,
|
|
||||||
HttpCompletionOption.ResponseHeadersRead);
|
|
||||||
|
|
||||||
if ((int)response.StatusCode <= 299)
|
if ((int)response.StatusCode <= 299)
|
||||||
return currentUrl;
|
return currentUrl;
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace KinopoiskUnofficialInfo.ApiClient.Tests
|
|
||||||
{
|
|
||||||
public class BadSpouseSexConverterTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void ShouldDeserializeUnknownSpouseSex()
|
|
||||||
{
|
|
||||||
const string json =
|
|
||||||
"{\"personId\":1,\"name\":\"Test\",\"divorced\":false," +
|
|
||||||
"\"divorcedReason\":\"\",\"sex\":\"UNKNOWN\",\"children\":0," +
|
|
||||||
"\"webUrl\":\"\",\"relation\":\"\"}";
|
|
||||||
|
|
||||||
var settings = new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
ContractResolver = new DeclarationPatcherContractResolver()
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = JsonConvert.DeserializeObject<PersonResponse_spouses>(
|
|
||||||
json,
|
|
||||||
settings);
|
|
||||||
|
|
||||||
Assert.NotNull(result);
|
|
||||||
Assert.Equal(
|
|
||||||
(PersonResponse_spousesSex)(-1),
|
|
||||||
result.Sex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
<PackageReference Include="Moq" Version="4.18.4" />
|
<PackageReference Include="Moq" Version="4.18.4" />
|
||||||
<PackageReference Include="VCR.net" Version="0.1.3" />
|
<PackageReference Include="VCR.net" Version="0.1.3" />
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
|
|
||||||
namespace KinopoiskUnofficialInfo.ApiClient
|
|
||||||
{
|
|
||||||
public class BadSpouseSexConverter : StringEnumConverter
|
|
||||||
{
|
|
||||||
public override bool CanConvert(System.Type objectType)
|
|
||||||
=> objectType == typeof(PersonResponse_spousesSex);
|
|
||||||
|
|
||||||
public override object ReadJson(
|
|
||||||
JsonReader reader,
|
|
||||||
System.Type objectType,
|
|
||||||
object existingValue,
|
|
||||||
JsonSerializer serializer)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return base.ReadJson(reader, objectType, existingValue, serializer);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return (PersonResponse_spousesSex)(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@ namespace KinopoiskUnofficialInfo.ApiClient
|
|||||||
new BadIntegerConverter(),
|
new BadIntegerConverter(),
|
||||||
new BadDoubleConverter(),
|
new BadDoubleConverter(),
|
||||||
new BadProfessionKeyConverter(),
|
new BadProfessionKeyConverter(),
|
||||||
new BadSpouseSexConverter(),
|
|
||||||
new BadProductionStatusConverter(),
|
new BadProductionStatusConverter(),
|
||||||
new BadFilmSearchResponse_filmsTypeConverter(),
|
new BadFilmSearchResponse_filmsTypeConverter(),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user