public async Task PreviewCommandHandlesValidCommand() { using var file = new TemporaryFile(); var sourceControl = Substitute.For <ISourceControl>(); sourceControl.Preview(Arg.Any <string>(), Arg.Any <int>()).Returns(new Document()); var target = new PreviewCommandHandler(sourceControl); dynamic command = new System.Dynamic.ExpandoObject(); command.Type = "Preview"; command.Path = file.Fullname; command.Bookmark = "4"; command.Destination = "Destination"; await HandleCommand(target, command); await sourceControl.Received().Preview(file.Fullname, 4); }
public async Task PreventsDuplicateEvents() { var eventCount = 0; using (var file = new TemporaryFile()) { var fileProvider = new WindowsFileProvider(); var target = new WindowsFileSystemWatcher(fileProvider); target.Monitor(file.Fullname); target.Changed += (e) => { eventCount++; }; file.Append("test"); file.Append("test"); } await Task.Delay(1000); // Gives the OS enough time to dispatch the event Assert.AreEqual(1, eventCount); }
public async Task AppendsEvents() { var repository = new SqliteRepository(); var fileProvider = new WindowsFileProvider(); var eventStore = new EventSource(repository, fileProvider); using var fileWatcher = new WindowsFileSystemWatcher(fileProvider); using var file = new TemporaryFile(); file.Append("InitialText"); using var target = new SourceControl(fileProvider, eventStore, fileWatcher); await target.Add(file.Fullname); file.Append("AdditionalText"); await Task.Delay(10000); var lines = await repository.ReadRecordsAsync($"{file.Fullname}.events").CountAsync(); Assert.AreEqual(2, lines); }