Add tests for SqliteItemRepository.(De)SerializeProviderIds
This commit is contained in:
parent
ea5bc90189
commit
874f92e93a
|
@ -897,7 +897,7 @@ namespace Emby.Server.Implementations.Data
|
|||
saveItemStatement.TryBind("@ExternalSeriesId", item.ExternalSeriesId);
|
||||
saveItemStatement.TryBind("@Tagline", item.Tagline);
|
||||
|
||||
saveItemStatement.TryBind("@ProviderIds", SerializeProviderIds(item));
|
||||
saveItemStatement.TryBind("@ProviderIds", SerializeProviderIds(item.ProviderIds));
|
||||
saveItemStatement.TryBind("@Images", SerializeImages(item.ImageInfos));
|
||||
|
||||
if (item.ProductionLocations.Length > 0)
|
||||
|
@ -968,10 +968,10 @@ namespace Emby.Server.Implementations.Data
|
|||
saveItemStatement.MoveNext();
|
||||
}
|
||||
|
||||
private static string SerializeProviderIds(BaseItem item)
|
||||
internal static string SerializeProviderIds(Dictionary<string, string> providerIds)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
foreach (var i in item.ProviderIds)
|
||||
foreach (var i in providerIds)
|
||||
{
|
||||
// Ideally we shouldn't need this IsNullOrWhiteSpace check,
|
||||
// but we're seeing some cases of bad data slip through
|
||||
|
@ -995,18 +995,13 @@ namespace Emby.Server.Implementations.Data
|
|||
return str.ToString();
|
||||
}
|
||||
|
||||
private static void DeserializeProviderIds(string value, BaseItem item)
|
||||
internal static void DeserializeProviderIds(string value, IHasProviderIds item)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.ProviderIds.Count > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parts = value.Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var part in parts)
|
||||
|
@ -1787,16 +1782,16 @@ namespace Emby.Server.Implementations.Data
|
|||
index++;
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(index))
|
||||
if (item.ProviderIds.Count == 0 && !reader.IsDBNull(index))
|
||||
{
|
||||
DeserializeProviderIds(reader.GetString(index), item);
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
if (query.DtoOptions.EnableImages && item.ImageInfos.Length == 0)
|
||||
if (query.DtoOptions.EnableImages)
|
||||
{
|
||||
if (!reader.IsDBNull(index))
|
||||
if (item.ImageInfos.Length == 0 && !reader.IsDBNull(index))
|
||||
{
|
||||
item.ImageInfos = DeserializeImages(reader.GetString(index));
|
||||
}
|
||||
|
|
|
@ -168,5 +168,62 @@ namespace Jellyfin.Server.Implementations.Tests.Data
|
|||
{
|
||||
Assert.Equal(expected, _sqliteItemRepository.SerializeImages(value));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> DeserializeProviderIds_Valid_TestData()
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
"Imdb=tt0119567",
|
||||
new Dictionary<string, string>()
|
||||
{
|
||||
{ "Imdb", "tt0119567" },
|
||||
}
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
"Imdb=tt0119567|Tmdb=330|TmdbCollection=328",
|
||||
new Dictionary<string, string>()
|
||||
{
|
||||
{ "Imdb", "tt0119567" },
|
||||
{ "Tmdb", "330" },
|
||||
{ "TmdbCollection", "328" },
|
||||
}
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
"MusicBrainzAlbum=9d363e43-f24f-4b39-bc5a-7ef305c677c7|MusicBrainzReleaseGroup=63eba062-847c-3b73-8b0f-6baf27bba6fa|AudioDbArtist=111352|AudioDbAlbum=2116560|MusicBrainzAlbumArtist=20244d07-534f-4eff-b4d4-930878889970",
|
||||
new Dictionary<string, string>()
|
||||
{
|
||||
{ "MusicBrainzAlbum", "9d363e43-f24f-4b39-bc5a-7ef305c677c7" },
|
||||
{ "MusicBrainzReleaseGroup", "63eba062-847c-3b73-8b0f-6baf27bba6fa" },
|
||||
{ "AudioDbArtist", "111352" },
|
||||
{ "AudioDbAlbum", "2116560" },
|
||||
{ "MusicBrainzAlbumArtist", "20244d07-534f-4eff-b4d4-930878889970" },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DeserializeProviderIds_Valid_TestData))]
|
||||
public void DeserializeProviderIds_Valid_Success(string value, Dictionary<string, string> expected)
|
||||
{
|
||||
var result = new ProviderIdsExtensionsTestsObject();
|
||||
SqliteItemRepository.DeserializeProviderIds(value, result);
|
||||
Assert.Equal(expected, result.ProviderIds);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DeserializeProviderIds_Valid_TestData))]
|
||||
public void SerializeProviderIds_Valid_Success(string expected, Dictionary<string, string> values)
|
||||
{
|
||||
Assert.Equal(expected, SqliteItemRepository.SerializeProviderIds(values));
|
||||
}
|
||||
|
||||
private class ProviderIdsExtensionsTestsObject : IHasProviderIds
|
||||
{
|
||||
public Dictionary<string, string> ProviderIds { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user