forked from NancyFx/Nancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Nancy Testing View Location
philjones88 edited this page Jan 24, 2013
·
1 revision
By default Nancy unit tests will struggle to find view files when you run your tests.
You can create the following file in your test project to help Nancy out.
public class TestingRootPathProvider : IRootPathProvider
{
private static readonly string RootPath;
static TestingRootPathProvider()
{
var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);
if (directoryName != null)
{
var assemblyPath = directoryName.Replace(@"file:\", string.Empty);
RootPath = Path.Combine(assemblyPath, "..", "..", "..", "Escape.Web");
}
}
public string GetRootPath()
{
return RootPath;
}
}
You will have to alter RootPath to match your solutions layout and target project's folder name. The idea is you want your view engine to not look in "bin/debug" for views but instead look in your target project for the views.
This is accomplished by using ".." to go up a folder level until you can then go into your target project.
- Taking a look at the DynamicDictionary
- The before and after module hooks
- Model binding
- Bootstrapper
- View Engines
- View location conventions
- Testing your application
- The root path
- Managing static content
- Diagnostics
- Adding a custom FavIcon
- The Application Before, After and OnError pipelines
- Generating a custom error page
- The cryptography helpers
- Content negotiation
- Authentication
- More to come
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Blog Posts, Video & Audio
- Async-Beta (Async Beta)