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
2 changes: 1 addition & 1 deletion sample/SampleServer/SampleServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<IsPackable>false</IsPackable>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public override IEnumLikeString ReadJson(
bool hasExistingValue,
JsonSerializer serializer
) =>
reader.TokenType switch {
JsonToken.String => (IEnumLikeString) Activator.CreateInstance(objectType, (string) reader.Value),
_ => (IEnumLikeString) Activator.CreateInstance(objectType, null)
( reader.TokenType, Nullable.GetUnderlyingType(objectType) ) switch {
(JsonToken.String, null) => (IEnumLikeString) Activator.CreateInstance(objectType, (string) reader.Value),
(JsonToken.String, { } realType) => (IEnumLikeString) Activator.CreateInstance(realType, (string) reader.Value),
(_, { }) => (IEnumLikeString) Activator.CreateInstance(objectType, null),
_ => null
};

public override bool CanRead => true;
Expand Down
36 changes: 36 additions & 0 deletions test/Dap.Tests/EnumLikeConverterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using FluentAssertions;
using OmniSharp.Extensions.DebugAdapter.Client;
using OmniSharp.Extensions.DebugAdapter.Protocol;
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
using Xunit;

namespace Dap.Tests
{
public class EnumLikeConverterTests
{
[Fact]
public void PathFormat_Should_Be_Serializable()
{
var options = new InitializeRequestArguments() {
PathFormat = PathFormat.Uri
};

Action a = () => new DapSerializer().SerializeObject(options);
a.Should().NotThrow();
}
[Fact]
public void PathFormat_Should_Be_Deserializable()
{
Func<InitializeRequestArguments> a = () => new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\": \"Uri\"}");
a.Should().NotThrow().Subject.PathFormat.Should().NotBeNull();
}
[Fact]
public void PathFormat_Should_Be_Deserializable_When_Null()
{
var a = new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\":null}");
a.PathFormat.Should().BeNull();
}
}
}