using System; using System.Collections.Generic; using Amphora; using Annulus; using Azimuth; using Glass; using Glass.Blacklight; using UnitTestSharp; using Action = System.Action; namespace Foundations.UnitTests { public class ExceptionReportWindowTests : TestFixture { public static readonly Duration Frame = Duration.FromMilliseconds(16); public static readonly Vector RoomyScreen = new Vector(1000, 700); public class RecordingClipboard : IClipboard { public bool Accepts = true; public Exception Fault; public string Text; public bool TryOpenText(out IClipboardText text) { text = null; return false; } public bool SetText(IChunkedText text) { if (Fault != null) { throw Fault; } if (Accepts) { Text = text.ToText(); } return Accepts; } } public class Rig { public int QuitCount; public readonly ExceptionReporter Reporter; public readonly Screen Screen; public readonly ExceptionReportWindow Window; public readonly RecordingClipboard Clipboard = new RecordingClipboard(); public Rig(bool developerMode = false, Vector? screenSize = null) { VectorSkin skin = VectorSkinTests.BuiltSkin(); Reporter = new ExceptionReporter(developerMode, () => ++QuitCount); Screen = new Screen(Reporter.Sandbox) { Size = screenSize ?? RoomyScreen }; Screen.KeyboardManager.Clipboard = Clipboard; Window = new ExceptionReportWindow(Reporter, skin.MakeReportLook()); } public void RunFrame() { Reporter.Sandbox.Advance(Frame); Window.Sync(Screen); Screen.Update(Frame); } public ExceptionEntry Throw(string message, ExceptionSeverity severity = ExceptionSeverity.StateSuspect, HostWork work = null) { try { throw new InvalidOperationException(message); } catch (Exception exception) { return Reporter.Sandbox.Record(exception, new ExceptionSite(work ?? new HostWork("update"), phase: 0), notes: null, severity); } } public void Press(Button button) { button.Activate(Screen.KeyboardManager.Held, Screen.KeyboardManager); } public List