mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
Added unit tests for the MusicSearch Engine
This commit is contained in:
parent
b5dcacfed2
commit
6c443469af
4 changed files with 169 additions and 3 deletions
|
@ -14,6 +14,7 @@
|
||||||
public const string Streams = "769085a1-c2f7-4c24-a532-2375a77693bd";
|
public const string Streams = "769085a1-c2f7-4c24-a532-2375a77693bd";
|
||||||
public const string YouTube = "6a540e5b-58c6-4192-b6ba-dbc71ec8fcf0";
|
public const string YouTube = "6a540e5b-58c6-4192-b6ba-dbc71ec8fcf0";
|
||||||
public const string Download = "f8319a2f-f824-4617-81c8-be6560b3b203";
|
public const string Download = "f8319a2f-f824-4617-81c8-be6560b3b203";
|
||||||
|
public const string BandMember = "5be4c609-9afa-4ea0-910b-12ffb71e3821";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
160
src/Ombi.Core.Tests/Engine/V2/MusicSearchEngineV2Tests.cs
Normal file
160
src/Ombi.Core.Tests/Engine/V2/MusicSearchEngineV2Tests.cs
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
using AutoFixture;
|
||||||
|
using Hqub.MusicBrainz.API.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Ombi.Api.MusicBrainz;
|
||||||
|
using Ombi.Core.Engine.V2;
|
||||||
|
using Ombi.Core.Models.Requests;
|
||||||
|
using Ombi.Core.Models.Search.V2.Music;
|
||||||
|
using Ombi.Core.Rule.Interfaces;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Helpers;
|
||||||
|
using Ombi.Settings.Settings.Models;
|
||||||
|
using Ombi.Settings.Settings.Models.External;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
using Ombi.Store.Repository;
|
||||||
|
using Ombi.Test.Common;
|
||||||
|
|
||||||
|
namespace Ombi.Core.Tests.Engine.V2
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class MusicSearchEngineV2Tests
|
||||||
|
{
|
||||||
|
|
||||||
|
private MusicSearchEngineV2 _engine;
|
||||||
|
|
||||||
|
private Mock<IMusicBrainzApi> _musicApi;
|
||||||
|
private Fixture F;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
F = new Fixture();
|
||||||
|
F.Behaviors.OfType<ThrowingRecursionBehavior>().ToList()
|
||||||
|
.ForEach(b => F.Behaviors.Remove(b));
|
||||||
|
F.Behaviors.Add(new OmitOnRecursionBehavior());
|
||||||
|
|
||||||
|
var principle = new Mock<IPrincipal>();
|
||||||
|
var requestService = new Mock<IRequestServiceMain>();
|
||||||
|
var ruleEval = new Mock<IRuleEvaluator>();
|
||||||
|
var um = MockHelper.MockUserManager(new List<OmbiUser>());
|
||||||
|
var cache = new Mock<ICacheService>();
|
||||||
|
var ombiSettings = new Mock<ISettingsService<OmbiSettings>>();
|
||||||
|
var requestSub = new Mock<IRepository<RequestSubscription>>();
|
||||||
|
_musicApi = new Mock<IMusicBrainzApi>();
|
||||||
|
var lidarrSettings = new Mock<ISettingsService<LidarrSettings>>();
|
||||||
|
_engine = new MusicSearchEngineV2(principle.Object, requestService.Object, ruleEval.Object,
|
||||||
|
um.Object, cache.Object, ombiSettings.Object, requestSub.Object, _musicApi.Object,
|
||||||
|
lidarrSettings.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetBasicArtistInformation_SingleArtist_Test()
|
||||||
|
{
|
||||||
|
_musicApi.Setup(x => x.GetArtistInformation("pretend-artist-id")).ReturnsAsync(F.Create<Artist>());
|
||||||
|
|
||||||
|
var result = await _engine.GetArtistInformation("pretend-artist-id");
|
||||||
|
|
||||||
|
Assert.That(result, Is.Not.Null);
|
||||||
|
Assert.That(result.ReleaseGroups.Any(), Is.True, "Release Groups are null");
|
||||||
|
Assert.That(result.Members.Any(), Is.False, "Members somehow populated?");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetBasicArtistInformation_Group_Test()
|
||||||
|
{
|
||||||
|
var musicReturnVal = F.Build<Artist>().With(x => x.Relations, new List<Relation>
|
||||||
|
{
|
||||||
|
new Relation
|
||||||
|
{
|
||||||
|
TypeId = RelationLinks.BandMember,
|
||||||
|
Artist = new Artist
|
||||||
|
{
|
||||||
|
Name = "Mr Artist"
|
||||||
|
},
|
||||||
|
Attributes = new []{"a nobody"},
|
||||||
|
Begin = "1992",
|
||||||
|
End = "2019",
|
||||||
|
Ended = true
|
||||||
|
},
|
||||||
|
new Relation
|
||||||
|
{
|
||||||
|
TypeId = RelationLinks.BandMember,
|
||||||
|
Artist = new Artist
|
||||||
|
{
|
||||||
|
Name = "Mr Artist2"
|
||||||
|
},
|
||||||
|
Attributes = new []{"a nobody2"},
|
||||||
|
Begin = "1993",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_musicApi.Setup(x => x.GetArtistInformation("pretend-artist-id")).ReturnsAsync(musicReturnVal.Create());
|
||||||
|
|
||||||
|
var result = await _engine.GetArtistInformation("pretend-artist-id");
|
||||||
|
|
||||||
|
Assert.That(result, Is.Not.Null);
|
||||||
|
Assert.That(result.ReleaseGroups.Any(), Is.True, "Release Groups are null");
|
||||||
|
Assert.That(result.Members.Any(), Is.True, "Members IS NULL!");
|
||||||
|
|
||||||
|
Assert.That(result.Members.FirstOrDefault(x => x.Name == "Mr Artist").End, Is.EqualTo("2019"));
|
||||||
|
Assert.That(result.Members.FirstOrDefault(x => x.Name == "Mr Artist").Attributes.Length, Is.EqualTo(1));
|
||||||
|
Assert.That(result.Members.FirstOrDefault(x => x.Name == "Mr Artist").IsCurrentMember, Is.EqualTo(false));
|
||||||
|
Assert.That(result.Members.FirstOrDefault(x => x.Name == "Mr Artist").Start, Is.EqualTo("1992"));
|
||||||
|
|
||||||
|
Assert.That(result.Members.FirstOrDefault(x => x.Name == "Mr Artist2").IsCurrentMember, Is.EqualTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCaseSource(nameof(LinksData))]
|
||||||
|
public async Task<string> GetBasicArtistInformation_Links_Test(string url, string typeId, Func<ArtistInformation, string> func)
|
||||||
|
{
|
||||||
|
var musicReturnVal = F.Build<Artist>().With(x => x.Relations, new List<Relation>
|
||||||
|
{
|
||||||
|
new Relation
|
||||||
|
{
|
||||||
|
TypeId = typeId,
|
||||||
|
Url = new Url
|
||||||
|
{
|
||||||
|
Resource = url
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
_musicApi.Setup(x => x.GetArtistInformation("pretend-artist-id")).ReturnsAsync(musicReturnVal.Create());
|
||||||
|
|
||||||
|
var result = await _engine.GetArtistInformation("pretend-artist-id");
|
||||||
|
|
||||||
|
Assert.That(result, Is.Not.Null);
|
||||||
|
return func(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<TestCaseData> LinksData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return new TestCaseData("twitter.com", RelationLinks.SocialNetwork, new Func<ArtistInformation, string>(artist => artist.Links.Twitter)).Returns("twitter.com").SetName("ArtistInformation_Links_Twitter");
|
||||||
|
yield return new TestCaseData("allmusic", RelationLinks.AllMusic, new Func<ArtistInformation, string>(artist => artist.Links.AllMusic)).Returns("allmusic").SetName("ArtistInformation_Links_AllMusic");
|
||||||
|
yield return new TestCaseData("bbcmusic", RelationLinks.BbcMusic, new Func<ArtistInformation, string>(artist => artist.Links.BbcMusic)).Returns("bbcmusic").SetName("ArtistInformation_Links_BbcMusic");
|
||||||
|
yield return new TestCaseData("discogs", RelationLinks.Discogs, new Func<ArtistInformation, string>(artist => artist.Links.Discogs)).Returns("discogs").SetName("ArtistInformation_Links_Discogs");
|
||||||
|
yield return new TestCaseData("homepage", RelationLinks.Homepage, new Func<ArtistInformation, string>(artist => artist.Links.HomePage)).Returns("homepage").SetName("ArtistInformation_Links_Homepage");
|
||||||
|
yield return new TestCaseData("imdb", RelationLinks.Imdb, new Func<ArtistInformation, string>(artist => artist.Links.Imdb)).Returns("imdb").SetName("ArtistInformation_Links_Imdb");
|
||||||
|
yield return new TestCaseData("lastfm", RelationLinks.LastFm, new Func<ArtistInformation, string>(artist => artist.Links.LastFm)).Returns("lastfm").SetName("ArtistInformation_Links_LastFm");
|
||||||
|
yield return new TestCaseData("myspace", RelationLinks.MySpace, new Func<ArtistInformation, string>(artist => artist.Links.MySpace)).Returns("myspace").SetName("ArtistInformation_Links_MySpace");
|
||||||
|
yield return new TestCaseData("onlinecommunity", RelationLinks.OnlineCommunity, new Func<ArtistInformation, string>(artist => artist.Links.OnlineCommunity)).Returns("onlinecommunity").SetName("ArtistInformation_Links_OnlineCommunity");
|
||||||
|
yield return new TestCaseData("www.facebook.com", RelationLinks.SocialNetwork, new Func<ArtistInformation, string>(artist => artist.Links.Facebook)).Returns("www.facebook.com").SetName("ArtistInformation_Links_Facebook");
|
||||||
|
yield return new TestCaseData("www.instagram.com", RelationLinks.SocialNetwork, new Func<ArtistInformation, string>(artist => artist.Links.Instagram)).Returns("www.instagram.com").SetName("ArtistInformation_Links_insta");
|
||||||
|
yield return new TestCaseData("www.vk.com", RelationLinks.SocialNetwork, new Func<ArtistInformation, string>(artist => artist.Links.Vk)).Returns("www.vk.com").SetName("ArtistInformation_Links_vk");
|
||||||
|
yield return new TestCaseData("app.spotify.com", RelationLinks.Streams, new Func<ArtistInformation, string>(artist => artist.Links.Spotify)).Returns("app.spotify.com").SetName("ArtistInformation_Links_Spotify");
|
||||||
|
yield return new TestCaseData("deezer.com", RelationLinks.Streams, new Func<ArtistInformation, string>(artist => artist.Links.Deezer)).Returns("deezer.com").SetName("ArtistInformation_Links_Deezer");
|
||||||
|
yield return new TestCaseData("play.google.com", RelationLinks.Download, new Func<ArtistInformation, string>(artist => artist.Links.Google)).Returns("play.google.com").SetName("ArtistInformation_Links_Google");
|
||||||
|
yield return new TestCaseData("itunes.apple.com", RelationLinks.Download, new Func<ArtistInformation, string>(artist => artist.Links.Apple)).Returns("itunes.apple.com").SetName("ArtistInformation_Links_Apple");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ using Ombi.Core.Rule.Interfaces;
|
||||||
using Ombi.Core.Settings;
|
using Ombi.Core.Settings;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
using Ombi.Settings.Settings.Models;
|
using Ombi.Settings.Settings.Models;
|
||||||
|
using Ombi.Settings.Settings.Models.External;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
using ReleaseGroup = Ombi.Core.Models.Search.V2.Music.ReleaseGroup;
|
using ReleaseGroup = Ombi.Core.Models.Search.V2.Music.ReleaseGroup;
|
||||||
|
@ -22,13 +23,15 @@ namespace Ombi.Core.Engine.V2
|
||||||
public class MusicSearchEngineV2 : BaseMediaEngine, IMusicSearchEngineV2
|
public class MusicSearchEngineV2 : BaseMediaEngine, IMusicSearchEngineV2
|
||||||
{
|
{
|
||||||
private readonly IMusicBrainzApi _musicBrainzApi;
|
private readonly IMusicBrainzApi _musicBrainzApi;
|
||||||
|
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||||
|
|
||||||
public MusicSearchEngineV2(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
public MusicSearchEngineV2(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
||||||
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings,
|
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings,
|
||||||
IRepository<RequestSubscription> sub, IMusicBrainzApi musicBrainzApi)
|
IRepository<RequestSubscription> sub, IMusicBrainzApi musicBrainzApi, ISettingsService<LidarrSettings> lidarrSettings)
|
||||||
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
|
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
|
||||||
{
|
{
|
||||||
_musicBrainzApi = musicBrainzApi;
|
_musicBrainzApi = musicBrainzApi;
|
||||||
|
_lidarrSettings = lidarrSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ArtistInformation> GetArtistInformation(string artistId)
|
public async Task<ArtistInformation> GetArtistInformation(string artistId)
|
||||||
|
@ -48,7 +51,7 @@ namespace Ombi.Core.Engine.V2
|
||||||
ReleaseGroups = new List<ReleaseGroup>(),
|
ReleaseGroups = new List<ReleaseGroup>(),
|
||||||
Members = new List<BandMember>()
|
Members = new List<BandMember>()
|
||||||
};
|
};
|
||||||
// TODO FINISH MAPPING
|
|
||||||
foreach (var g in artist.ReleaseGroups)
|
foreach (var g in artist.ReleaseGroups)
|
||||||
{
|
{
|
||||||
info.ReleaseGroups.Add(new ReleaseGroup
|
info.ReleaseGroups.Add(new ReleaseGroup
|
||||||
|
@ -68,7 +71,7 @@ namespace Ombi.Core.Engine.V2
|
||||||
private List<BandMember> GetBandMembers(Artist artist)
|
private List<BandMember> GetBandMembers(Artist artist)
|
||||||
{
|
{
|
||||||
var members = new List<BandMember>();
|
var members = new List<BandMember>();
|
||||||
var membersOfBand = artist.Relations.Where(x => x.TypeId == "5be4c609-9afa-4ea0-910b-12ffb71e3821");
|
var membersOfBand = artist.Relations.Where(x => x.TypeId == RelationLinks.BandMember);
|
||||||
foreach (var member in membersOfBand)
|
foreach (var member in membersOfBand)
|
||||||
{
|
{
|
||||||
members.Add(new BandMember
|
members.Add(new BandMember
|
||||||
|
|
2
src/Ombi.sln.DotSettings
Normal file
2
src/Ombi.sln.DotSettings
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Brainz/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
Add table
Add a link
Reference in a new issue