private void When_unlocking_bytes_in_stream_it_must_not_raise_events()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";
            string       filePath         = Path.Combine(directoryToWatch, "file.txt");

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingBinaryFile(filePath, BufferFactory.Create(4096))
                                        .Build();

            using (IFileStream stream = fileSystem.File.Open(filePath, FileMode.Open))
            {
                stream.Lock(0, 256);

                using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch))
                {
                    watcher.NotifyFilter          = TestNotifyFilters.All;
                    watcher.IncludeSubdirectories = true;

                    using (var listener = new FileSystemWatcherEventListener(watcher))
                    {
                        // Act
                        stream.Unlock(0, 256);

                        watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds);

                        // Assert
                        listener.EventsCollected.Should().BeEmpty();
                    }
                }
            }
        }
Beispiel #2
0
        private void When_locking_segment_in_stream_it_must_not_update_file_timings()
        {
            // Arrange
            const string path = @"C:\some\file.txt";

            DateTime creationTimeUtc = 17.March(2006).At(14, 03, 53).AsUtc();
            var      clock           = new SystemClock(() => creationTimeUtc);

            IFileSystem fileSystem = new FakeFileSystemBuilder(clock)
                                     .IncludingTextFile(path, DefaultContents)
                                     .Build();

            using (IFileStream stream = fileSystem.File.Open(path, FileMode.Open, FileAccess.ReadWrite))
            {
                DateTime changeTimeUtc = 18.March(2006).At(14, 03, 53).AsUtc();
                clock.UtcNow = () => changeTimeUtc;

                // Act
                stream.Lock(0, DefaultContents.Length);
            }

            // Assert
            fileSystem.File.GetCreationTimeUtc(path).Should().Be(creationTimeUtc);
            fileSystem.File.GetLastWriteTimeUtc(path).Should().Be(creationTimeUtc);
            fileSystem.File.GetLastAccessTimeUtc(path).Should().Be(creationTimeUtc);
        }