Created
October 6, 2012 10:21
-
-
Save peterkeating/3844557 to your computer and use it in GitHub Desktop.
Abstract class used to test Nancy modules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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