diff --git a/MarkdownToSiteGenerator/FileSourceProvider.cs b/MarkdownToSiteGenerator/FileSourceProvider.cs index d417206..1ff90f9 100644 --- a/MarkdownToSiteGenerator/FileSourceProvider.cs +++ b/MarkdownToSiteGenerator/FileSourceProvider.cs @@ -1,33 +1,33 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MarkdownToSiteGenerator -{ - internal class FileSourceProvider : ISourceFileProvider - { - /// - /// Location of the config file relative to the top directory - /// - public const string Loc_config_relative = "config.ini"; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MarkdownToSiteGenerator +{ + internal class FileSourceProvider : ISourceFileProvider + { + /// + /// Location of the config file relative to the top directory + /// + public const string Loc_config_relative = "config.ini"; readonly FilePath dir_top; static readonly IReadOnlyList ImageSuffixes = new string[] { ".jpg", ".jpeg", ".bmp", ".png", ".gif", ".webp" - }; - - public FileSourceProvider(FilePath dir_top) - { - if (!dir_top.IsDirectory) - { - throw new ArgumentException($"File path must explicitly be a directory (end with {Path.DirectorySeparatorChar})"); - } - this.dir_top = dir_top; - } - + }; + + public FileSourceProvider(FilePath dir_top) + { + if (!dir_top.IsDirectory) + { + throw new ArgumentException($"File path must explicitly be a directory (end with {Path.DirectorySeparatorChar})"); + } + this.dir_top = dir_top; + } + public async Task GetFileContent(FilePath path) => await File.ReadAllTextAsync(path.ToString()); public Stream GetImageFileContent(FilePath imInfo) => File.OpenRead(imInfo.ToString()); public FilePath[] GetFileLocations(FileTypes sourceFilesOnly) @@ -44,13 +44,13 @@ public FilePath[] GetFileLocations(FileTypes sourceFilesOnly) return Directory.EnumerateFiles(dir_top.ToAbsoluteString(),"*", SearchOption.AllDirectories) .Where(a => extensions.Contains(Path.GetExtension(a), StringComparer.InvariantCultureIgnoreCase)) - .Select(a => new FilePath(a)) + .Select(a => new FilePath(a)) .ToArray(); - } - public async Task GetConfigurationFileContent() - { - string path = (dir_top + Loc_config_relative).ToString(); - return File.Exists(path) ? await GetFileContent(path) : null; + } + public async Task GetConfigurationFileContent() + { + string path = (dir_top + Loc_config_relative).ToString(); + return File.Exists(path) ? await GetFileContent(path) : null; } public string GetImageTitle(FilePath path) @@ -66,5 +66,5 @@ public string GetImageTitle(FilePath path) } - } -} + } +} diff --git a/MarkdownToSiteGeneratorUnitTests/FileSourceProviderTests.cs b/MarkdownToSiteGeneratorUnitTests/FileSourceProviderTests.cs index 68882a2..7f4759d 100644 --- a/MarkdownToSiteGeneratorUnitTests/FileSourceProviderTests.cs +++ b/MarkdownToSiteGeneratorUnitTests/FileSourceProviderTests.cs @@ -89,6 +89,11 @@ public void GetFileLocations(FileTypes ft, int expectedFrom, int count) dir + "bob.md", dir + "bob2.md", dir + "config.ini", // shouldn't be found + dir + ".gitattributes", // shouldn't be found + dir + ".gitignore", // shouldn't be found + dir + "launch.sh", // shouldn't be found + dir + "launch.bash", // shouldn't be found + dir + "build.ps1", // shouldn't be found }; try