using System.IO;
using System.Linq;
using Chernobyl.Config;
using Chernobyl.Dependency;
using Chernobyl.IO;
using Chernobyl.Resources;
using NUnit.Framework;
namespace Chernobyl.Reflection.Template.CodeDom
{
///
/// A helper class for test classes that test CodeDom Fall file processing.
///
public class CodeDomTestUtility
{
public CodeDomTestUtility()
{
_core = new Core(new SearchPaths(".", "../../../"));
_codeDomProcessor = _core.ComponentProcessor.First();
_core.Services.Inject(this);
}
[Inject]
public ISearchPaths SearchPaths
{
set
{
value.Add("../../../Chernobyl.Test/Reflection/Template/data/instance");
}
}
///
/// A helper method that creates an from a file.
///
/// The path to the file to load the
/// from.
/// The that was created from the file.
public IInstance FromFile(string filepath)
{
IInstance instance = null;
using (FileSearchStream fileStream = new FileSearchStream(_core.Services, filepath, FileMode.Open))
{
_codeDomProcessor.From(result => instance = (IInstance)result.Resource, fileStream);
}
return instance;
}
IResourceProcessor _codeDomProcessor;
Core _core;
}
}