-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestOutputLogger.cs
More file actions
78 lines (72 loc) · 2.54 KB
/
TestOutputLogger.cs
File metadata and controls
78 lines (72 loc) · 2.54 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
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Contentstack.Management.Core.Tests.Helpers
{
public static class TestOutputLogger
{
private const string START_MARKER = "###TEST_OUTPUT_START###";
private const string END_MARKER = "###TEST_OUTPUT_END###";
public static void LogAssertion(string assertionName, object expected, object actual, bool passed)
{
Emit(new Dictionary<string, object>
{
{ "type", "ASSERTION" },
{ "assertionName", assertionName },
{ "expected", expected?.ToString() ?? "null" },
{ "actual", actual?.ToString() ?? "null" },
{ "passed", passed }
});
}
public static void LogHttpRequest(string method, string url,
IDictionary<string, string> headers, string body,
string curlCommand, string sdkMethod)
{
Emit(new Dictionary<string, object>
{
{ "type", "HTTP_REQUEST" },
{ "method", method ?? "" },
{ "url", url ?? "" },
{ "headers", headers ?? new Dictionary<string, string>() },
{ "body", body ?? "" },
{ "curlCommand", curlCommand ?? "" },
{ "sdkMethod", sdkMethod ?? "" }
});
}
public static void LogHttpResponse(int statusCode, string statusText,
IDictionary<string, string> headers, string body)
{
Emit(new Dictionary<string, object>
{
{ "type", "HTTP_RESPONSE" },
{ "statusCode", statusCode },
{ "statusText", statusText ?? "" },
{ "headers", headers ?? new Dictionary<string, string>() },
{ "body", body ?? "" }
});
}
public static void LogContext(string key, string value)
{
Emit(new Dictionary<string, object>
{
{ "type", "CONTEXT" },
{ "key", key ?? "" },
{ "value", value ?? "" }
});
}
private static void Emit(object data)
{
try
{
var json = JsonConvert.SerializeObject(data, Formatting.None);
Console.Write(START_MARKER);
Console.Write(json);
Console.WriteLine(END_MARKER);
}
catch
{
// Never let logging break a test
}
}
}
}