using Recordingtest.DiffReporter; using Recordingtest.Player; using Recordingtest.Player.Model; using Recordingtest.Runner; namespace Recordingtest.Runner.Tests; public sealed class FakePlayerHost : IPlayerHost { private readonly string _outDir; private readonly string _resultContent; private readonly bool _throwOnClick; public FakePlayerHost(string outDir, string resultContent, bool throwOnClick = false) { _outDir = outDir; _resultContent = resultContent; _throwOnClick = throwOnClick; } public ResolvedElement? ResolveElement(string uiaPath, TimeSpan timeout) => new ResolvedElement(new ElementBounds(0, 0, 10, 10), null); public bool WaitFor(string waitForHint, TimeSpan timeout) => true; public void Click(ScreenPoint point) { if (_throwOnClick) throw new InvalidOperationException("fake click failure"); } public void Type(string text) { } public void Drag(ScreenPoint from, ScreenPoint to) { } public void Hotkey(string keys) { // simulate save Directory.CreateDirectory(_outDir); File.WriteAllText(Path.Combine(_outDir, "result.json"), _resultContent); } public void CaptureCheckpoint(int afterStep, string saveAs) { } public void CaptureFailureArtifacts(int stepIndex, string reason) { } } public sealed class FakeHostFactory : IRunnerHostFactory { private readonly string _resultContent; private readonly bool _throwOnClick; public FakeHostFactory(string resultContent, bool throwOnClick = false) { _resultContent = resultContent; _throwOnClick = throwOnClick; } public IPlayerHost Create(Scenario scenario, string outDir) => new FakePlayerHost(outDir, _resultContent, _throwOnClick); } public sealed class SpyNormalizer : INormalizer { public List Profiles { get; } = new(); public string Normalize(string input, string profile, string? sidecarPath) { Profiles.Add(profile); return input; } } public sealed class StubDiffer : IDiffer { private readonly bool _identical; private readonly int _hunkCount; public StubDiffer(bool identical, int hunkCount = 0) { _identical = identical; _hunkCount = hunkCount; } public DiffResult Compare(string approvedPath, string receivedPath) { var hunks = new List(); for (int i = 0; i < _hunkCount; i++) hunks.Add(new Hunk(i, "changed", "a", "b")); return new DiffResult(Path.GetFileName(receivedPath), _identical, hunks, new DiffSummary(0, 0, _hunkCount)); } }