Skip to content

Instantly share code, notes, and snippets.

@rarous
Created January 15, 2014 14:38
Show Gist options
  • Save rarous/8437413 to your computer and use it in GitHub Desktop.
Save rarous/8437413 to your computer and use it in GitHub Desktop.
public class FormReaders
{
const string SlovakConnectors = "MultiConnector.Connectors.Svk.*.dll";
public static IEnumerable<object[]> Connectors
{
get
{
var currentDir = Path.GetFullPath(".");
return from file in Directory.EnumerateFiles(currentDir, SlovakConnectors)
orderby file
let asm = Assembly.LoadFile(file)
from type in asm.GetTypes()
where typeof(IConnector).IsAssignableFrom(type)
&& !type.IsAbstract
select new object[] { type, file };
}
}
[Theory]
[PropertyData("Connectors")]
public void ConnectorShouldHaveCorrespondingFormReader(Type connector, string file)
{
var uiAsm = Assembly.Load(file.Replace(".dll", ".UI.dll"));
var readers = from type in uiAsm.GetTypes()
where typeof(IFormReader).IsAssignableFrom(type)
&& !type.IsAbstract
select type;
Assert.True(readers.Any(x =>
x.Name.Replace("FormReader", "") == connector.Name.Replace("Connector", "")),
String.Format("Connector {0} does not have form reader defined.", connector.Name));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment