Skip to content

Commit a018572

Browse files
committed
Add .net9.0 supports
- Enable multiple target frameworks for Test project - Enable RespectNullable and RequiredConstructor option in Interpreter when run on .9.0
1 parent 5dc89fd commit a018572

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

TouchSenderInterpreter.Test/InterpreterTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,39 @@ public void Read_InvalidJson_ReturnsFailureResult(string invalidJson)
138138
Assert.NotNull(result.ErrorMessage);
139139
}
140140

141+
/// <summary>
142+
/// Test the Read method with an empty JSON payload.
143+
///
144+
/// for .NET 9.0 or greater, it should return a failure result
145+
/// for .NET 8.0 or lower, it should return a success result with null payload
146+
/// </summary>
147+
[Theory]
148+
[InlineData("{}")]
149+
[InlineData("{\"Id\":0,\"DeviceInfo\":null,\"SingleTouch\":null}")]
150+
public void Read_EmptyJson_ReturnsUnsucceededResult(string invalidJson)
151+
{
152+
// Log
153+
output.WriteLine(invalidJson);
154+
155+
// Arrange
156+
var input = Encoding.UTF8.GetBytes(invalidJson);
157+
158+
// Act
159+
var result = Interpreter.Read(input);
160+
output.WriteLine(result.ToString());
161+
162+
// Assert
163+
#if NET9_0_OR_GREATER
164+
Assert.False(result.IsSuccess);
165+
Assert.Null(result.Payload);
166+
Assert.NotNull(result.ErrorMessage);
167+
#else
168+
Assert.True(result.IsSuccess);
169+
Assert.NotNull(result.Payload);
170+
Assert.Null(result.ErrorMessage);
171+
#endif
172+
}
173+
141174
/// <summary>
142175
/// Test the Equals method with different payloads
143176
/// </summary>

TouchSenderInterpreter.Test/TouchSenderInterpreter.Test.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

TouchSenderInterpreter/Interpreter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ public class Interpreter
99

1010
private static readonly JsonSerializerOptions _options = new()
1111
{
12-
PropertyNameCaseInsensitive = true
12+
PropertyNameCaseInsensitive = true,
13+
#if NET9_0_OR_GREATER
14+
RespectNullableAnnotations = true,
15+
RespectRequiredConstructorParameters = true,
16+
#endif
1317
};
1418

1519
public static TouchSenderResult Read(byte[] input)

TouchSenderInterpreter/TouchSenderInterpreter.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<Copyright>Copyright (c) Voltaney 2025</Copyright>

0 commit comments

Comments
 (0)