Exemple #1
0
        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);
        }
        public async Task CreatesEventsFile()
        {
            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);

            Assert.IsTrue(fileProvider.Exists($"{file.Fullname}.events"));
            Assert.IsFalse(fileProvider.IsEmpty($"{file.Fullname}.events"));
        }