using System.Collections.Generic;
using System.IO;
using WireMock.Handlers;
namespace WireMock.Net.ConsoleApplication
{
internal class CustomFileSystemFileHandler : IFileSystemHandler
{
private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings");
///
public bool FolderExists(string path)
{
return Directory.Exists(path);
}
///
public void CreateFolder(string path)
{
Directory.CreateDirectory(path);
}
///
public IEnumerable EnumerateFiles(string path)
{
return Directory.EnumerateFiles(path);
}
///
public string GetMappingFolder()
{
return Path.Combine(@"c:\temp-wiremock", AdminMappingsFolder);
}
///
public string ReadMappingFile(string path)
{
return File.ReadAllText(path);
}
///
public void WriteMappingFile(string path, string text)
{
File.WriteAllText(path, text);
}
///
public byte[] ReadResponseBodyAsFile(string path)
{
return File.ReadAllBytes(Path.GetFileName(path) == path ? Path.Combine(GetMappingFolder(), path) : path);
}
///
public string ReadResponseBodyAsString(string path)
{
return File.ReadAllText(Path.GetFileName(path) == path ? Path.Combine(GetMappingFolder(), path) : path);
}
///
public bool FileExists(string path)
{
return File.Exists(AdjustPath(path));
}
///
public void WriteFile(string path, byte[] bytes)
{
File.WriteAllBytes(AdjustPath(path), bytes);
}
///
public void DeleteFile(string path)
{
File.Delete(AdjustPath(path));
}
///
public byte[] ReadFile(string path)
{
return File.ReadAllBytes(AdjustPath(path));
}
///
/// Adjusts the path to the MappingFolder.
///
/// The path.
/// Adjusted path
private string AdjustPath(string path)
{
return Path.Combine(GetMappingFolder(), path);
}
}
}