c# - ASP.NET-5 测试库不发现主代码

标签 c# asp.net asp.net-core xunit.net

我有一个针对 net451dotnet5.4 的类库。两者都是 ASP.NET vNext 中类库的推荐名字对象。但是,我的单元测试基于 xUnit,因此必须针对 dnx451dnxcore50。然而,这导致我的测试项目没有发现我想要测试的类。它只是说无法解析符号

有没有办法解决这个问题,除了将我的类库重新定位到与我的测试项目相同的名字(这真的很愚蠢,tbh)

这是我的测试项目中的 project.json:

{
    "version": "1.0.0-*",
    "description": "Test Class Library",
    "authors": [ "Robert" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",
    "dependencies": {
        "SemanticVersion": "1.0.0-*",
        "xunit": "2.1.0",
        "xunit.runner.dnx": "2.1.0-rc1-build204"
    },
    "commands": {
        "test": "xunit.runner.dnx"
    },
    "frameworks": {
        "dnx451": { },
        "dnxcore50": {
            "dependencies": {
                "Microsoft.CSharp": "4.0.1-beta-23516",
                "System.Collections": "4.0.11-beta-23516",
                "System.Linq": "4.0.1-beta-23516",
                "System.Runtime": "4.0.21-beta-23516",
                "System.Threading": "4.0.11-beta-23516"
            }
        }
    }
}

此外,这是来自主库的 project.json:

{
    "version": "1.0.0-*",
  "description": "SemanticVersion Class Library",
  "authors": [ "Robert" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "net451": { },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  }
}

为了进一步调试,这里是有问题的代码:

namespace Semver
{
    public class SemanticVersion
    {
        public int Major { get; set; }

        public int Minor { get; set; }

        public int Patch { get; set; }

        public string Prerelease { get; set; }

        public string Build { get; set; }

        public static SemanticVersion Parse(string versionString, bool strict = false)
        {
            // Code here
        }
    }
}

namespace SemanticVersionTest
{
    using Xunit;
    using Semver;

    public class ParseTests
    {
        [Fact]
        public void ParseMajor()
        {
            SemanticVersion version = SemanticVersion.Parse("1");

            Assert.Equal(1, version.Major);
            Assert.Equal(0, version.Minor);
            Assert.Equal(0, version.Patch);
        }
     }
}

最佳答案

如我之前的评论所述,我也遇到了这个问题。就我而言,问题出在 ReSharper 上,因为项目仍会构建,我仍然可以使用 F12 进行导航。我注意到,在更新 R# 时,我收到了一个错误

CrossAppDomainPointer is NULL.

我能够通过在以管理员身份启动安装程序后重新安装 R# 来解决此问题。希望这对您有所帮助!

关于c# - ASP.NET-5 测试库不发现主代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922762/

相关文章:

c# - Entity Framework 的重复键异常?

asp.net - ASP.NET 中的线程和请求线程池

c# - 我如何创建一个具有 Int 值的 SelectListItem()

c# - RemoteApp 拖放

asp.net mvc 全局化。你怎么做呢?

asp.net - IIS 6 : How to handle a space (%20) after . aspx

c# - Request.IsHttps 和 Request.Scheme 显示请求是 HTTP 而不是 HTTPS

c# - .NET Core 3.1 Identity 在 Azure 上登录需要很长时间

c# - 一次通话即可获取 Facebook 用户的详细信息和大头像

c# - 系统.InvalidOperationException : Collection was modified