Skip to content

Commit fe11626

Browse files
committed
Merge branch 'v4'
2 parents 2bd887e + 7207545 commit fe11626

16 files changed

Lines changed: 155 additions & 86 deletions

GlobalSuppressions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented")]
1717
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601:Partial elements should be documented")]
18+
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented")]
1819
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1611:Element parameters should be documented")]
1920
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1615:Element return value should be documented")]
2021
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:Property summary documentation must match accessors")]

PassKitHelper.Tests/PassKitHelper.Tests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0</TargetFrameworks>
4+
<TargetFrameworks>netframework4.8;net6.0;net8.0;net9.0</TargetFrameworks>
55

66
<LangVersion>8.0</LangVersion>
77
<Nullable>enable</Nullable>
@@ -16,6 +16,10 @@
1616
<EmbeddedResource Include="res\*.*" />
1717
</ItemGroup>
1818

19+
<ItemGroup Condition="'$(TargetFramework)' == 'netframework4.8'">
20+
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.34" />
21+
</ItemGroup>
22+
1923
<ItemGroup>
2024
<PackageReference Include="JsonDiffPatch.Net" Version="2.3.0" />
2125
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />

PassKitHelper.Tests/PassKitMiddlewareTests_Logs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task ServiceIsCalled()
4848
{
4949
using (var sw = new StreamWriter(body, Encoding.Default, 2048, true))
5050
{
51-
await sw.WriteAsync("{ logs: [\"log line 1\", \"log line 2\" ] }");
51+
await sw.WriteAsync("{ \"logs\": [\"log line 1\", \"log line 2\" ] }");
5252
}
5353

5454
body.Position = 0;

PassKitHelper.Tests/SamplePassesTest.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace PassKitHelper
22
{
33
using System;
44
using System.IO;
5+
using System.Text;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Linq;
78
using Xunit;
@@ -27,7 +28,7 @@ public SamplePassesTest(ITestOutputHelper output)
2728
[Fact]
2829
public void Coupon()
2930
{
30-
var actual = new PassBuilder()
31+
var pass = new PassBuilder()
3132
.Standard
3233
.PassTypeIdentifier("pass.com.apple.devpubs.example")
3334
.SerialNumber("E5982H-I2")
@@ -58,6 +59,9 @@ public void Coupon()
5859
.DateStyle(DateStyle.Short)
5960
.Build();
6061

62+
var json = Encoding.UTF8.GetString(pass.ToArray());
63+
var actual = JToken.Parse(json);
64+
6165
output.WriteLine("Actual JSON:");
6266
output.WriteLine(actual.ToString(Formatting.Indented));
6367

@@ -75,7 +79,7 @@ public void Coupon()
7579
[Fact]
7680
public void Event()
7781
{
78-
var actual = new PassBuilder()
82+
var pass = new PassBuilder()
7983
.Standard
8084
.PassTypeIdentifier("pass.com.apple.devpubs.example")
8185
.SerialNumber("nmyuxofgna")
@@ -104,6 +108,9 @@ public void Event()
104108
.Value("Moscone West")
105109
.Build();
106110

111+
var json = Encoding.UTF8.GetString(pass.ToArray());
112+
var actual = JToken.Parse(json);
113+
107114
output.WriteLine("Actual JSON:");
108115
output.WriteLine(actual.ToString(Formatting.Indented));
109116

@@ -121,7 +128,7 @@ public void Event()
121128
[Fact]
122129
public void StoreCard()
123130
{
124-
var actual = new PassBuilder()
131+
var pass = new PassBuilder()
125132
.Standard
126133
.PassTypeIdentifier("pass.com.apple.devpubs.example")
127134
.SerialNumber("p69f2J")
@@ -150,6 +157,9 @@ public void StoreCard()
150157
.Value("Lemons")
151158
.Build();
152159

160+
var json = Encoding.UTF8.GetString(pass.ToArray());
161+
var actual = JToken.Parse(json);
162+
153163
output.WriteLine("Actual JSON:");
154164
output.WriteLine(actual.ToString(Formatting.Indented));
155165

@@ -164,7 +174,7 @@ public void StoreCard()
164174
Assert.True(JToken.DeepEquals(expected, actual));
165175
}
166176

167-
private JObject? LoadFromResource(string name)
177+
private JToken? LoadFromResource(string name)
168178
{
169179
using var stream = this.GetType().Assembly.GetManifestResourceStream($"PassKitHelper.res.{name}");
170180

@@ -174,7 +184,7 @@ public void StoreCard()
174184
}
175185

176186
var json = new StreamReader(stream).ReadToEnd();
177-
return JsonConvert.DeserializeObject<JObject>(json, PassBuilder.JsonSettings);
187+
return JToken.Parse(json);
178188
}
179189
}
180190
}

PassKitHelper.sln

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29215.179
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3DE6FB8D-8225-4E4A-B065-3A2ECCC88B06}"
77
ProjectSection(SolutionItems) = preProject
8+
.editorconfig = .editorconfig
89
.gitignore = .gitignore
910
GlobalSuppressions.cs = GlobalSuppressions.cs
1011
how_to_create_pfx.md = how_to_create_pfx.md

