-
-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathSentryGraphQlTestHelpers.cs
More file actions
67 lines (61 loc) · 1.94 KB
/
SentryGraphQlTestHelpers.cs
File metadata and controls
67 lines (61 loc) · 1.94 KB
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
namespace Sentry.Tests;
internal static class SentryGraphQlTestHelpers
{
/// <summary>
/// GraphQL Queries get sent in a dictionary using the GraphQL over HTTP protocol
/// </summary>
public static string WrapRequestContent(string queryText)
{
var wrapped = new Dictionary<string, object>()
{
{ "query", queryText }
};
return wrapped.ToJsonString();
}
public static HttpRequestMessage GetRequestQuery(string query, string url = "http://foo")
{
var content = query is not null
? new StringContent(WrapRequestContent(query))
: null;
return GetRequest(content, url);
}
public static HttpRequestMessage GetRequest(HttpContent content, string url = "http://foo") => new(HttpMethod.Post, new Uri(url))
{
Content = content
};
public static StringContent JsonContent(dynamic json)
{
var serialised = JsonSerializer.Serialize(json);
return new(serialised, Encoding.UTF8,
"application/json")
{
Headers = { ContentLength = serialised.Length }
};
}
public static StringContent ResponesContent(string responseText) => JsonContent(
new
{
data = responseText
}
);
/// <summary>
/// e.g.
/// "{"errors": [{"message":"Query does not contain operation \u0027getAllNotes\u0027.","extensions":{"code":"INVALID_OPERATION","codes":["INVALID_OPERATION"]}}]}"
/// </summary>
public static StringContent ErrorContent(string errorMessage, string errorCode) => JsonContent(
new
{
errors = new dynamic[]
{
new
{
message = errorMessage,
extensions = new {
code = errorCode,
codes = new dynamic[]{ errorCode }
}
}
}
}
);
}