Skip to content

Commit 4abdcc1

Browse files
Added test for null cases as well
1 parent 67b82bd commit 4abdcc1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

sample/SampleServer/SampleServer.csproj

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

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>

src/JsonRpc/Serialization/Converters/EnumLikeStringConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ JsonSerializer serializer
1616
( reader.TokenType, Nullable.GetUnderlyingType(objectType) ) switch {
1717
(JsonToken.String, null) => (IEnumLikeString) Activator.CreateInstance(objectType, (string) reader.Value),
1818
(JsonToken.String, { } realType) => (IEnumLikeString) Activator.CreateInstance(realType, (string) reader.Value),
19-
_ => (IEnumLikeString) Activator.CreateInstance(objectType, null)
19+
(_, { }) => (IEnumLikeString) Activator.CreateInstance(objectType, null),
20+
_ => null
2021
};
2122

2223
public override bool CanRead => true;

test/Dap.Tests/EnumLikeConverterTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public void PathFormat_Should_Be_Serializable()
2323
[Fact]
2424
public void PathFormat_Should_Be_Deserializable()
2525
{
26-
Action a = () => new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\": \"Uri\"}");
27-
a.Should().NotThrow();
26+
Func<InitializeRequestArguments> a = () => new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\": \"Uri\"}");
27+
a.Should().NotThrow().Subject.PathFormat.Should().NotBeNull();
28+
}
29+
[Fact]
30+
public void PathFormat_Should_Be_Deserializable_When_Null()
31+
{
32+
var a = new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\":null}");
33+
a.PathFormat.Should().BeNull();
2834
}
2935
}
3036
}

0 commit comments

Comments
 (0)