Files
DodoSSH/tests/DodoSSH.Client.App.Tests/CrashLogTests.cs
T

42 lines
1.3 KiB
C#

using DodoSSH.Client.App.Platform;
using DodoSSH.Client.Session;
namespace DodoSSH.Client.App.Tests;
/// <summary>
/// That the application leaves a record of why it died.
/// </summary>
/// <remarks>
/// An exception nothing caught used to close the window and leave nothing at all behind. Installing the hooks
/// here also installs them in the test process, which is harmless: they only write to this test's own
/// directory, and only when something reaches the top.
/// </remarks>
public sealed class CrashLogTests : IDisposable
{
private readonly string directory =
Path.Combine(Path.GetTempPath(), $"dodossh-crash-{Guid.CreateVersion7():N}");
public void Dispose()
{
if (Directory.Exists(directory))
{
Directory.Delete(directory, recursive: true);
}
}
[Fact]
public void AnExceptionThatReachesTheTop_IsWrittenToTheProfile()
{
var paths = new ClientPaths(directory);
CrashLog.Install(paths);
CrashLog.Write("UI thread", new InvalidOperationException("the thing nobody caught"));
var written = File.ReadAllText(paths.CrashLogFile);
written.ShouldContain("UI thread");
written.ShouldContain("the thing nobody caught");
written.ShouldContain(nameof(InvalidOperationException));
}
}