Skip to content

Commit

Permalink
added slight test depth
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeReid1 committed Dec 29, 2022
1 parent 23c4a57 commit ae00920
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
66 changes: 33 additions & 33 deletions MarkdownToSiteGenerator/FileSourceProvider.cs
Original file line number Diff line number Diff line change
@@ -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<FilePath>
{
/// <summary>
/// Location of the config file relative to the top directory
/// </summary>
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<FilePath>
{
/// <summary>
/// Location of the config file relative to the top directory
/// </summary>
public const string Loc_config_relative = "config.ini";
readonly FilePath dir_top;

static readonly IReadOnlyList<string> 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<string> GetFileContent(FilePath path) => await File.ReadAllTextAsync(path.ToString());
public Stream GetImageFileContent(FilePath imInfo) => File.OpenRead(imInfo.ToString());
public FilePath[] GetFileLocations(FileTypes sourceFilesOnly)
Expand All @@ -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<string?> GetConfigurationFileContent()
{
string path = (dir_top + Loc_config_relative).ToString();
return File.Exists(path) ? await GetFileContent(path) : null;
}
public async Task<string?> GetConfigurationFileContent()
{
string path = (dir_top + Loc_config_relative).ToString();
return File.Exists(path) ? await GetFileContent(path) : null;
}

public string GetImageTitle(FilePath path)
Expand All @@ -66,5 +66,5 @@ public string GetImageTitle(FilePath path)
}


}
}
}
}
5 changes: 5 additions & 0 deletions MarkdownToSiteGeneratorUnitTests/FileSourceProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae00920

Please sign in to comment.