Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/Hqub.MusicBrainz.Tests/AreaGetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace Hqub.MusicBrainz.Tests
{
using Hqub.MusicBrainz.Entities;
using NUnit.Framework;
using System.Linq;
using System.Threading.Tasks;

// Resource: area-get.json
// URL: https://musicbrainz.org/ws/2/area/c9ac1239-e832-41bc-9930-e252a1fd1105?inc=area-rels&fmt=json

public class AreaGetTests
{
private Area area;

[OneTimeSetUp]
public async Task Init()
{
var client = new MusicBrainzClient()
{
Cache = EmbeddedResourceCache.Instance
};

string[] inc = ["area-rels"];

area = await client.Area.GetAsync("c9ac1239-e832-41bc-9930-e252a1fd1105", inc);
}

[Test]
public void TestAreaElements()
{
Assert.That(area.Id, Is.EqualTo("c9ac1239-e832-41bc-9930-e252a1fd1105"));
Assert.That(area.Type, Is.EqualTo("City"));
Assert.That(area.Name, Is.EqualTo("Berlin"));
Assert.That(area.Relations, Is.Not.Null);
Assert.That(area.Iso2Codes, Is.Not.Null);
}

[Test]
public void TestAreaForwardRelations()
{
var list = area.Relations.Where(r => r.TargetType == "area" && r.Direction == "forward");

Assert.That(list.Count(), Is.GreaterThanOrEqualTo(6));
}

[Test]
public void TestAreaBackwardRelations()
{
var list = area.Relations.Where(r => r.TargetType == "area" && r.Direction == "backward");

Assert.That(list.Count(), Is.EqualTo(1));

var relation = list.First();

Assert.That(relation.Area, Is.Not.Null);
Assert.That(relation.Area.Type, Is.EqualTo("Country"));
Assert.That(relation.Area.Name, Is.EqualTo("Germany"));

}
}
}
17 changes: 17 additions & 0 deletions src/Hqub.MusicBrainz/Entities/Area.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Hqub.MusicBrainz.Entities
[DataContract(Name = "area")]
public class Area : IEntity
{
#region Properties

/// <summary>
/// Gets or sets the MusicBrainz id.
/// </summary>
Expand Down Expand Up @@ -52,5 +54,20 @@ public class Area : IEntity
/// </summary>
[DataMember(Name = "iso-3166-2-codes")]
public List<string> Iso2Codes { get; set; }

#endregion

#region Sub-queries

/// <summary>
/// Gets or sets a list of relations associated to this area.
/// </summary>
/// <example>
/// var e = await client.Area.GetAsync(mbid, "area-rels");
/// </example>
[DataMember(Name = "relations")]
public List<Relation> Relations { get; set; }

#endregion
}
}
6 changes: 6 additions & 0 deletions src/Hqub.MusicBrainz/Entities/Relation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class Relation
[DataMember(Name = "work")]
public Work Work { get; set; }

/// <summary>
/// Gets or sets the area relationship (include area-rels).
/// </summary>
[DataMember(Name = "area")]
public Area Area { get; set; }

// Other relationships:
//
// /// <summary>
Expand Down
8 changes: 7 additions & 1 deletion src/Hqub.MusicBrainz/MusicBrainzClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@
/// </summary>
public ILookupService<Work> Work { get; }

/// <summary>
/// Gets the area entity lookup service.
/// </summary>
public ILookupService<Area> Area { get; }

#endregion

/// <summary>
/// Gets or sets the <see cref="IRequestCache"/> implementation.
/// </summary>
public IRequestCache Cache { get; set; }

private HttpClient client;
private readonly HttpClient client;

/// <summary>
/// Initializes a new instance of the <see cref="MusicBrainzClient"/> class.
Expand Down Expand Up @@ -116,6 +121,7 @@
ReleaseGroups = new ReleaseGroupService(this, urlBuilder);

Work = new LookupService<Work>(this, urlBuilder, "work");
Area = new LookupService<Area>(this, urlBuilder, "area");

client = httpClient;
}
Expand All @@ -133,7 +139,7 @@
{
/// <summary>The error message.</summary>
[DataMember(Name = "error")]
public string Message;

Check warning on line 142 in src/Hqub.MusicBrainz/MusicBrainzClient.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Field 'MusicBrainzClient.ResponseError.Message' is never assigned to, and will always have its default value null

Check warning on line 142 in src/Hqub.MusicBrainz/MusicBrainzClient.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Field 'MusicBrainzClient.ResponseError.Message' is never assigned to, and will always have its default value null

Check warning on line 142 in src/Hqub.MusicBrainz/MusicBrainzClient.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Field 'MusicBrainzClient.ResponseError.Message' is never assigned to, and will always have its default value null

Check warning on line 142 in src/Hqub.MusicBrainz/MusicBrainzClient.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Field 'MusicBrainzClient.ResponseError.Message' is never assigned to, and will always have its default value null
}

internal async Task<T> GetAsync<T>(string url, CancellationToken ct = default)
Expand Down