Skip to content

Instantly share code, notes, and snippets.

@peterkeating
Created October 6, 2012 10:21
Show Gist options
  • Select an option

  • Save peterkeating/3844557 to your computer and use it in GitHub Desktop.

Select an option

Save peterkeating/3844557 to your computer and use it in GitHub Desktop.
Abstract class used to test Nancy modules.
public class CustomRootPathProvider : IRootPathProvider
{
public string GetRootPath()
{
return Path.GetDirectoryName(typeof(Bootstrapper).Assembly.Location);
}
}
public class ModuleTestBase<TModule> where TModule : NancyModule
{
protected ConfigurableBootstrapper Bootstrapper;
protected Browser Browser;
protected BrowserResponse Response;
public ModuleTestBase()
{
Bootstrapper = new ConfigurableBootstrapper(with =>
{
with.Module<TModule>();
with.Dependencies(
Mock<IDependancy>().Object,
Mock<IAnotherDependancy>().Object
);
with.NancyEngine<NancyEngine>();
with.ViewFactory(AutoMoqer.GetMock<IViewFactory>().Object);
with.RootPathProvider<CustomRootPathProvider>();
});
}
protected void Get(string path, Action<BrowserContext> browserContext = null)
{
Browser = new Browser(Bootstrapper);
Response = Browser.Get(path, browserContext);
}
protected void Post(string path, Action<BrowserContext> browserContext = null)
{
Browser = new Browser(Bootstrapper);
Response = Browser.Post(path, browserContext);
}
public void SetView(string path, HtmlResponse htmlResponse)
{
AutoMoqer.GetMock<IViewFactory>().Setup(v => v.RenderView(path, It.IsAny<object>(), It.IsAny<ViewLocationContext>()))
.Returns(htmlResponse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment