Skip to content
Merged
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
39 changes: 39 additions & 0 deletions tests/TraceClient.Tests/TraceClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,45 @@ public void Quote_EscapesCarriageReturnAndEveryOtherControlCharacter()
Assert.Equal("\" \u00e9/\u00fc\"", TraceClient.Quote(" \u00e9/\u00fc"));
}

[Fact]
public void Quote_WritesDeleteAndTheUnicodeLineSeparatorsAsIs()
{
// JSON only requires U+0000-U+001F to be escaped, so DEL and the
// line/paragraph separators are valid as they are and go out unescaped.
Assert.Equal("\"\u007f\u2028\u2029\"", TraceClient.Quote("\u007f\u2028\u2029"));
}

[Fact]
public void Json_EscapesTheApplicationNameAndTagKeysLikeTagValues()
{
// Every string in the body goes through Quote, not only tag values.
var tags = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("k\"1", "v"),
new KeyValuePair<string, string>("line\nkey", "v"),
};

Assert.Null(TraceClient.Json("My \"Game\"", "a\\b", null, tags, out string json));

Assert.Equal("{\"application\":\"My \\\"Game\\\"\",\"name\":\"a\\\\b\","
+ "\"tags\":{\"k\\\"1\":\"v\",\"line\\nkey\":\"v\"}}", json);
}

[Fact]
public void Report_SendsTheNameAndTagsUntrimmed()
{
// The constructor trims the application, version and key; Report
// sends an event's name, tag keys and tag values exactly as given.
var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k");

client.Report(" startup\t", tags: new Dictionary<string, string> { { " k ", " v " } });
client.Close();

Assert.Equal("{\"application\":\"MyGame\",\"name\":\" startup\\t\","
+ "\"tags\":{\" k \":\" v \",\"version\":\"1.2.3\"}}",
_server.Received.Single().Body);
}

[Fact]
public void EnvironmentDisables_IsFalseWhenTheEnvironmentCannotBeRead()
{
Expand Down
Loading