Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert breaking change to HasProviderId #5339

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@ namespace MediaBrowser.Model.Entities
/// </summary>
public static class ProviderIdsExtensions
{
/// <summary>
/// Checks if this instance has an id for the given provider.
/// </summary>
/// <param name="instance">The instance.</param>
/// <param name="name">The of the provider name.</param>
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
public static bool HasProviderId(this IHasProviderIds instance, string name)
{
if (instance == null)
{
throw new ArgumentNullException(nameof(instance));
}

return instance.ProviderIds?.ContainsKey(name) ?? false;
}

/// <summary>
/// Checks if this instance has an id for the given provider.
/// </summary>
/// <param name="instance">The instance.</param>
/// <param name="provider">The provider.</param>
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
public static bool HasProviderId(this IHasProviderIds instance, MetadataProvider provider)
{
return instance.HasProviderId(provider.ToString());
Bond-009 marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Gets a provider id.
/// </summary>
Expand Down
38 changes: 38 additions & 0 deletions tests/Jellyfin.Model.Tests/Entities/ProviderIdsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ public class ProviderIdsExtensionsTests
{
private const string ExampleImdbId = "tt0113375";

[Fact]
public void HasProviderId_NullInstance_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() => ProviderIdsExtensions.HasProviderId(null!, MetadataProvider.Imdb));
}

[Fact]
public void HasProviderId_NullProvider_False()
{
var nullProvider = new ProviderIdsExtensionsTestsObject()
{
ProviderIds = null!
};

Assert.False(nullProvider.HasProviderId(MetadataProvider.Imdb));
}

[Fact]
public void HasProviderId_NullName_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() => ProviderIdsExtensionsTestsObject.Empty.HasProviderId(null!));
}

[Fact]
public void HasProviderId_NotFoundName_False()
{
Assert.False(ProviderIdsExtensionsTestsObject.Empty.HasProviderId(MetadataProvider.Imdb));
}

[Fact]
public void HasProviderId_FoundName_True()
{
var provider = new ProviderIdsExtensionsTestsObject();
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = ExampleImdbId;

Assert.True(provider.HasProviderId(MetadataProvider.Imdb));
}

[Fact]
public void GetProviderId_NullInstance_ThrowsArgumentNullException()
{
Expand Down