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 @@ -97,7 +97,7 @@ public class BrewFormulaModel

/// <summary>Gets or sets compile-time options (rarely used).</summary>
[JsonPropertyName("options")]
public string[]? Options { get; set; }
public BrewFormulaOptionModel[]? Options { get; set; }

/// <summary>Gets or sets build-time dependencies.</summary>
[JsonPropertyName("build_dependencies")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Text.Json.Serialization;
using JetBrains.Annotations;

namespace CreativeCoders.MacOS.HomeBrew.Models.Formulae;

/// <summary>
/// Represents a compile-time option for a Homebrew formula.
/// </summary>
[UsedImplicitly]
public class BrewFormulaOptionModel
{
/// <summary>Gets or sets the option flag (e.g. <c>--without-mono</c>).</summary>
[JsonPropertyName("option")]
public string? Option { get; set; }

/// <summary>Gets or sets the human-readable description of the option.</summary>
[JsonPropertyName("description")]
public string? Description { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Text.Json;
using AwesomeAssertions;
using CreativeCoders.MacOS.HomeBrew.Models.Formulae;

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

public class BrewFormulaOptionModelTests
{
[Fact]
public void Deserialize_WhenOptionsContainObjects_ReturnsModelsWithProperties()
{
const string json = """
{
"options": [
{"option": "--without-mono", "description": "Build without mono support"}
]
}
""";

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

result!.Options.Should().HaveCount(1);
result.Options![0].Option.Should().Be("--without-mono");
result.Options[0].Description.Should().Be("Build without mono support");
}

[Fact]
public void Deserialize_WhenOptionsIsEmptyArray_ReturnsEmptyArray()
{
const string json = """{"options": []}""";

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

result!.Options.Should().BeEmpty();
}

[Fact]
public void Deserialize_WhenOptionsIsNull_ReturnsNull()
{
const string json = """{"options": null}""";

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

result!.Options.Should().BeNull();
}

[Fact]
public void Deserialize_WhenOptionsIsMissing_ReturnsNull()
{
const string json = """{}""";

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

result!.Options.Should().BeNull();
}
}
Loading