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
80 changes: 80 additions & 0 deletions AccessGridTest/AccessPassEventTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace AccessGridTest;

using System.Text.Json;
using System.Text.Json.Serialization;
using AccessGrid;
using NUnit.Framework;

[TestFixture]
public class AccessPassEventTests
{
private JsonSerializerOptions _jsonOptions;

[SetUp]
public void SetUp()
{
_jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverter() }
};
}

[Test]
public void Deserialize_ShouldIncludeAppleUserId_WhenPresent()
{
var json = """
{
"id": "ap_123",
"card_template_id": "ct_456",
"state": "active",
"full_name": "Jane Doe",
"apple_user_id": "001234.abc567def890.1234",
"card_templates": [],
"devices": []
}
""";

var evt = JsonSerializer.Deserialize<AccessPassEvent>(json, _jsonOptions);

Assert.That(evt.AppleUserId, Is.EqualTo("001234.abc567def890.1234"));

Check warning on line 41 in AccessGridTest/AccessPassEventTests.cs

View workflow job for this annotation

GitHub Actions / test (8.0.x)

Dereference of a possibly null reference.
}

[Test]
public void Deserialize_ShouldHaveNullAppleUserId_WhenAbsent()
{
var json = """
{
"id": "ap_123",
"card_template_id": "ct_456",
"state": "active",
"card_templates": [],
"devices": []
}
""";

var evt = JsonSerializer.Deserialize<AccessPassEvent>(json, _jsonOptions);

Assert.That(evt.AppleUserId, Is.Null);

Check warning on line 59 in AccessGridTest/AccessPassEventTests.cs

View workflow job for this annotation

GitHub Actions / test (8.0.x)

Dereference of a possibly null reference.
}

[Test]
public void Deserialize_ShouldHaveNullAppleUserId_WhenExplicitlyNull()
{
var json = """
{
"id": "ap_123",
"card_template_id": "ct_456",
"state": "active",
"apple_user_id": null,
"card_templates": [],
"devices": []
}
""";

var evt = JsonSerializer.Deserialize<AccessPassEvent>(json, _jsonOptions);

Assert.That(evt.AppleUserId, Is.Null);

Check warning on line 78 in AccessGridTest/AccessPassEventTests.cs

View workflow job for this annotation

GitHub Actions / test (8.0.x)

Dereference of a possibly null reference.
}
}
26 changes: 26 additions & 0 deletions AccessGridTest/VersionConsistencyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace AccessGridTest;

using System.IO;
using System.Text.RegularExpressions;
using NUnit.Framework;

[TestFixture]
public class VersionConsistencyTests
{
[Test]
public void ReadmeVersion_ShouldMatchCsprojVersion()
{
var repoRoot = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", ".."));

var csproj = File.ReadAllText(Path.Combine(repoRoot, "src", "AccessGrid.csproj"));
var csprojMatch = Regex.Match(csproj, @"<Version>(.+?)</Version>");
Assert.That(csprojMatch.Success, Is.True, "Could not find <Version> in csproj");

var readme = File.ReadAllText(Path.Combine(repoRoot, "README.md"));
var readmeMatch = Regex.Match(readme, @"-Version\s+(\S+)");
Assert.That(readmeMatch.Success, Is.True, "Could not find version in README");

Assert.That(readmeMatch.Groups[1].Value, Is.EqualTo(csprojMatch.Groups[1].Value),
"README version does not match csproj version");
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Official C# SDK for interacting with the AccessGrid API.
## Installation

```
Install-Package accessgrid -Version 1.2.1
Install-Package accessgrid -Version 1.2.2
```

## Authentication
Expand Down
Loading