public async Task DeterminesDeltaOnModification()
        {
            var file         = "BB";
            var readModel    = "AB";
            var fileProvider = Substitute.For <IFileProvider>();

            fileProvider.Exists(Arg.Any <string>()).Returns(true);
            fileProvider.ReadAsync(Arg.Any <string>()).Returns(Encoding.UTF8.GetBytes(file).ToAsyncEnumerable());
            fileProvider.ReadAsync(Arg.Any <Stream>()).Returns(Encoding.UTF8.GetBytes(readModel).ToAsyncEnumerable());
            var eventSource = Substitute.For <IEventSource>();

            eventSource.Rebuild(Arg.Any <string>()).Returns(new Document());
            var watcher = Substitute.For <IFileSystemWatcher>();
            var target  = new SourceControl(fileProvider, eventSource, watcher);
            await target.Add("path");

            watcher.Changed += Raise.Event <FileChangedEventHandler>("path");

            var actual = eventSource.ReceivedCalls().Last().GetArguments().Last();

            actual.Should().BeEquivalentTo(new UpdateEvent
            {
                Updates = new List <Changeset>
                {
                    new Changeset
                    {
                        Offset = 0,
                        Values = Encoding.UTF8.GetBytes("B").ToList()
                    }
                }
            });
        }
        public void AddsFileToSourceColtrol()
        {
            var fileProvider = Substitute.For <IFileProvider>();

            fileProvider.Exists(Arg.Any <string>()).Returns(true);
            var eventSource = Substitute.For <IEventSource>();
            var watcher     = Substitute.For <IFileSystemWatcher>();
            var target      = new SourceControl(fileProvider, eventSource, watcher);

            target.Add("path");

            watcher.Received().Monitor("path");
            eventSource.Received().CreateRepository("path");
        }
        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"));
        }
        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);
        }