2021-02-19 11:01:52 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Model.Tests.Entities
|
|
|
|
{
|
|
|
|
public class ProviderIdsExtensionsTests
|
|
|
|
{
|
|
|
|
private const string ExampleImdbId = "tt0113375";
|
|
|
|
|
2021-03-01 14:35:38 -05:00
|
|
|
[Fact]
|
|
|
|
public void HasProviderId_NullInstance_ThrowsArgumentNullException()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException>(() => ProviderIdsExtensions.HasProviderId(null!, MetadataProvider.Imdb));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void HasProviderId_NullProvider_False()
|
|
|
|
{
|
2021-03-03 03:37:21 -05:00
|
|
|
var nullProvider = new ProviderIdsExtensionsTestsObject
|
2021-03-01 14:35:38 -05:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2021-03-03 06:28:40 -05:00
|
|
|
[Fact]
|
|
|
|
public void HasProviderId_FoundNameEmptyValue_False()
|
|
|
|
{
|
|
|
|
var provider = new ProviderIdsExtensionsTestsObject();
|
|
|
|
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = string.Empty;
|
|
|
|
|
|
|
|
Assert.False(provider.HasProviderId(MetadataProvider.Imdb));
|
|
|
|
}
|
|
|
|
|
2021-02-19 11:01:52 -05:00
|
|
|
[Fact]
|
|
|
|
public void GetProviderId_NullInstance_ThrowsArgumentNullException()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException>(() => ProviderIdsExtensions.GetProviderId(null!, MetadataProvider.Imdb));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetProviderId_NullName_ThrowsArgumentNullException()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException>(() => ProviderIdsExtensionsTestsObject.Empty.GetProviderId(null!));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetProviderId_NotFoundName_Null()
|
|
|
|
{
|
|
|
|
Assert.Null(ProviderIdsExtensionsTestsObject.Empty.GetProviderId(MetadataProvider.Imdb));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetProviderId_NullProvider_Null()
|
|
|
|
{
|
2021-03-03 03:37:21 -05:00
|
|
|
var nullProvider = new ProviderIdsExtensionsTestsObject
|
2021-02-19 11:01:52 -05:00
|
|
|
{
|
|
|
|
ProviderIds = null!
|
|
|
|
};
|
|
|
|
|
|
|
|
Assert.Null(nullProvider.GetProviderId(MetadataProvider.Imdb));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void TryGetProviderId_NotFoundName_False()
|
|
|
|
{
|
|
|
|
Assert.False(ProviderIdsExtensionsTestsObject.Empty.TryGetProviderId(MetadataProvider.Imdb, out _));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void TryGetProviderId_NullProvider_False()
|
|
|
|
{
|
2021-03-03 03:37:21 -05:00
|
|
|
var nullProvider = new ProviderIdsExtensionsTestsObject
|
2021-02-19 11:01:52 -05:00
|
|
|
{
|
|
|
|
ProviderIds = null!
|
|
|
|
};
|
|
|
|
|
|
|
|
Assert.False(nullProvider.TryGetProviderId(MetadataProvider.Imdb, out _));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetProviderId_FoundName_Id()
|
|
|
|
{
|
|
|
|
var provider = new ProviderIdsExtensionsTestsObject();
|
|
|
|
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = ExampleImdbId;
|
|
|
|
|
|
|
|
Assert.Equal(ExampleImdbId, provider.GetProviderId(MetadataProvider.Imdb));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void TryGetProviderId_FoundName_True()
|
|
|
|
{
|
|
|
|
var provider = new ProviderIdsExtensionsTestsObject();
|
|
|
|
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = ExampleImdbId;
|
|
|
|
|
|
|
|
Assert.True(provider.TryGetProviderId(MetadataProvider.Imdb, out var id));
|
|
|
|
Assert.Equal(ExampleImdbId, id);
|
|
|
|
}
|
|
|
|
|
2021-03-03 06:28:40 -05:00
|
|
|
[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);
|
|
|
|
}
|
|
|
|
|
2021-02-19 11:01:52 -05:00
|
|
|
[Fact]
|
|
|
|
public void SetProviderId_NullInstance_ThrowsArgumentNullException()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException>(() => ProviderIdsExtensions.SetProviderId(null!, MetadataProvider.Imdb, ExampleImdbId));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void SetProviderId_Null_Remove()
|
|
|
|
{
|
|
|
|
var provider = new ProviderIdsExtensionsTestsObject();
|
|
|
|
provider.SetProviderId(MetadataProvider.Imdb, null!);
|
|
|
|
Assert.Empty(provider.ProviderIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void SetProviderId_EmptyName_Remove()
|
|
|
|
{
|
|
|
|
var provider = new ProviderIdsExtensionsTestsObject();
|
|
|
|
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = ExampleImdbId;
|
|
|
|
provider.SetProviderId(MetadataProvider.Imdb, string.Empty);
|
|
|
|
Assert.Empty(provider.ProviderIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void SetProviderId_NonEmptyId_Success()
|
|
|
|
{
|
|
|
|
var provider = new ProviderIdsExtensionsTestsObject();
|
|
|
|
provider.SetProviderId(MetadataProvider.Imdb, ExampleImdbId);
|
|
|
|
Assert.Single(provider.ProviderIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void SetProviderId_NullProvider_Success()
|
|
|
|
{
|
2021-03-03 03:37:21 -05:00
|
|
|
var nullProvider = new ProviderIdsExtensionsTestsObject
|
2021-02-19 11:01:52 -05:00
|
|
|
{
|
|
|
|
ProviderIds = null!
|
|
|
|
};
|
|
|
|
|
|
|
|
nullProvider.SetProviderId(MetadataProvider.Imdb, ExampleImdbId);
|
|
|
|
Assert.Single(nullProvider.ProviderIds);
|
|
|
|
}
|
|
|
|
|
2021-02-19 11:26:34 -05:00
|
|
|
[Fact]
|
|
|
|
public void SetProviderId_NullProviderAndEmptyName_Success()
|
|
|
|
{
|
2021-03-03 03:37:21 -05:00
|
|
|
var nullProvider = new ProviderIdsExtensionsTestsObject
|
2021-02-19 11:26:34 -05:00
|
|
|
{
|
|
|
|
ProviderIds = null!
|
|
|
|
};
|
|
|
|
|
|
|
|
nullProvider.SetProviderId(MetadataProvider.Imdb, string.Empty);
|
|
|
|
Assert.Null(nullProvider.ProviderIds);
|
|
|
|
}
|
|
|
|
|
2022-12-14 16:03:03 -05:00
|
|
|
private sealed class ProviderIdsExtensionsTestsObject : IHasProviderIds
|
2021-02-19 11:01:52 -05:00
|
|
|
{
|
|
|
|
public static readonly ProviderIdsExtensionsTestsObject Empty = new ProviderIdsExtensionsTestsObject();
|
|
|
|
|
|
|
|
public Dictionary<string, string> ProviderIds { get; set; } = new Dictionary<string, string>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|