NancyFx 测试:找不到类型或命名空间 Bootstrapper
NancyFx testing: The type or namespace Bootstrapper cannot be found
更新:我用
解决了我的问题
var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);
与
var directoryName = AppDomain.CurrentDomain.BaseDirectory;
所以现在测试工作正常。无论如何,如果有人可以使原始代码正常工作(可能是在解释为什么 Bootstraper 比我的解决方案更好 :) 所以我可以理解为什么在这里使用
原题
我刚刚在 C# 中使用 Nancyfx,但我上周才重新开始使用 C# 工作,可能我遗漏了很多与 dot.net 和 C# 相关的概念,将学习关于本周末的那些
尝试为 nancy 模块创建一些测试(我使用 NancyFx 的 Nunit 和辅助测试 class)我遇到的问题是这些测试必须使用我为其编写测试的项目的路径对于(例如,我在 TestProject 中编写了那些测试,并且我正在测试 SelfHostNancyProject)。
所以我需要明确地解决这个问题(实际上我手动复制了 TestProject 的 Views 目录中的项目 SelfHostNancyProject 的 Views 目录)。
但是即使使用自动 post-build 命令复制那些 dir/files 也不是最好的方法。
我发现了这个解决方案
https://github.com/NancyFx/Nancy/wiki/Nancy-Testing-View-Location
但是在我的代码中复制 class TestingRootPathProvider 的代码我有错误
The type or namespace Bootstrapper cannot be found
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;
}
}
但是在 google 周围徘徊,我找不到解决方案。我看到这似乎与应用程序初始化有关
What are Bootstrappers/Bootstrapping in C#
但无论如何,我不明白我必须执行哪个导入(如果有的话)来解决问题,或者可能是我遗漏了什么。
我用
解决了我的问题
var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);
有
var directoryName = AppDomain.CurrentDomain.BaseDirectory;
更新:我用
解决了我的问题var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);
与
var directoryName = AppDomain.CurrentDomain.BaseDirectory;
所以现在测试工作正常。无论如何,如果有人可以使原始代码正常工作(可能是在解释为什么 Bootstraper 比我的解决方案更好 :) 所以我可以理解为什么在这里使用
原题
我刚刚在 C# 中使用 Nancyfx,但我上周才重新开始使用 C# 工作,可能我遗漏了很多与 dot.net 和 C# 相关的概念,将学习关于本周末的那些
尝试为 nancy 模块创建一些测试(我使用 NancyFx 的 Nunit 和辅助测试 class)我遇到的问题是这些测试必须使用我为其编写测试的项目的路径对于(例如,我在 TestProject 中编写了那些测试,并且我正在测试 SelfHostNancyProject)。 所以我需要明确地解决这个问题(实际上我手动复制了 TestProject 的 Views 目录中的项目 SelfHostNancyProject 的 Views 目录)。 但是即使使用自动 post-build 命令复制那些 dir/files 也不是最好的方法。
我发现了这个解决方案 https://github.com/NancyFx/Nancy/wiki/Nancy-Testing-View-Location 但是在我的代码中复制 class TestingRootPathProvider 的代码我有错误
The type or namespace Bootstrapper cannot be found
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;
}
}
但是在 google 周围徘徊,我找不到解决方案。我看到这似乎与应用程序初始化有关 What are Bootstrappers/Bootstrapping in C#
但无论如何,我不明白我必须执行哪个导入(如果有的话)来解决问题,或者可能是我遗漏了什么。
我用
解决了我的问题var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);
有
var directoryName = AppDomain.CurrentDomain.BaseDirectory;