mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+224
@@ -0,0 +1,224 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.Contracts.Core.Metadata;
|
||||
using Lumina.Plugins.MusicBrainz.Common.DependencyInjection;
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.DTO.Settings;
|
||||
using Lumina.Plugins.MusicBrainz.Core.Api;
|
||||
using Lumina.Plugins.MusicBrainz.Core.Settings;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzServices"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzServicesTests
|
||||
{
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenServicesIsNull_ShouldThrowArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
IServiceCollection services = null!;
|
||||
|
||||
// Act
|
||||
Action act = () => services.AddMusicBrainzMetadataProviders(pluginId: Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
Assert.Throws<ArgumentNullException>(act);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenCalled_ShouldReturnTheSameServiceCollection()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
IServiceCollection result = services.AddMusicBrainzMetadataProviders(pluginId: Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
Assert.Same(services, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenCalled_ShouldRegisterTheThreeMetadataProvidersForKeyedResolution()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: pluginId);
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(3, serviceProvider.GetKeyedServices<IMetadataProvider>(pluginId).Count());
|
||||
Assert.Empty(serviceProvider.GetKeyedServices<IMetadataProvider>(Guid.NewGuid()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenCalled_ShouldRegisterTheSettingsProviderAsScoped()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
ServiceDescriptor settingsProviderDescriptor = Assert.Single(services, descriptor => descriptor.ServiceType == typeof(MusicBrainzSettingsProvider));
|
||||
Assert.Equal(ServiceLifetime.Scoped, settingsProviderDescriptor.Lifetime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenCalled_ShouldRegisterTheThrottleAndTheResponseCacheAsSingletons()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
ServiceDescriptor throttleDescriptor = Assert.Single(services, descriptor => descriptor.ServiceType == typeof(MusicBrainzRequestThrottle));
|
||||
ServiceDescriptor responseCacheDescriptor = Assert.Single(services, descriptor => descriptor.ServiceType == typeof(MusicBrainzResponseCache));
|
||||
Assert.Equal(ServiceLifetime.Singleton, throttleDescriptor.Lifetime);
|
||||
Assert.Equal(ServiceLifetime.Singleton, responseCacheDescriptor.Lifetime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenCalled_ShouldRegisterTheHttpClient()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: Guid.NewGuid());
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(serviceProvider.GetService<MusicBrainzHttpClient>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddMusicBrainzMetadataProviders_WhenASettingsCallbackIsProvided_ShouldApplyItToTheDefaults()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: pluginId, settings => settings.BaseUrl = "http://custom.example/ws/2/");
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
MusicBrainzSettingsProvider settingsProvider = scope.ServiceProvider.GetRequiredService<MusicBrainzSettingsProvider>();
|
||||
MusicBrainzSettingsDto settings = await settingsProvider.GetAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("http://custom.example/ws/2/", settings.BaseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenTheHostConfiguresHttpClientDefaults_ShouldKeepThePrimaryHandlerOfTheHost()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
StubPrimaryHttpMessageHandler hostPrimaryHandler = new();
|
||||
services.ConfigureHttpClientDefaults(builder => builder.ConfigurePrimaryHttpMessageHandler(() => hostPrimaryHandler));
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: Guid.NewGuid());
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
// Act
|
||||
MusicBrainzHttpClient client = scope.ServiceProvider.GetRequiredService<MusicBrainzHttpClient>();
|
||||
|
||||
// Assert
|
||||
// The host owns the primary handler, because it is what validates and pins the address of every connection. The plugin must not replace it.
|
||||
Assert.Same(hostPrimaryHandler, GetPrimaryHandler(client));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMusicBrainzMetadataProviders_WhenCalledTwice_ShouldNotDuplicateTheTryAddServices()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
ServiceCollection services = new();
|
||||
|
||||
// Act
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: pluginId);
|
||||
services.AddMusicBrainzMetadataProviders(pluginId: pluginId);
|
||||
|
||||
// Assert
|
||||
// The settings provider, the throttle and the response cache are registered with TryAdd, so a second call must not add them again.
|
||||
Assert.Single(services, descriptor => descriptor.ServiceType == typeof(MusicBrainzRequestThrottle));
|
||||
Assert.Single(services, descriptor => descriptor.ServiceType == typeof(MusicBrainzResponseCache));
|
||||
Assert.Single(services, descriptor => descriptor.ServiceType == typeof(MusicBrainzSettingsProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the primary HTTP message handler of the provided client, unwrapping the delegating handlers built by the HTTP client factory around it.
|
||||
/// </summary>
|
||||
/// <param name="client">The client whose primary handler is retrieved.</param>
|
||||
/// <returns>The primary HTTP message handler of the client.</returns>
|
||||
private static HttpMessageHandler GetPrimaryHandler(MusicBrainzHttpClient client)
|
||||
{
|
||||
HttpClient httpClient = (HttpClient)GetFieldOfType(client, typeof(HttpClient))!;
|
||||
HttpMessageHandler? handler = (HttpMessageHandler?)GetFieldOfType(httpClient, typeof(HttpMessageHandler));
|
||||
while (handler is DelegatingHandler delegatingHandler)
|
||||
handler = delegatingHandler.InnerHandler;
|
||||
return handler ?? throw new InvalidOperationException("The HTTP client has no primary handler.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the first field, declared on the provided <paramref name="instance"/> or any of its base types, whose type is assignable to
|
||||
/// <paramref name="fieldType"/>, without relying on the field name, so the test keeps working across runtime versions.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance whose field is read.</param>
|
||||
/// <param name="fieldType">The type the field must be assignable to.</param>
|
||||
/// <returns>The value of the found field.</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown when no field assignable to <paramref name="fieldType"/> is found.</exception>
|
||||
private static object GetFieldOfType(object instance, Type fieldType)
|
||||
{
|
||||
Type? type = instance.GetType();
|
||||
while (type is not null)
|
||||
{
|
||||
FieldInfo? field = type
|
||||
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly)
|
||||
.FirstOrDefault(candidate => fieldType.IsAssignableFrom(candidate.FieldType));
|
||||
if (field is not null)
|
||||
return field.GetValue(instance)!;
|
||||
type = type.BaseType;
|
||||
}
|
||||
throw new InvalidOperationException($"No field assignable to {fieldType} was found on {instance.GetType()} or its base types.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Primary HTTP message handler that identifies the handler the host configured, so a test can verify that the plugin does not replace it.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
private sealed class StubPrimaryHttpMessageHandler : HttpMessageHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends the provided request. The tests never send a request through this handler.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to send.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The response of the request.</returns>
|
||||
/// <exception cref="NotSupportedException">Always thrown, because this handler only identifies the handler configured by the host.</exception>
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzAliasResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzAliasResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsEnded_WhenTheMusicBrainzApiReturnsNull_ShouldDeserializeAsNull()
|
||||
{
|
||||
// Arrange
|
||||
// The MusicBrainz search API can return a null ended flag for aliases, which used to break deserialization into a non-nullable boolean.
|
||||
const string JSON = """{"name":"Rammstein","ended":null}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzAliasResponse? response = JsonSerializer.Deserialize<MusicBrainzAliasResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Null(response.IsEnded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsEnded_WhenTheMusicBrainzApiReturnsTrue_ShouldDeserializeAsTrue()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"name":"Rammstein","ended":true}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzAliasResponse? response = JsonSerializer.Deserialize<MusicBrainzAliasResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.True(response.IsEnded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"name": "Alias Name",
|
||||
"sort-name": "Alias Sort Name",
|
||||
"type": "Artist name",
|
||||
"locale": "en",
|
||||
"primary": true,
|
||||
"begin": "1994-01-01",
|
||||
"end": "2020-12-31",
|
||||
"ended": true
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzAliasResponse? response = JsonSerializer.Deserialize<MusicBrainzAliasResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("Alias Name", response.Name);
|
||||
Assert.Equal("Alias Sort Name", response.SortName);
|
||||
Assert.Equal("Artist name", response.Type);
|
||||
Assert.Equal("en", response.Locale);
|
||||
Assert.True(response.IsPrimary);
|
||||
Assert.Equal("1994-01-01", response.Begin);
|
||||
Assert.Equal("2020-12-31", response.End);
|
||||
Assert.True(response.IsEnded);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzAreaResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzAreaResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void SortNameTypeAndIsoCodes_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "c0e0e0e0-0000-0000-0000-000000000000",
|
||||
"name": "United Kingdom",
|
||||
"sort-name": "United Kingdom",
|
||||
"type": "Country",
|
||||
"iso-3166-1-codes": [ "GB" ],
|
||||
"iso-3166-2-codes": [ "GB-ENG" ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzAreaResponse? response = JsonSerializer.Deserialize<MusicBrainzAreaResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("United Kingdom", response.SortName);
|
||||
Assert.Equal("Country", response.Type);
|
||||
Assert.Equal("GB", Assert.Single(response.Iso3166Part1Codes));
|
||||
Assert.Equal("GB-ENG", Assert.Single(response.Iso3166Part2Codes));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "area-id",
|
||||
"name": "United Kingdom",
|
||||
"sort-name": "United Kingdom",
|
||||
"disambiguation": "The United Kingdom of Great Britain",
|
||||
"type": "Country",
|
||||
"iso-3166-1-codes": [ "GB" ],
|
||||
"iso-3166-2-codes": [ "GB-ENG" ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzAreaResponse? response = JsonSerializer.Deserialize<MusicBrainzAreaResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("area-id", response.Id);
|
||||
Assert.Equal("United Kingdom", response.Name);
|
||||
Assert.Equal("United Kingdom", response.SortName);
|
||||
Assert.Equal("The United Kingdom of Great Britain", response.Disambiguation);
|
||||
Assert.Equal("Country", response.Type);
|
||||
Assert.Equal("GB", Assert.Single(response.Iso3166Part1Codes));
|
||||
Assert.Equal("GB-ENG", Assert.Single(response.Iso3166Part2Codes));
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzArtistCreditResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzArtistCreditResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void NameJoinPhraseAndArtist_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"name":"Freddie Mercury","joinphrase":" & ","artist":{"id":"cb6c5931-436c-38c5-9d24-044f37d1fe35","name":"Freddie Mercury"}}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzArtistCreditResponse? response = JsonSerializer.Deserialize<MusicBrainzArtistCreditResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("Freddie Mercury", response.Name);
|
||||
Assert.Equal(" & ", response.JoinPhrase);
|
||||
Assert.NotNull(response.Artist);
|
||||
Assert.Equal("Freddie Mercury", response.Artist.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"name": "Freddie Mercury",
|
||||
"joinphrase": " & ",
|
||||
"artist": { "id": "artist-id", "name": "Freddie Mercury" }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzArtistCreditResponse? response = JsonSerializer.Deserialize<MusicBrainzArtistCreditResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("Freddie Mercury", response.Name);
|
||||
Assert.Equal(" & ", response.JoinPhrase);
|
||||
Assert.NotNull(response.Artist);
|
||||
Assert.Equal("artist-id", response.Artist.Id);
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzArtistResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzArtistResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void SortNameTypeCountryAndCodes_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "cb6c5931-436c-38c5-9d24-044f37d1fe35",
|
||||
"name": "Queen",
|
||||
"sort-name": "Queen",
|
||||
"type": "Group",
|
||||
"gender": null,
|
||||
"country": "GB",
|
||||
"life-span": { "begin": "1970", "ended": false },
|
||||
"ipis": [ "00000000000" ],
|
||||
"isnis": [ "0000000000000000" ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzArtistResponse? response = JsonSerializer.Deserialize<MusicBrainzArtistResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("Queen", response.SortName);
|
||||
Assert.Equal("Group", response.Type);
|
||||
Assert.Equal("GB", response.Country);
|
||||
Assert.Equal("00000000000", Assert.Single(response.Ipis));
|
||||
Assert.Equal("0000000000000000", Assert.Single(response.Isnis));
|
||||
Assert.NotNull(response.LifeSpan);
|
||||
Assert.Equal("1970", response.LifeSpan.Begin);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "artist-id",
|
||||
"name": "Queen",
|
||||
"sort-name": "Queen",
|
||||
"disambiguation": "UK rock band",
|
||||
"type": "Group",
|
||||
"gender": "Male",
|
||||
"country": "GB",
|
||||
"area": { "id": "area-id", "name": "United Kingdom" },
|
||||
"begin-area": { "id": "begin-area-id", "name": "London" },
|
||||
"end-area": { "id": "end-area-id", "name": "Montreux" },
|
||||
"life-span": { "begin": "1970", "end": "1991", "ended": true },
|
||||
"isnis": [ "isni-1" ],
|
||||
"ipis": [ "ipi-1" ],
|
||||
"aliases": [ { "name": "Queen alias" } ],
|
||||
"tags": [ { "name": "rock", "count": 5 } ],
|
||||
"genres": [ { "id": "genre-id", "name": "Rock" } ],
|
||||
"relations": [ { "type": "member of band", "artist": { "id": "member-id", "name": "Freddie Mercury" } } ],
|
||||
"rating": { "value": 4.5, "votes-count": 10 }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzArtistResponse? response = JsonSerializer.Deserialize<MusicBrainzArtistResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("artist-id", response.Id);
|
||||
Assert.Equal("Queen", response.Name);
|
||||
Assert.Equal("Queen", response.SortName);
|
||||
Assert.Equal("UK rock band", response.Disambiguation);
|
||||
Assert.Equal("Group", response.Type);
|
||||
Assert.Equal("Male", response.Gender);
|
||||
Assert.Equal("GB", response.Country);
|
||||
Assert.NotNull(response.Area);
|
||||
Assert.Equal("United Kingdom", response.Area.Name);
|
||||
Assert.NotNull(response.BeginArea);
|
||||
Assert.Equal("London", response.BeginArea.Name);
|
||||
Assert.NotNull(response.EndArea);
|
||||
Assert.Equal("Montreux", response.EndArea.Name);
|
||||
Assert.NotNull(response.LifeSpan);
|
||||
Assert.Equal("1970", response.LifeSpan.Begin);
|
||||
Assert.Equal("isni-1", Assert.Single(response.Isnis));
|
||||
Assert.Equal("ipi-1", Assert.Single(response.Ipis));
|
||||
Assert.Equal("Queen alias", Assert.Single(response.Aliases).Name);
|
||||
Assert.Equal("rock", Assert.Single(response.Tags).Name);
|
||||
Assert.Equal("Rock", Assert.Single(response.Genres).Name);
|
||||
Assert.Equal("member of band", Assert.Single(response.Relations).Type);
|
||||
Assert.NotNull(response.Rating);
|
||||
Assert.Equal(4.5m, response.Rating.Value);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzArtistSearchResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzArtistSearchResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void CountOffsetAndArtists_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"count":1,"offset":0,"artists":[{"id":"cb6c5931-436c-38c5-9d24-044f37d1fe35","name":"Queen"}]}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzArtistSearchResponse? response = JsonSerializer.Deserialize<MusicBrainzArtistSearchResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(1, response.Count);
|
||||
Assert.Equal(0, response.Offset);
|
||||
Assert.Equal("Queen", Assert.Single(response.Artists).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"count": 2,
|
||||
"offset": 1,
|
||||
"artists": [ { "id": "artist-id", "name": "Queen" } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzArtistSearchResponse? response = JsonSerializer.Deserialize<MusicBrainzArtistSearchResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(2, response.Count);
|
||||
Assert.Equal(1, response.Offset);
|
||||
Assert.Equal("artist-id", Assert.Single(response.Artists).Id);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzLabelInfoResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzLabelInfoResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void CatalogNumberAndLabel_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"catalog-number":"EMC 4008","label":{"id":"f0e0e0e0-0000-0000-0000-000000000000","name":"EMI"}}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLabelInfoResponse? response = JsonSerializer.Deserialize<MusicBrainzLabelInfoResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("EMC 4008", response.CatalogNumber);
|
||||
Assert.NotNull(response.Label);
|
||||
Assert.Equal("EMI", response.Label.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"catalog-number": "EMC 4008",
|
||||
"label": { "id": "label-id", "name": "EMI" }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLabelInfoResponse? response = JsonSerializer.Deserialize<MusicBrainzLabelInfoResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("EMC 4008", response.CatalogNumber);
|
||||
Assert.NotNull(response.Label);
|
||||
Assert.Equal("EMI", response.Label.Name);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzLabelResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzLabelResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void NameDisambiguationAndLabelCode_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"id":"f0e0e0e0-0000-0000-0000-000000000000","name":"EMI","disambiguation":"EMI Records Ltd.","label-code":1234}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLabelResponse? response = JsonSerializer.Deserialize<MusicBrainzLabelResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("EMI", response.Name);
|
||||
Assert.Equal("EMI Records Ltd.", response.Disambiguation);
|
||||
Assert.Equal(1234, response.LabelCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "label-id",
|
||||
"name": "EMI",
|
||||
"disambiguation": "EMI Records Ltd.",
|
||||
"label-code": 1234
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLabelResponse? response = JsonSerializer.Deserialize<MusicBrainzLabelResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("label-id", response.Id);
|
||||
Assert.Equal("EMI", response.Name);
|
||||
Assert.Equal("EMI Records Ltd.", response.Disambiguation);
|
||||
Assert.Equal(1234, response.LabelCode);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzLifeSpanResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzLifeSpanResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsEnded_WhenTheMusicBrainzApiReturnsNull_ShouldDeserializeAsNull()
|
||||
{
|
||||
// Arrange
|
||||
// The MusicBrainz search API returns a null ended flag for artists whose end status is unknown, which used to break deserialization into a non-nullable boolean.
|
||||
const string JSON = """{"begin":"1994-01","ended":null}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLifeSpanResponse? response = JsonSerializer.Deserialize<MusicBrainzLifeSpanResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Null(response.IsEnded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsEnded_WhenTheMusicBrainzApiReturnsTrue_ShouldDeserializeAsTrue()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"begin":"1970-06-27","ended":true}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLifeSpanResponse? response = JsonSerializer.Deserialize<MusicBrainzLifeSpanResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.True(response.IsEnded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"begin": "1970-06-27",
|
||||
"end": "1991-11-24",
|
||||
"ended": true
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzLifeSpanResponse? response = JsonSerializer.Deserialize<MusicBrainzLifeSpanResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("1970-06-27", response.Begin);
|
||||
Assert.Equal("1991-11-24", response.End);
|
||||
Assert.True(response.IsEnded);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzMediumResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzMediumResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void PositionFormatAndTrackCount_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"position":1,"title":"Disc 1","format":"CD","track-count":12}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzMediumResponse? response = JsonSerializer.Deserialize<MusicBrainzMediumResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(1, response.Position);
|
||||
Assert.Equal("Disc 1", response.Title);
|
||||
Assert.Equal("CD", response.Format);
|
||||
Assert.Equal(12, response.TrackCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"position": 2,
|
||||
"title": "Disc 2",
|
||||
"format": "Vinyl",
|
||||
"track-count": 8,
|
||||
"tracks": [ { "id": "track-id", "number": "A1", "position": 1, "title": "Death on Two Legs" } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzMediumResponse? response = JsonSerializer.Deserialize<MusicBrainzMediumResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(2, response.Position);
|
||||
Assert.Equal("Disc 2", response.Title);
|
||||
Assert.Equal("Vinyl", response.Format);
|
||||
Assert.Equal(8, response.TrackCount);
|
||||
Assert.Equal("track-id", Assert.Single(response.Tracks).Id);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzRatingResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzRatingResponseTests
|
||||
{
|
||||
private static readonly JsonSerializerOptions s_serializerOptions = new(JsonSerializerDefaults.Web)
|
||||
{
|
||||
NumberHandling = JsonNumberHandling.AllowReadingFromString
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ValueAndVotesCount_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"value":4.5,"votes-count":10}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRatingResponse? response = JsonSerializer.Deserialize<MusicBrainzRatingResponse>(JSON, s_serializerOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(4.5m, response.Value);
|
||||
Assert.Equal(10, response.VotesCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValueAndVotesCount_WhenTheMusicBrainzApiReturnsStrings_ShouldStillDeserializeThem()
|
||||
{
|
||||
// Arrange
|
||||
// The MusicBrainz search API sometimes returns the rating numbers as strings.
|
||||
const string JSON = """{"value":"4.5","votes-count":"10"}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRatingResponse? response = JsonSerializer.Deserialize<MusicBrainzRatingResponse>(JSON, s_serializerOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(4.5m, response.Value);
|
||||
Assert.Equal(10, response.VotesCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"value":4.5,"votes-count":10}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRatingResponse? response = JsonSerializer.Deserialize<MusicBrainzRatingResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(4.5m, response.Value);
|
||||
Assert.Equal(10, response.VotesCount);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzRecordingListResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzRecordingListResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void Recordings_WhenReturnedByTheMusicBrainzIsrcLookup_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"recordings":[{"id":"cb6c5931-436c-38c5-9d24-044f37d1fe35","title":"Death on Two Legs","isrcs":["GBUM71029604"]}]}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingListResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingListResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
MusicBrainzRecordingResponse recording = Assert.Single(response.Recordings);
|
||||
Assert.Equal("Death on Two Legs", recording.Title);
|
||||
Assert.Equal("GBUM71029604", Assert.Single(recording.Isrcs));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"recordings": [ { "id": "recording-id", "title": "Death on Two Legs", "isrcs": [ "GBUM71029604" ] } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingListResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingListResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
MusicBrainzRecordingResponse recording = Assert.Single(response.Recordings);
|
||||
Assert.Equal("recording-id", recording.Id);
|
||||
Assert.Equal("Death on Two Legs", recording.Title);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzRecordingResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzRecordingResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsVideo_WhenTheMusicBrainzApiReturnsNull_ShouldDeserializeAsNull()
|
||||
{
|
||||
// Arrange
|
||||
// The MusicBrainz search API returns a null video flag for most recordings, which used to break deserialization into a non-nullable boolean.
|
||||
const string JSON = """{"id":"8778bb30-2f72-4bc8-8b71-cdbe084036c3","title":"A Kind of Magic","video":null}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Null(response.IsVideo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsVideo_WhenTheMusicBrainzApiReturnsFalse_ShouldDeserializeAsFalse()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"id":"8778bb30-2f72-4bc8-8b71-cdbe084036c3","title":"A Kind of Magic","video":false}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.False(response.IsVideo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "recording-id",
|
||||
"title": "Bohemian Rhapsody",
|
||||
"disambiguation": "album version",
|
||||
"length": 354000,
|
||||
"video": true,
|
||||
"first-release-date": "1975-10-31",
|
||||
"artist-credit": [ { "name": "Queen", "artist": { "id": "artist-id", "name": "Queen" } } ],
|
||||
"isrcs": [ "GBUM71029604" ],
|
||||
"releases": [ { "id": "release-id", "title": "A Night at the Opera" } ],
|
||||
"tags": [ { "name": "rock", "count": 5 } ],
|
||||
"genres": [ { "id": "genre-id", "name": "Rock" } ],
|
||||
"relations": [ { "type": "performance", "work": { "id": "work-id", "title": "Bohemian Rhapsody" } } ],
|
||||
"rating": { "value": 4.5, "votes-count": 10 }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("recording-id", response.Id);
|
||||
Assert.Equal("Bohemian Rhapsody", response.Title);
|
||||
Assert.Equal("album version", response.Disambiguation);
|
||||
Assert.Equal(354000, response.Length);
|
||||
Assert.True(response.IsVideo);
|
||||
Assert.Equal("1975-10-31", response.FirstReleaseDate);
|
||||
Assert.Equal("Queen", Assert.Single(response.ArtistCredit).Name);
|
||||
Assert.Equal("GBUM71029604", Assert.Single(response.Isrcs));
|
||||
Assert.Equal("release-id", Assert.Single(response.Releases).Id);
|
||||
Assert.Equal("rock", Assert.Single(response.Tags).Name);
|
||||
Assert.Equal("Rock", Assert.Single(response.Genres).Name);
|
||||
Assert.Equal("performance", Assert.Single(response.Relations).Type);
|
||||
Assert.NotNull(response.Rating);
|
||||
Assert.Equal(4.5m, response.Rating.Value);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzRecordingSearchResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzRecordingSearchResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void CountOffsetAndRecordings_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"count":1,"offset":0,"recordings":[{"id":"cb6c5931-436c-38c5-9d24-044f37d1fe35","title":"Death on Two Legs"}]}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingSearchResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingSearchResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(1, response.Count);
|
||||
Assert.Equal(0, response.Offset);
|
||||
Assert.Equal("Death on Two Legs", Assert.Single(response.Recordings).Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"count": 3,
|
||||
"offset": 2,
|
||||
"recordings": [ { "id": "recording-id", "title": "Death on Two Legs" } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRecordingSearchResponse? response = JsonSerializer.Deserialize<MusicBrainzRecordingSearchResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(3, response.Count);
|
||||
Assert.Equal(2, response.Offset);
|
||||
Assert.Equal("recording-id", Assert.Single(response.Recordings).Id);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzRelationResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzRelationResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void TypeTargetTypeArtistAndAttributes_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"type": "producer",
|
||||
"type-id": "d0e0e0e0-0000-0000-0000-000000000000",
|
||||
"direction": "backward",
|
||||
"target-type": "artist",
|
||||
"artist": { "id": "cb6c5931-436c-38c5-9d24-044f37d1fe35", "name": "Roy Thomas Baker" },
|
||||
"attributes": [ "producer" ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRelationResponse? response = JsonSerializer.Deserialize<MusicBrainzRelationResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("producer", response.Type);
|
||||
Assert.Equal("backward", response.Direction);
|
||||
Assert.Equal("artist", response.TargetType);
|
||||
Assert.NotNull(response.Artist);
|
||||
Assert.Equal("Roy Thomas Baker", response.Artist.Name);
|
||||
Assert.Equal("producer", Assert.Single(response.Attributes));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"type": "producer",
|
||||
"type-id": "type-id",
|
||||
"direction": "backward",
|
||||
"target-type": "artist",
|
||||
"artist": { "id": "artist-id", "name": "Roy Thomas Baker" },
|
||||
"work": { "id": "work-id", "title": "Bohemian Rhapsody" },
|
||||
"url": { "id": "url-id", "resource": "https://example.com/" },
|
||||
"attributes": [ "producer" ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzRelationResponse? response = JsonSerializer.Deserialize<MusicBrainzRelationResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("producer", response.Type);
|
||||
Assert.Equal("type-id", response.TypeId);
|
||||
Assert.Equal("backward", response.Direction);
|
||||
Assert.Equal("artist", response.TargetType);
|
||||
Assert.NotNull(response.Artist);
|
||||
Assert.Equal("Roy Thomas Baker", response.Artist.Name);
|
||||
Assert.NotNull(response.Work);
|
||||
Assert.Equal("Bohemian Rhapsody", response.Work.Title);
|
||||
Assert.NotNull(response.Url);
|
||||
Assert.Equal("https://example.com/", response.Url.Resource);
|
||||
Assert.Equal("producer", Assert.Single(response.Attributes));
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzReleaseBrowseResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzReleaseBrowseResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void ReleaseCountReleaseOffsetAndReleases_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"release-count":5,"release-offset":2,"releases":[{"id":"11111111-1111-1111-1111-111111111111","title":"A Night at the Opera"}]}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseBrowseResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseBrowseResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(5, response.ReleaseCount);
|
||||
Assert.Equal(2, response.ReleaseOffset);
|
||||
Assert.Equal("A Night at the Opera", Assert.Single(response.Releases).Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"releases": [ { "id": "release-id", "title": "A Night at the Opera" } ],
|
||||
"release-count": 5,
|
||||
"release-offset": 2
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseBrowseResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseBrowseResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("release-id", Assert.Single(response.Releases).Id);
|
||||
Assert.Equal(5, response.ReleaseCount);
|
||||
Assert.Equal(2, response.ReleaseOffset);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzReleaseEventResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzReleaseEventResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void DateAndArea_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"date":"1975-11-21","area":{"id":"c0e0e0e0-0000-0000-0000-000000000000","name":"United Kingdom","iso-3166-1-codes":["GB"]}}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseEventResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseEventResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("1975-11-21", response.Date);
|
||||
Assert.NotNull(response.Area);
|
||||
Assert.Equal("United Kingdom", response.Area.Name);
|
||||
Assert.Equal("GB", Assert.Single(response.Area.Iso3166Part1Codes));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"date": "1975-11-21",
|
||||
"area": { "id": "area-id", "name": "United Kingdom" }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseEventResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseEventResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("1975-11-21", response.Date);
|
||||
Assert.NotNull(response.Area);
|
||||
Assert.Equal("area-id", response.Area.Id);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzReleaseGroupResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzReleaseGroupResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void PrimaryTypeSecondaryTypesAndFirstReleaseDate_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"title": "A Night at the Opera",
|
||||
"primary-type": "Album",
|
||||
"secondary-types": [ "Live" ],
|
||||
"first-release-date": "1975-11-21",
|
||||
"artist-credit": [ { "name": "Queen", "artist": { "id": "cb6c5931-436c-38c5-9d24-044f37d1fe35" } } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseGroupResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseGroupResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("Album", response.PrimaryType);
|
||||
Assert.Equal("Live", Assert.Single(response.SecondaryTypes));
|
||||
Assert.Equal("1975-11-21", response.FirstReleaseDate);
|
||||
Assert.Equal("Queen", Assert.Single(response.ArtistCredit).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "release-group-id",
|
||||
"title": "A Night at the Opera",
|
||||
"disambiguation": "1975 album",
|
||||
"primary-type": "Album",
|
||||
"secondary-types": [ "Live" ],
|
||||
"first-release-date": "1975-11-21",
|
||||
"artist-credit": [ { "name": "Queen", "artist": { "id": "artist-id" } } ],
|
||||
"releases": [ { "id": "release-id", "title": "A Night at the Opera" } ],
|
||||
"tags": [ { "name": "rock", "count": 5 } ],
|
||||
"genres": [ { "id": "genre-id", "name": "Rock" } ],
|
||||
"rating": { "value": 4.5, "votes-count": 10 }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseGroupResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseGroupResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("release-group-id", response.Id);
|
||||
Assert.Equal("A Night at the Opera", response.Title);
|
||||
Assert.Equal("1975 album", response.Disambiguation);
|
||||
Assert.Equal("Album", response.PrimaryType);
|
||||
Assert.Equal("Live", Assert.Single(response.SecondaryTypes));
|
||||
Assert.Equal("1975-11-21", response.FirstReleaseDate);
|
||||
Assert.Equal("Queen", Assert.Single(response.ArtistCredit).Name);
|
||||
Assert.Equal("release-id", Assert.Single(response.Releases).Id);
|
||||
Assert.Equal("rock", Assert.Single(response.Tags).Name);
|
||||
Assert.Equal("Rock", Assert.Single(response.Genres).Name);
|
||||
Assert.NotNull(response.Rating);
|
||||
Assert.Equal(4.5m, response.Rating.Value);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzReleaseGroupSearchResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzReleaseGroupSearchResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void CountOffsetAndReleaseGroups_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"count":2,"offset":1,"release-groups":[{"id":"22222222-2222-2222-2222-222222222222","title":"A Night at the Opera"}]}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseGroupSearchResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseGroupSearchResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(2, response.Count);
|
||||
Assert.Equal(1, response.Offset);
|
||||
Assert.Equal("A Night at the Opera", Assert.Single(response.ReleaseGroups).Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"count": 2,
|
||||
"offset": 1,
|
||||
"release-groups": [ { "id": "release-group-id", "title": "A Night at the Opera" } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseGroupSearchResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseGroupSearchResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(2, response.Count);
|
||||
Assert.Equal(1, response.Offset);
|
||||
Assert.Equal("release-group-id", Assert.Single(response.ReleaseGroups).Id);
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzReleaseResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzReleaseResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void Media_WhenTheRequestIncludesRecordings_ShouldDeserializeTheTracksAndTheirRecordingsWithTheirWorks()
|
||||
{
|
||||
// Arrange
|
||||
// The recordings included in a release lookup already carry the fields the per track lookups return, including the work of each recording.
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "1e14b2d6-8652-3dcc-b60b-4fb5fe79e024",
|
||||
"title": "A Night at the Opera",
|
||||
"media": [
|
||||
{
|
||||
"position": 1,
|
||||
"track-count": 1,
|
||||
"tracks": [
|
||||
{
|
||||
"id": "b1e2c3d4-0000-0000-0000-000000000000",
|
||||
"number": "1",
|
||||
"position": 1,
|
||||
"title": "Death on Two Legs",
|
||||
"length": 223293,
|
||||
"recording": {
|
||||
"id": "cb6c5931-436c-38c5-9d24-044f37d1fe35",
|
||||
"title": "Death on Two Legs (Dedicated To...)",
|
||||
"video": null,
|
||||
"isrcs": [ "GBUM71029604" ],
|
||||
"relations": [
|
||||
{
|
||||
"target-type": "work",
|
||||
"type": "performance",
|
||||
"work": {
|
||||
"id": "d0e0e0e0-0000-0000-0000-000000000000",
|
||||
"title": "Death on Two Legs",
|
||||
"type": "Song",
|
||||
"languages": [ "eng" ],
|
||||
"iswcs": [ "T-010.154.482-4" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
MusicBrainzMediumResponse medium = Assert.Single(response.Media);
|
||||
Assert.Equal(1, medium.TrackCount);
|
||||
MusicBrainzTrackResponse track = Assert.Single(medium.Tracks);
|
||||
Assert.Equal(1, track.Position);
|
||||
Assert.NotNull(track.Recording);
|
||||
Assert.Equal("cb6c5931-436c-38c5-9d24-044f37d1fe35", track.Recording.Id);
|
||||
Assert.Equal("Death on Two Legs (Dedicated To...)", track.Recording.Title);
|
||||
Assert.Null(track.Recording.IsVideo);
|
||||
Assert.Equal("GBUM71029604", Assert.Single(track.Recording.Isrcs));
|
||||
MusicBrainzRelationResponse relation = Assert.Single(track.Recording.Relations);
|
||||
Assert.NotNull(relation.Work);
|
||||
Assert.Equal("Death on Two Legs", relation.Work.Title);
|
||||
Assert.Equal("eng", Assert.Single(relation.Work.Languages));
|
||||
Assert.Equal("T-010.154.482-4", Assert.Single(relation.Work.Iswcs));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "release-id",
|
||||
"title": "A Night at the Opera",
|
||||
"disambiguation": "1975 album",
|
||||
"status": "Official",
|
||||
"date": "1975-11-21",
|
||||
"country": "GB",
|
||||
"release-events": [ { "date": "1975-11-21", "area": { "id": "area-id", "name": "United Kingdom" } } ],
|
||||
"barcode": "0094639819524",
|
||||
"packaging": "Jewel Case",
|
||||
"text-representation": { "language": "eng", "script": "Latn" },
|
||||
"artist-credit": [ { "name": "Queen", "artist": { "id": "artist-id", "name": "Queen" } } ],
|
||||
"release-group": { "id": "release-group-id", "title": "A Night at the Opera" },
|
||||
"label-info": [ { "catalog-number": "EMC 4008", "label": { "id": "label-id", "name": "EMI" } } ],
|
||||
"media": [ { "position": 1, "title": "Disc 1", "format": "CD", "track-count": 12 } ],
|
||||
"asin": "B000000000",
|
||||
"tags": [ { "name": "rock", "count": 5 } ],
|
||||
"genres": [ { "id": "genre-id", "name": "Rock" } ],
|
||||
"relations": [ { "type": "producer", "artist": { "id": "artist-id", "name": "Roy Thomas Baker" } } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzReleaseResponse? response = JsonSerializer.Deserialize<MusicBrainzReleaseResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("release-id", response.Id);
|
||||
Assert.Equal("A Night at the Opera", response.Title);
|
||||
Assert.Equal("1975 album", response.Disambiguation);
|
||||
Assert.Equal("Official", response.Status);
|
||||
Assert.Equal("1975-11-21", response.Date);
|
||||
Assert.Equal("GB", response.Country);
|
||||
Assert.Equal("1975-11-21", Assert.Single(response.ReleaseEvents).Date);
|
||||
Assert.Equal("0094639819524", response.Barcode);
|
||||
Assert.Equal("Jewel Case", response.Packaging);
|
||||
Assert.NotNull(response.TextRepresentation);
|
||||
Assert.Equal("eng", response.TextRepresentation.Language);
|
||||
Assert.Equal("Queen", Assert.Single(response.ArtistCredit).Name);
|
||||
Assert.NotNull(response.ReleaseGroup);
|
||||
Assert.Equal("A Night at the Opera", response.ReleaseGroup.Title);
|
||||
Assert.Equal("EMC 4008", Assert.Single(response.LabelInfo).CatalogNumber);
|
||||
Assert.Equal(1, Assert.Single(response.Media).Position);
|
||||
Assert.Equal("B000000000", response.Asin);
|
||||
Assert.Equal("rock", Assert.Single(response.Tags).Name);
|
||||
Assert.Equal("Rock", Assert.Single(response.Genres).Name);
|
||||
Assert.Equal("producer", Assert.Single(response.Relations).Type);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzTagResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzTagResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void NameCountAndDisambiguation_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"name":"rock","disambiguation":"genre","count":5}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzTagResponse? response = JsonSerializer.Deserialize<MusicBrainzTagResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("rock", response.Name);
|
||||
Assert.Equal("genre", response.Disambiguation);
|
||||
Assert.Equal(5, response.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "genre-id",
|
||||
"name": "rock",
|
||||
"disambiguation": "genre",
|
||||
"count": 5
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzTagResponse? response = JsonSerializer.Deserialize<MusicBrainzTagResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("genre-id", response.Id);
|
||||
Assert.Equal("rock", response.Name);
|
||||
Assert.Equal("genre", response.Disambiguation);
|
||||
Assert.Equal(5, response.Count);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzTextRepresentationResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzTextRepresentationResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void LanguageAndScript_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"language":"eng","script":"Latn"}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzTextRepresentationResponse? response = JsonSerializer.Deserialize<MusicBrainzTextRepresentationResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("eng", response.Language);
|
||||
Assert.Equal("Latn", response.Script);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"language":"eng","script":"Latn"}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzTextRepresentationResponse? response = JsonSerializer.Deserialize<MusicBrainzTextRepresentationResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("eng", response.Language);
|
||||
Assert.Equal("Latn", response.Script);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzTrackResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzTrackResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void NumberPositionLengthAndRecording_WhenTheTrackCarriesARecording_ShouldDeserializeAllOfThem()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "b1e2c3d4-0000-0000-0000-000000000000",
|
||||
"number": "A1",
|
||||
"position": 2,
|
||||
"title": "Death on Two Legs",
|
||||
"length": 223293,
|
||||
"recording": { "id": "cb6c5931-436c-38c5-9d24-044f37d1fe35", "title": "Death on Two Legs (Dedicated To...)" }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzTrackResponse? response = JsonSerializer.Deserialize<MusicBrainzTrackResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("A1", response.Number);
|
||||
Assert.Equal(2, response.Position);
|
||||
Assert.Equal(223293, response.Length);
|
||||
Assert.NotNull(response.Recording);
|
||||
Assert.Equal("cb6c5931-436c-38c5-9d24-044f37d1fe35", response.Recording.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "track-id",
|
||||
"number": "A1",
|
||||
"position": 2,
|
||||
"title": "Death on Two Legs",
|
||||
"length": 223293,
|
||||
"recording": { "id": "recording-id", "title": "Death on Two Legs (Dedicated To...)" }
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzTrackResponse? response = JsonSerializer.Deserialize<MusicBrainzTrackResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("track-id", response.Id);
|
||||
Assert.Equal("A1", response.Number);
|
||||
Assert.Equal(2, response.Position);
|
||||
Assert.Equal("Death on Two Legs", response.Title);
|
||||
Assert.Equal(223293, response.Length);
|
||||
Assert.NotNull(response.Recording);
|
||||
Assert.Equal("recording-id", response.Recording.Id);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzUrlResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzUrlResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void Resource_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"id":"e0e0e0e0-0000-0000-0000-000000000000","resource":"https://www.queenonline.com/"}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzUrlResponse? response = JsonSerializer.Deserialize<MusicBrainzUrlResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("e0e0e0e0-0000-0000-0000-000000000000", response.Id);
|
||||
Assert.Equal("https://www.queenonline.com/", response.Resource);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"id":"url-id","resource":"https://www.queenonline.com/"}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzUrlResponse? response = JsonSerializer.Deserialize<MusicBrainzUrlResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("url-id", response.Id);
|
||||
Assert.Equal("https://www.queenonline.com/", response.Resource);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.MusicBrainz.Common.Models.Contracts.Responses;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.Models.Contracts.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicBrainzWorkResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicBrainzWorkResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void TypeLanguagesAndIswcs_WhenReturnedByTheMusicBrainzApi_ShouldDeserialize()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """{"id":"d0e0e0e0-0000-0000-0000-000000000000","title":"Death on Two Legs","type":"Song","languages":["eng"],"iswcs":["T-010.154.482-4"]}""";
|
||||
|
||||
// Act
|
||||
MusicBrainzWorkResponse? response = JsonSerializer.Deserialize<MusicBrainzWorkResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("Song", response.Type);
|
||||
Assert.Equal("eng", Assert.Single(response.Languages));
|
||||
Assert.Equal("T-010.154.482-4", Assert.Single(response.Iswcs));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenEveryFieldIsPresent_ShouldDeserializeEveryProperty()
|
||||
{
|
||||
// Arrange
|
||||
const string JSON = """
|
||||
{
|
||||
"id": "work-id",
|
||||
"title": "Bohemian Rhapsody",
|
||||
"type": "Song",
|
||||
"disambiguation": "studio version",
|
||||
"languages": [ "eng" ],
|
||||
"iswcs": [ "T-010.154.482-4" ],
|
||||
"relations": [ { "type": "composer", "artist": { "id": "artist-id", "name": "Freddie Mercury" } } ],
|
||||
"tags": [ { "name": "rock", "count": 5 } ],
|
||||
"genres": [ { "id": "genre-id", "name": "Rock" } ]
|
||||
}
|
||||
""";
|
||||
|
||||
// Act
|
||||
MusicBrainzWorkResponse? response = JsonSerializer.Deserialize<MusicBrainzWorkResponse>(JSON);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal("work-id", response.Id);
|
||||
Assert.Equal("Bohemian Rhapsody", response.Title);
|
||||
Assert.Equal("Song", response.Type);
|
||||
Assert.Equal("studio version", response.Disambiguation);
|
||||
Assert.Equal("eng", Assert.Single(response.Languages));
|
||||
Assert.Equal("T-010.154.482-4", Assert.Single(response.Iswcs));
|
||||
Assert.Equal("composer", Assert.Single(response.Relations).Type);
|
||||
Assert.Equal("rock", Assert.Single(response.Tags).Name);
|
||||
Assert.Equal("Rock", Assert.Single(response.Genres).Name);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.MusicBrainz.UnitTests.Common.TestHelpers;
|
||||
|
||||
/// <summary>
|
||||
/// Test HTTP message handler that answers every request with a canned response produced by a factory, and records the requests that were sent.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal sealed class StubHttpMessageHandler : HttpMessageHandler
|
||||
{
|
||||
private readonly Func<HttpRequestMessage, int, HttpResponseMessage> _responseFactory;
|
||||
private int _callCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the requests that were sent through the handler.
|
||||
/// </summary>
|
||||
public List<HttpRequestMessage> Requests { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of requests that were sent through the handler.
|
||||
/// </summary>
|
||||
public int CallCount => _callCount;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StubHttpMessageHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="responseFactory">The factory that produces the response of a request, given the request and its one based call index.</param>
|
||||
public StubHttpMessageHandler(Func<HttpRequestMessage, int, HttpResponseMessage> responseFactory)
|
||||
{
|
||||
_responseFactory = responseFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the provided request, producing its response through the configured factory.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to send.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The response produced for the request.</returns>
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
int callIndex = Interlocked.Increment(ref _callCount);
|
||||
Requests.Add(request);
|
||||
try
|
||||
{
|
||||
return Task.FromResult(_responseFactory(request, callIndex));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// A response factory may throw to simulate a transport failure, which is surfaced as a faulted task.
|
||||
return Task.FromException<HttpResponseMessage>(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user