PassKitHelper/Extensions/DateTimeOffsetExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace System
22
{
3-
using System;
43
using System.Globalization;
54

65
internal static class DateTimeOffsetExtensions

PassKitHelper/Extensions/PassBuilderVisualAppearanceBuilderExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace PassKitHelper
22
{
3-
using System;
4-
53
public static class PassBuilderVisualAppearanceBuilderExtensions
64
{
75
/// <summary>

PassKitHelper/Extensions/PassPackageBuilderExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace PassKitHelper
22
{
3-
using System;
43
using System.IO;
54
using System.Runtime.CompilerServices;
65

PassKitHelper/IPassKitService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.IO;
55
using System.Threading.Tasks;
6-
using Newtonsoft.Json.Linq;
76

87
public interface IPassKitService
98
{
@@ -53,7 +52,7 @@ public interface IPassKitService
5352
/// If there are no matching passes, returns HTTP status 204.
5453
/// Otherwise, returns the appropriate standard HTTP status.
5554
/// </returns>
56-
Task<(int status, string[]? passes, string? tag)> GetAssociatedPassesAsync(string deviceLibraryIdentifier, string passTypeIdentifier, string? tag);
55+
Task<(int Status, string[]? Passes, string? Tag)> GetAssociatedPassesAsync(string deviceLibraryIdentifier, string passTypeIdentifier, string? tag);
5756

5857
/// <summary>
5958
/// Getting the Latest Version of a Pass.
@@ -65,10 +64,10 @@ public interface IPassKitService
6564
/// <returns>
6665
/// If request is authorized, returns HTTP status 200 with a payload of the pass data (signed and built pass package, timestamp of last change).
6766
/// If the request is not authorized, returns HTTP status 401 (and null as pass data).
68-
/// If no data has changed since <see cref="ifModifiedSince"/> - return HTTP status code 304 (and null as pass data).
67+
/// If no data has changed since <paramref name="ifModifiedSince"/> - return HTTP status code 304 (and null as pass data).
6968
/// Otherwise, returns the appropriate standard HTTP status (and null as pass data).
7069
/// </returns>
71-
Task<(int statusCode, MemoryStream? passData, DateTimeOffset? lastModified)> GetPassAsync(string passTypeIdentifier, string serialNumber, string authorizationToken, DateTimeOffset? ifModifiedSince);
70+
Task<(int StatusCode, MemoryStream? PassData, DateTimeOffset? LastModified)> GetPassAsync(string passTypeIdentifier, string serialNumber, string authorizationToken, DateTimeOffset? ifModifiedSince);
7271

7372
/// <summary>
7473
/// Logging Errors. Log messages contain a description of the error in a human-readable format.

PassKitHelper/PassBuilder.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,34 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.IO;
56
using System.Runtime.CompilerServices;
7+
using System.Text;
8+
9+
#if NETSTANDARD2_0
610
using Newtonsoft.Json;
7-
using Newtonsoft.Json.Linq;
811
using Newtonsoft.Json.Serialization;
12+
#else
13+
using System.Text.Json;
14+
using System.Text.Json.Serialization;
15+
#endif
916

1017
public class PassBuilder
1118
{
19+
#if NETSTANDARD2_0
1220
public static readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings
1321
{
1422
ContractResolver = new DefaultContractResolver() { NamingStrategy = new CamelCaseNamingStrategy() },
1523
NullValueHandling = NullValueHandling.Ignore,
1624
DateParseHandling = DateParseHandling.DateTimeOffset,
1725
};
26+
#else
27+
public static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions()
28+
{
29+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
30+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
31+
};
32+
#endif
1833

1934
private readonly IDictionary<string, object> values;
2035

@@ -89,9 +104,17 @@ public Dictionary<string, object> CreateBag(string name)
89104
return (Dictionary<string, object>)dic;
90105
}
91106

92-
public JObject Build()
107+
public MemoryStream Build()
93108
{
94-
return JObject.FromObject(values, JsonSerializer.Create(JsonSettings));
109+
#if NETSTANDARD2_0
110+
var jsonString = JsonConvert.SerializeObject(values, JsonSettings);
111+
return new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
112+
#else
113+
var ms = new MemoryStream();
114+
JsonSerializer.Serialize(ms, values, JsonOptions);
115+
ms.Position = 0;
116+
return ms;
117+
#endif
95118
}
96119

97120
public class StandardBuilder : PassBuilder
@@ -278,7 +301,11 @@ public Barcode(string message, BarcodeFormat format)
278301
[JsonIgnore]
279302
public BarcodeFormat Format { get; set; }
280303

304+
#if NETSTANDARD2_0
281305
[JsonProperty("format")]
306+
#else
307+
[JsonPropertyName("format")]
308+
#endif
282309
public string FormatAsString
283310
{
284311
get => Format.ToPassKitString();

0 commit comments

Comments
 (0)