-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathDebugAdapterSpecifictionRecieverTests.cs
141 lines (125 loc) · 6.06 KB
/
DebugAdapterSpecifictionRecieverTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System.Linq;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.DebugAdapter.Protocol;
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
using OmniSharp.Extensions.DebugAdapter.Protocol.Serialization;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.JsonRpc.Server;
using OmniSharp.Extensions.JsonRpc.Server.Messages;
using Xunit;
namespace Dap.Tests
{
public class DebugAdapterSpecificationReceiverTests
{
[Theory]
[ClassData(typeof(SpecificationMessages))]
public void ShouldRespond_AsExpected(string json, Renor[] request)
{
var receiver = new DapReceiver();
var inSerializer = new DapProtocolSerializer();
var outSerializer = new DapProtocolSerializer();
var (requests, _) = receiver.GetRequests(JToken.Parse(json));
var result = requests.ToArray();
request.Length.Should().Be(result.Length);
for (var i = 0; i < request.Length; i++)
{
var r = request[i];
var response = result[i];
inSerializer.SerializeObject(response)
.Should().Be(outSerializer.SerializeObject(r));
}
}
[Fact]
public void Should_Camel_Case_As_Expected()
{
var serializer = new DapProtocolSerializer();
var response = serializer.SerializeObject(
new InitializeResponse() {
SupportsCancelRequest = true
}
);
response.Should().Be("{\"supportsConfigurationDoneRequest\":false,\"supportsFunctionBreakpoints\":false,\"supportsConditionalBreakpoints\":false,\"supportsHitConditionalBreakpoints\":false,\"supportsEvaluateForHovers\":false,\"supportsStepBack\":false,\"supportsSetVariable\":false,\"supportsRestartFrame\":false,\"supportsGotoTargetsRequest\":false,\"supportsStepInTargetsRequest\":false,\"supportsCompletionsRequest\":false,\"supportsModulesRequest\":false,\"supportsRestartRequest\":false,\"supportsExceptionOptions\":false,\"supportsValueFormattingOptions\":false,\"supportsExceptionInfoRequest\":false,\"supportTerminateDebuggee\":false,\"supportsDelayedStackTraceLoading\":false,\"supportsLoadedSourcesRequest\":false,\"supportsLogPoints\":false,\"supportsTerminateThreadsRequest\":false,\"supportsSetExpression\":false,\"supportsTerminateRequest\":false,\"supportsDataBreakpoints\":false,\"supportsReadMemoryRequest\":false,\"supportsDisassembleRequest\":false,\"supportsCancelRequest\":true,\"supportsBreakpointLocationsRequest\":false,\"supportsClipboardContext\":false,\"supportsSteppingGranularity\":false,\"supportsInstructionBreakpoints\":false}");
}
private class SpecificationMessages : TheoryData<string, Renor[]>
{
public SpecificationMessages()
{
Add(
@"{""seq"": ""0"", ""type"": ""request"", ""command"": ""attach"", ""arguments"": { ""__restart"": 3 }}",
new Renor[] {
new Request(0, "attach", new JObject { { "__restart", 3 } })
}
);
Add(
@"{""seq"": ""1"", ""type"": ""request"", ""command"": ""attach""}",
new Renor[] {
new Request(1, "attach", new JObject())
}
);
Add(
@"{""seq"": ""0"", ""type"": ""event"", ""event"": ""breakpoint"", ""body"": { ""reason"": ""new"" }}",
new Renor[] {
new Notification("breakpoint", new JObject { { "reason", "new" } }),
}
);
Add(
@"{""seq"": ""1"", ""type"": ""event"", ""event"": ""breakpoint""}",
new Renor[] {
new Notification("breakpoint", null)
}
);
Add(
@"{""seq"": ""1"", ""type"": ""response"", ""request_seq"": 3, ""success"": true, ""command"": ""attach"", ""body"": { }}",
new Renor[] {
new ServerResponse(3, new JObject()),
}
);
Add(
@"{""seq"": ""1"", ""type"": ""response"", ""request_seq"": 3, ""success"": true, ""command"": ""attach"", ""body"": null}",
new Renor[] {
new ServerResponse(3, null),
}
);
// Add (
// @"{""seq"": ""1"", ""type"": ""response"", ""request_seq"": 3, ""success"": false, ""command"": ""attach"", ""body"": { }}",
// new Renor[]
// {
// new ServerError(3, new ServerErrorResult()),
// }
// );
Add(
@"{""seq"": ""1"", ""type"": ""response"", ""request_seq"": 3, ""success"": false, ""command"": ""attach"", ""body"": null}",
new Renor[] {
new ServerError(3, new ServerErrorResult(-1, "Unknown Error", new JObject())),
}
);
Add(
@"[1]",
new Renor[] {
new InvalidRequest(string.Empty, "Not an object")
}
);
}
}
[Theory]
[ClassData(typeof(InvalidMessages))]
public void Should_ValidateInvalidMessages(string json, bool expected)
{
var receiver = new DapReceiver();
var result = receiver.IsValid(JToken.Parse(json));
result.Should().Be(expected);
}
private class InvalidMessages : TheoryData<string, bool>
{
public InvalidMessages()
{
Add(@"[]", false);
Add(@"""""", false);
Add(@"1", false);
Add(@"true", false);
Add(@"{}", true);
}
}
}
}