From f371fdc6f303b70a6370721d60433de03d9116bd Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Mon, 19 Oct 2026 19:10:50 +0200 Subject: [PATCH] Update `CompatibilityVersion` in `BrewFormulaModel` to `int?` and add deserialization tests. --- .../Models/Formulae/BrewFormulaModel.cs | 2 +- .../Models/Formulae/BrewFormulaModelTests.cs | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/CreativeCoders.MacOS.HomeBrew.Tests/Models/Formulae/BrewFormulaModelTests.cs diff --git a/source/CreativeCoders.MacOS.HomeBrew/Models/Formulae/BrewFormulaModel.cs b/source/CreativeCoders.MacOS.HomeBrew/Models/Formulae/BrewFormulaModel.cs index 1119e5c..da5c03c 100644 --- a/source/CreativeCoders.MacOS.HomeBrew/Models/Formulae/BrewFormulaModel.cs +++ b/source/CreativeCoders.MacOS.HomeBrew/Models/Formulae/BrewFormulaModel.cs @@ -65,7 +65,7 @@ public class BrewFormulaModel /// Gets or sets the compatibility version, if provided. [JsonPropertyName("compatibility_version")] - public string? CompatibilityVersion { get; set; } + public int? CompatibilityVersion { get; set; } /// Gets or sets whether autobump is enabled for the formula. [JsonPropertyName("autobump")] diff --git a/tests/CreativeCoders.MacOS.HomeBrew.Tests/Models/Formulae/BrewFormulaModelTests.cs b/tests/CreativeCoders.MacOS.HomeBrew.Tests/Models/Formulae/BrewFormulaModelTests.cs new file mode 100644 index 0000000..1784483 --- /dev/null +++ b/tests/CreativeCoders.MacOS.HomeBrew.Tests/Models/Formulae/BrewFormulaModelTests.cs @@ -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(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(json); + + // Assert + result!.CompatibilityVersion.Should().BeNull(); + } + + [Fact] + public void Deserialize_WhenCompatibilityVersionIsMissing_ReturnsNull() + { + // Arrange + const string json = """{}"""; + + // Act + var result = JsonSerializer.Deserialize(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(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(); + } +}