Exemplo n.º 1
0
        public async Task Start_Directory_RenameCaptured()
        {
            // arrange
            var dirName = "dir";
            var newName = "dir_new";
            var dirPath = $"{TestFolder}/{dirName}";
            var newPath = $"{TestFolder}/{newName}";

            using var watcher = new FileWatcher($"{TestFolder}");
            Directory.CreateDirectory(dirPath);

            var firstEventTask = SubscribeFirstAsync <IFileEvent, FileRenamed>(watcher.FileObservable());

            // act
            watcher.Start();
            Directory.Move(dirPath, newPath);

            // assert
            var ev = await firstEventTask;

            ev.Should().BeOfType <FileRenamed>();
            ev.As <FileRenamed>().FileName.Should().Be(newName);
            ev.As <FileRenamed>().OldFileName.Should().Be(dirName);
            IsPathEqual(ev.As <FileRenamed>().Path, newPath).Should().BeTrue();
            IsPathEqual(ev.As <FileRenamed>().OldPath, dirPath).Should().BeTrue();
        }
Exemplo n.º 2
0
        public async Task Start_SingleFile_CreateCaptured()
        {
            // arrange
            var fileName = "file.test";
            var filePath = $"{TestFolder}/{fileName}";

            using var watcher = new FileWatcher($"{TestFolder}");

            var firstEventTask = SubscribeFirstAsync <IFileEvent, FileCreated>(watcher.FileObservable());

            // act
            watcher.Start();
            await using var file = File.Create(filePath);

            // assert
            var ev = await firstEventTask;

            ev.Should().BeOfType <FileCreated>();
            ev.As <FileCreated>().FileName.Should().Be(fileName);
            IsPathEqual(ev.As <FileCreated>().Path, filePath).Should().BeTrue();
        }
Exemplo n.º 3
0
        public async Task Start_SingleFile_RenameCaptured()
        {
            // arrange
            var fileName = "file.test";
            var newName  = "file_new.test";
            var filePath = $"{TestFolder}/{fileName}";
            var newPath  = $"{TestFolder}/{newName}";

            using var watcher    = new FileWatcher($"{TestFolder}");
            await using var file = File.Create(filePath);
            await file.DisposeAsync();

            var firstEventTask = SubscribeFirstAsync <IFileEvent, IFileEvent>(watcher.FileObservable());

            // act
            watcher.Start();
            File.Move(filePath, newPath);

            // assert
            var ev = await firstEventTask;

            // different behaviour on windows and linux
            if (ev is FileRenamed)
            {
                ev.Should().BeOfType <FileRenamed>();
                ev.As <FileRenamed>().FileName.Should().Be(newName);
                ev.As <FileRenamed>().OldFileName.Should().Be(fileName);
                IsPathEqual(ev.As <FileRenamed>().Path, newPath).Should().BeTrue();
                IsPathEqual(ev.As <FileRenamed>().OldPath, filePath).Should().BeTrue();
                return;
            }

            ev.Should().BeOfType <FileCreated>();
            ev.As <FileCreated>().FileName.Should().Be(newName);
            IsPathEqual(ev.As <FileCreated>().Path, newPath).Should().BeTrue();
        }