public void AddsTwoFilesToListWhenAddingDefaultFileName() { var updated = new ManualResetEvent(false); var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(0); folder.Watcher.Created += (sender, args) => { updated.Set(); }; var filename = folder.IndexFileName; var filepath = Path.Combine(path, filename); File.WriteAllText(filepath, "for testing purposes - delete me"); updated.WaitOne(1000, false); folder.DirectoryListing.Count.ShouldBe(2); folder.DirectoryListing.Count(x => x.Key == $"/{filename}" && x.Value == filepath).ShouldBe(1); folder.CleanUp(); }
public void UpdatesIndexerWhenChangingFromDefaultFileName() { var updated = new ManualResetEvent(false); var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); var filepath = Path.Combine(path, PublicFolder.DefaultIndexFileName); var newfilepath = Path.Combine(path, GenerateUniqueString()); File.WriteAllText(filepath, "for testing purposes - delete me"); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(2); folder.DirectoryListing.Count(x => x.Value == filepath).ShouldBe(2); folder.DirectoryListing.Count(x => x.Key == $"/{PublicFolder.DefaultIndexFileName}").ShouldBe(1); folder.Watcher.Renamed += (sender, args) => { updated.Set(); }; File.Move(filepath, newfilepath); updated.WaitOne(1000, false); folder.DirectoryListing.Count.ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == newfilepath).ShouldBe(1); folder.DirectoryListing.Count(x => x.Key == $"/{PublicFolder.DefaultIndexFileName}").ShouldBe(0); folder.CleanUp(); }
public void DirectoryListingIsUpdatedWhenDefaultFileNameChanges() { var defaultFileName1 = PublicFolder.DefaultIndexFileName; const string defaultFileName2 = "default.html"; var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); File.WriteAllText(Path.Combine(path, defaultFileName1), "for testing purposes - delete me"); File.WriteAllText(Path.Combine(path, defaultFileName2), "for testing purposes - delete me"); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(3); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName1)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName2)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == Path.Combine(folder.FolderPath, defaultFileName1)).ShouldBe(2); folder.IndexFileName = defaultFileName2; folder.DirectoryListing.Count.ShouldBe(3); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName2)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName2)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == Path.Combine(folder.FolderPath, defaultFileName2)).ShouldBe(2); folder.CleanUp(); }
public void CreatesFolderIfNotExists() { var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.Exists(path).ShouldBeFalse(); var folder = new PublicFolder(path); Directory.Exists(path).ShouldBeTrue(); folder.CleanUp(); }
public void RelativePathShouldBeRelativeToCurrentFolder() { const string path = "temp"; var folder = new PublicFolder(path); folder.IndexFileName.ShouldBe(PublicFolder.DefaultIndexFileName); folder.FolderPath.ShouldBe(Path.Combine(Directory.GetCurrentDirectory(), path)); folder.Prefix.Equals(string.Empty).ShouldBeTrue(); folder.DirectoryListing.Any().ShouldBeFalse(); folder.CleanUp(); }
public void AbsolutePathShouldNotChange() { string path = Path.Combine(Path.GetTempPath(), "kjhgf"); var folder = new PublicFolder(path); folder.IndexFileName.ShouldBe(PublicFolder.DefaultIndexFileName); folder.FolderPath.ShouldBe(path); folder.Prefix.Equals(string.Empty).ShouldBeTrue(); folder.DirectoryListing.Any().ShouldBeFalse(); folder.CleanUp(); }
public void AbsolutePathShouldNotChange() { const string path = @"C:\temp"; var folder = new PublicFolder(path); folder.IndexFileName.ShouldBe(PublicFolder.DefaultIndexFileName); folder.FolderPath.ShouldBe(path); folder.Prefix.Equals(string.Empty).ShouldBeTrue(); folder.DirectoryListing.Any().ShouldBeFalse(); folder.CleanUp(); }
public void PathAndPrefixSetsPrefix() { var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); const string prefix = "testing"; var folder = new PublicFolder(path, prefix); folder.IndexFileName.ShouldBe(PublicFolder.DefaultIndexFileName); folder.FolderPath.ShouldBe(path); folder.Prefix.Equals($"/{prefix}").ShouldBeTrue(); folder.DirectoryListing.Any().ShouldBeFalse(); folder.CleanUp(); }
public void DefaultFileNameShowsInDirectoryListingForFileAndFolder() { var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); File.WriteAllText(Path.Combine(path, PublicFolder.DefaultIndexFileName), "for testing purposes - delete me"); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(2); folder.DirectoryListing.Count(x => x.Key.EndsWith(PublicFolder.DefaultIndexFileName)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == Path.Combine(folder.FolderPath, PublicFolder.DefaultIndexFileName)).ShouldBe(2); folder.CleanUp(); }
public void RemovesDeletedFilesFromList() { var updated = new ManualResetEvent(false); var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); var filepath = Path.Combine(path, GenerateUniqueString()); File.WriteAllText(filepath, "for testing purposes - delete me"); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(1); folder.Watcher.Deleted += (sender, args) => { updated.Set(); }; File.Delete(filepath); updated.WaitOne(1000, false); folder.DirectoryListing.Count.ShouldBe(0); folder.CleanUp(); }
public void Dispose() { _folder.CleanUp(); }