public void TestMonitorUpdateFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int updates = 0;
                    monitor.FileUpdated += _ => updates++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    using (var stream = storage.GetStream(name, FileAccess.Write, FileMode.Open))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write("Hello");
                            writer.Flush();
                        }

                    Thread.Sleep(10);

                    Assert.IsTrue(updates == 1);
                }
        }
        public void TestAttemptEscapeRoot()
        {
            var guid = new Guid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.Throws <ArgumentException>(() => storage.GetStream("../test"));
                Assert.Throws <ArgumentException>(() => storage.GetStorageForDirectory("../"));
            }
        }
        public void TestMonitorAddFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int creates = 0;
                    monitor.FileCreated += _ => creates++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    Assert.IsTrue(monitor.Files.Contains(name));
                    Assert.IsTrue(creates == 1);
                }
        }
        public void TestMonitorRenameFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int renames = 0;
                    monitor.FileRenamed += (_, __) => renames++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    string nameReplace = Guid.NewGuid().ToString();
                    var    fi          = new FileInfo(storage.GetFullPath(name));
                    fi.MoveTo(Path.Combine(storage.GetFullPath(string.Empty), nameReplace));

                    Thread.Sleep(10);

                    Assert.IsTrue(monitor.Files.Contains(nameReplace));
                    Assert.IsTrue(renames == 1);
                }
        }