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
23 changes: 23 additions & 0 deletions tests/TraceClient.Tests/InstallIdTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Xunit;

Expand Down Expand Up @@ -84,6 +85,28 @@ public void InstallIdFromFile_KeepsALineExactlyAtTheLimit()
Assert.Equal(atTheLimit + "\n", File.ReadAllText(path)); // not replaced
}

[Theory]
[InlineData("utf-8")]
[InlineData("utf-8-bom")]
[InlineData("utf-16")]
public void InstallIdFromFile_KeepsAHandEditedWindowsFileAsIs(string encoding)
{
// "Put your own value in it": a file saved by Notepad has CRLF line
// endings and may start with a byte order mark, or be UTF-16 outright.
Directory.CreateDirectory(_directory);
string path = Path.Combine(_directory, "install-id");
Encoding chosen = encoding == "utf-8" ? new UTF8Encoding(false)
: encoding == "utf-8-bom" ? new UTF8Encoding(true)
: Encoding.Unicode;
File.WriteAllText(path, "my-own-id \r\nsecond\r\n", chosen);
byte[] before = File.ReadAllBytes(path);

string id = TraceClient.InstallIdFromFile(path);

Assert.Equal("my-own-id", id);
Assert.Equal(before, File.ReadAllBytes(path)); // not replaced
}

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