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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class BrewFormulaModel

/// <summary>Gets or sets the compatibility version, if provided.</summary>
[JsonPropertyName("compatibility_version")]
public string? CompatibilityVersion { get; set; }
public int? CompatibilityVersion { get; set; }

/// <summary>Gets or sets whether autobump is enabled for the formula.</summary>
[JsonPropertyName("autobump")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Text.Json;
using AwesomeAssertions;
using CreativeCoders.MacOS.HomeBrew.Models;
using CreativeCoders.MacOS.HomeBrew.Models.Formulae;

namespace CreativeCoders.MacOS.HomeBrew.Tests.Models.Formulae;

public class BrewFormulaModelTests
{
[Fact]
public void Deserialize_WhenCompatibilityVersionIsNumber_ReturnsNumber()
{
// Arrange
const string json = """{"compatibility_version": 3}""";

// Act
var result = JsonSerializer.Deserialize<BrewFormulaModel>(json);

// Assert
result!.CompatibilityVersion.Should().Be(3);
}

[Fact]
public void Deserialize_WhenCompatibilityVersionIsNull_ReturnsNull()
{
// Arrange
const string json = """{"compatibility_version": null}""";

// Act
var result = JsonSerializer.Deserialize<BrewFormulaModel>(json);

// Assert
result!.CompatibilityVersion.Should().BeNull();
}

[Fact]
public void Deserialize_WhenCompatibilityVersionIsMissing_ReturnsNull()
{
// Arrange
const string json = """{}""";

// Act
var result = JsonSerializer.Deserialize<BrewFormulaModel>(json);

// Assert
result!.CompatibilityVersion.Should().BeNull();
}

[Fact]
public void Deserialize_WhenInstalledFormulaeHaveNumericCompatibilityVersion_ReturnsAllFormulae()
{
// Arrange
const string json = """
{
"formulae": [
{"name": "abseil", "compatibility_version": 3},
{"name": "wget", "compatibility_version": null}
],
"casks": []
}
""";

// Act
var result = JsonSerializer.Deserialize<BrewInstalledModel>(json);

// Assert
result!.Formulae.Should().HaveCount(2);
result.Formulae[0].Name.Should().Be("abseil");
result.Formulae[0].CompatibilityVersion.Should().Be(3);
result.Formulae[1].Name.Should().Be("wget");
result.Formulae[1].CompatibilityVersion.Should().BeNull();
}
}
Loading