Merge pull request #5356 from cvium/fix_provideridextensions

return false when providerid is null or empty
pull/5362/head
Claus Vium 4 years ago committed by GitHub
commit ddc62a89ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,7 +22,7 @@ namespace MediaBrowser.Model.Entities
throw new ArgumentNullException(nameof(instance));
}
return instance.ProviderIds?.ContainsKey(name) ?? false;
return instance.TryGetProviderId(name, out _);
}
/// <summary>
@ -56,7 +56,15 @@ namespace MediaBrowser.Model.Entities
return false;
}
return instance.ProviderIds.TryGetValue(name, out id);
var foundProviderId = instance.ProviderIds.TryGetValue(name, out id);
// This occurs when searching with Identify (and possibly in other places)
if (string.IsNullOrEmpty(id))
{
id = null;
foundProviderId = false;
}
return foundProviderId;
}
/// <summary>

@ -869,14 +869,14 @@ namespace MediaBrowser.Providers.Manager
}
}
}
catch (Exception)
#pragma warning disable CA1031 // do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // do not catch general exception types
{
// Logged at lower levels
_logger.LogError(ex, "Provider {ProviderName} failed to retrieve search results", provider.Name);
}
}
// _logger.LogDebug("Returning search results {0}", _json.SerializeToString(resultList));
return resultList;
}

@ -18,7 +18,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact]
public void HasProviderId_NullProvider_False()
{
var nullProvider = new ProviderIdsExtensionsTestsObject()
var nullProvider = new ProviderIdsExtensionsTestsObject
{
ProviderIds = null!
};
@ -47,6 +47,15 @@ namespace Jellyfin.Model.Tests.Entities
Assert.True(provider.HasProviderId(MetadataProvider.Imdb));
}
[Fact]
public void HasProviderId_FoundNameEmptyValue_False()
{
var provider = new ProviderIdsExtensionsTestsObject();
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = string.Empty;
Assert.False(provider.HasProviderId(MetadataProvider.Imdb));
}
[Fact]
public void GetProviderId_NullInstance_ThrowsArgumentNullException()
{
@ -68,7 +77,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact]
public void GetProviderId_NullProvider_Null()
{
var nullProvider = new ProviderIdsExtensionsTestsObject()
var nullProvider = new ProviderIdsExtensionsTestsObject
{
ProviderIds = null!
};
@ -85,7 +94,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact]
public void TryGetProviderId_NullProvider_False()
{
var nullProvider = new ProviderIdsExtensionsTestsObject()
var nullProvider = new ProviderIdsExtensionsTestsObject
{
ProviderIds = null!
};
@ -112,6 +121,16 @@ namespace Jellyfin.Model.Tests.Entities
Assert.Equal(ExampleImdbId, id);
}
[Fact]
public void TryGetProviderId_FoundNameEmptyValue_False()
{
var provider = new ProviderIdsExtensionsTestsObject();
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = string.Empty;
Assert.False(provider.TryGetProviderId(MetadataProvider.Imdb, out var id));
Assert.Null(id);
}
[Fact]
public void SetProviderId_NullInstance_ThrowsArgumentNullException()
{
@ -146,7 +165,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact]
public void SetProviderId_NullProvider_Success()
{
var nullProvider = new ProviderIdsExtensionsTestsObject()
var nullProvider = new ProviderIdsExtensionsTestsObject
{
ProviderIds = null!
};
@ -158,7 +177,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact]
public void SetProviderId_NullProviderAndEmptyName_Success()
{
var nullProvider = new ProviderIdsExtensionsTestsObject()
var nullProvider = new ProviderIdsExtensionsTestsObject
{
ProviderIds = null!
};

Loading…
Cancel
Save