roadie/Roadie.Api.Library.Tests/InspectorTests.cs

131 lines
5.3 KiB
C#
Raw Permalink Normal View History

2019-07-10 04:08:27 +00:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Roadie.Library.Caching;
using Roadie.Library.Inspect;
using Roadie.Library.Inspect.Plugins.File;
using Roadie.Library.MetaData.ID3Tags;
using Roadie.Library.Processors;
2019-02-16 21:08:20 +00:00
using System;
using Xunit;
using configuration = Roadie.Library.Configuration;
2019-07-10 04:08:27 +00:00
2019-02-16 21:08:20 +00:00
namespace Roadie.Library.Tests
{
public class InspectorTests : HttpClientFactoryBaseTests
2019-02-16 21:08:20 +00:00
{
2019-07-10 04:08:27 +00:00
private IEventMessageLogger MessageLogger { get; }
2019-07-10 04:08:27 +00:00
private ILogger Logger
{
get
{
return MessageLogger as ILogger;
2019-07-10 04:08:27 +00:00
}
}
private ID3TagsHelper TagsHelper { get; }
private configuration.IRoadieSettings Configuration { get; }
public DictionaryCacheManager CacheManager { get; }
public InspectorTests()
{
MessageLogger = new EventMessageLogger<ID3TagsHelperTests>();
MessageLogger.Messages += MessageLoggerMessages;
2019-07-10 04:08:27 +00:00
var settings = new configuration.RoadieSettings();
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("appsettings.test.json");
IConfiguration configuration = configurationBuilder.Build();
configuration.GetSection("RoadieSettings").Bind(settings);
settings.ConnectionString = configuration.GetConnectionString("RoadieDatabaseConnection");
Configuration = settings;
2020-06-21 20:39:14 +00:00
CacheManager = new DictionaryCacheManager(Logger, new NewtonsoftCacheSerializer(Logger), new CachePolicy(TimeSpan.FromHours(4)));
2019-07-10 04:08:27 +00:00
var tagHelperLooper = new EventMessageLogger<ID3TagsHelper>();
2019-11-04 03:19:04 +00:00
tagHelperLooper.Messages += MessageLoggerMessages;
TagsHelper = new ID3TagsHelper(Configuration, CacheManager, tagHelperLooper, _httpClientFactory);
2019-07-10 04:08:27 +00:00
}
2019-11-04 03:19:04 +00:00
private void MessageLoggerMessages(object sender, EventMessage e)
2019-07-10 04:08:27 +00:00
{
Console.WriteLine($"Log Level [{ e.Level }] Log Message [{ e.Message }] ");
}
[Theory]
[InlineData("Bob Jones", "Bob Jones")]
[InlineData("Bob Jones\\Mary Jones", "Bob Jones/Mary Jones")]
[InlineData("Bob Jones;Mary Jones", "Bob Jones/Mary Jones")]
[InlineData("Bob Jones; Mary Jones", "Bob Jones/Mary Jones")]
[InlineData("Bob Jones ; Mary Jones", "Bob Jones/Mary Jones")]
[InlineData("Bob Jones/Mary Jones", "Bob Jones/Mary Jones")]
[InlineData("Bob Jones & Mary Jones", "Bob Jones & Mary Jones")]
[InlineData("Bob Jones ", "Bob Jones")]
[InlineData(" BoB Jones ", "Bob Jones")]
[InlineData("Ain't NO THING", "Ain't No Thing")]
2019-11-04 03:19:04 +00:00
public void CleanArtistPlugin(string artist, string shouldBe)
2019-07-10 04:08:27 +00:00
{
var plugin = new CleanUpArtists(Configuration, CacheManager, Logger, TagsHelper);
Assert.Equal(shouldBe, plugin.CleanArtist(artist));
}
[Theory]
[InlineData("Ain't NO THING", "Ain't No Thing")]
2019-11-04 03:19:04 +00:00
public void CleanTrackTitlePlugin(string title, string shouldBe)
2019-07-10 04:08:27 +00:00
{
var plugin = new CleanUpTrackTitle(Configuration, CacheManager, Logger, TagsHelper);
var result = plugin.Process(new MetaData.Audio.AudioMetaData { Title = title });
2019-07-10 04:08:27 +00:00
Assert.Equal(shouldBe, result.Data.Title);
}
[Fact]
2019-11-04 03:19:04 +00:00
public void CleanArtistPluginRemoveArtistFromTrackArtist()
2019-07-10 04:08:27 +00:00
{
var artist = "Bob Jones";
2019-07-10 04:08:27 +00:00
var trackArtist = "Bob Jones;Mary Jones";
var trackShouldBe = "Mary Jones";
var plugin = new CleanUpArtists(Configuration, CacheManager, Logger, TagsHelper);
var cleaned = plugin.CleanArtist(trackArtist, artist);
Assert.Equal(trackShouldBe, cleaned);
}
2019-02-16 21:08:20 +00:00
[Theory]
[InlineData("Bob Jones")]
[InlineData("Nancy Jones")]
2019-11-04 03:19:04 +00:00
public void GenerateInspectorArtistToken(string artist)
2019-02-16 21:08:20 +00:00
{
var token = Inspector.ArtistInspectorToken(new MetaData.Audio.AudioMetaData { Artist = artist });
Assert.NotNull(token);
}
[Fact]
2019-11-04 03:19:04 +00:00
public void ShouldGenerateSameTokenValue()
2019-02-16 21:08:20 +00:00
{
var md = new MetaData.Audio.AudioMetaData { Artist = "Omniversum Fractum", Release = "Paradigm Of The Elementals Essence" };
var artistToken = Inspector.ArtistInspectorToken(md);
Assert.NotNull(artistToken);
var releaseToken = Inspector.ReleaseInspectorToken(md);
Assert.NotNull(releaseToken);
Assert.NotEqual(artistToken, releaseToken);
var secondReleaseToken = Inspector.ReleaseInspectorToken(md);
Assert.NotNull(releaseToken);
Assert.NotEqual(artistToken, releaseToken);
Assert.Equal(secondReleaseToken, releaseToken);
}
[Fact]
2019-11-04 03:19:04 +00:00
public void GenerateInspectorTokensArtistAndReleaseUnique()
2019-02-16 21:08:20 +00:00
{
var md = new MetaData.Audio.AudioMetaData { Artist = "Bob Jones", Release = "Bob's First Release" };
var artistToken = Inspector.ArtistInspectorToken(md);
Assert.NotNull(artistToken);
var releaseToken = Inspector.ReleaseInspectorToken(md);
Assert.NotNull(releaseToken);
Assert.NotEqual(artistToken, releaseToken);
}
}
}