diff --git a/AccessGridTest/AccessPassEventTests.cs b/AccessGridTest/AccessPassEventTests.cs new file mode 100644 index 0000000..01860cf --- /dev/null +++ b/AccessGridTest/AccessPassEventTests.cs @@ -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(json, _jsonOptions); + + Assert.That(evt.AppleUserId, Is.EqualTo("001234.abc567def890.1234")); + } + + [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(json, _jsonOptions); + + Assert.That(evt.AppleUserId, Is.Null); + } + + [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(json, _jsonOptions); + + Assert.That(evt.AppleUserId, Is.Null); + } +} diff --git a/AccessGridTest/VersionConsistencyTests.cs b/AccessGridTest/VersionConsistencyTests.cs new file mode 100644 index 0000000..7089269 --- /dev/null +++ b/AccessGridTest/VersionConsistencyTests.cs @@ -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, @"(.+?)"); + Assert.That(csprojMatch.Success, Is.True, "Could not find 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"); + } +} diff --git a/README.md b/README.md index d8fe4d2..6a7d1f8 100644 --- a/README.md +++ b/README.md @@ -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