【问题标题】:NancyFx testing: The type or namespace Bootstrapper cannot be foundNancyFx 测试:找不到类型或命名空间 Bootstrapper
【发布时间】:2018-03-11 06:30:16
【问题描述】:

更新:我解决了替换问题

var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);

var directoryName = AppDomain.CurrentDomain.BaseDirectory;

所以现在测试工作正常。无论如何,如果有人可以使原始代码正常工作,我会留下问题(可能是在解释为什么 Bootstraper 比我的解决方案更好:) 所以我可以理解为什么在这里使用

原始问题

我只是在 C# 中与 Nancyfx 一起工作,但我刚刚重新开始在上周的 c# 上工作,可能我错过了很多与 dot.net 和 c# 相关的概念,将研究这些内容周末

尝试为 nancy 模块创建一些测试(我使用 Nunit 和 NancyFx 的辅助测试类)我遇到的问题是这些测试必须使用我为其编写测试的项目的路径(例如我在 TestProject 中编写了这些测试,并且正在测试 SelfHostNancyProject)。 所以我需要彻底解决这个问题(实际上我是在TestProject的Views目录中手动复制了项目SelfHostNancyProject的Views目录)。 但是即使使用自动构建后命令复制这些目录/文件也不是最好的方法。

我发现了这个解决方案 https://github.com/NancyFx/Nancy/wiki/Nancy-Testing-View-Location 但是在我的代码中复制TestingRootPathProvider类的代码我有错误

找不到类型或命名空间引导程序

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;
  }
}

但是与谷歌闲逛我找不到解决方案。我看到这似乎与应用程序初始化有关 What are Bootstrappers/Bootstrapping in C#

但无论如何,我不明白我必须执行哪个导入(如果有)来解决问题,或者我可能缺少某些东西。

【问题讨论】:

  • 你能把你的答案写在下面吗,如果你已经回答了你自己的问题就可以了。
  • 好的,谢谢,完成。 @DaiBok 我可以接受我自己的答案吗?
  • 是的,如果你现在做不到,你可能只需要等待几天然后接受它

标签: c# .net testing nancy


【解决方案1】:

我解决了替换问题

var directoryName = Path.GetDirectoryName(typeof (Bootstrapper).Assembly.CodeBase);

var directoryName = AppDomain.CurrentDomain.BaseDirectory;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 2017-07-12
    • 2011-05-13
    • 2021-03-01
    • 2020-08-13
    • 2018-11-18
    相关资源
    最近更新 更多