Files
Nemera/tests/UnitTests/Lumina.Plugins.MusicBrainz.UnitTests/Common/Models/Contracts/Responses/MusicBrainzLifeSpanResponseTests.cs
T
BinaryAlley 057f557791 Formats code comments as sentences in the tests.
Capitalizes the first word and adds the terminal period in the unit, integration and security tests. The AAA markers stay bare, the TODO bodies stay lowercase, and no assertion, payload, expected status code or test signature changes.
2026-11-16 18:17:29 +02:00

66 lines
2.1 KiB
C#

#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);
}
}