Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我在MSpec中得到get_ConsoleOut()的MissingMethodException?_C#_Unit Testing_Mspec - Fatal编程技术网

C# 为什么我在MSpec中得到get_ConsoleOut()的MissingMethodException?

C# 为什么我在MSpec中得到get_ConsoleOut()的MissingMethodException?,c#,unit-testing,mspec,C#,Unit Testing,Mspec,我以前创建过许多MSpec类,但在最近创建的文件中运行单元测试时出现以下错误。有人在单元测试中遇到过这种情况吗 System.MissingMethodException:未找到方法:“System.String Machine.Specifications.Result.get_ConsoleOut()” 代码如下: [Subject(typeof(UsersDao))] public class query_for_a_specific_user { private static C

我以前创建过许多MSpec类,但在最近创建的文件中运行单元测试时出现以下错误。有人在单元测试中遇到过这种情况吗

System.MissingMethodException:未找到方法:“System.String Machine.Specifications.Result.get_ConsoleOut()”

代码如下:

[Subject(typeof(UsersDao))]
public class query_for_a_specific_user
{
    private static Context context1;
    private static Filter queryFilter;
    private static List<User> users;

    Establish context = () =>
    {
        context1 = new Context() { DatabaseId = 1 };
        queryFilter = new Filter() { UserId = 1223 };
    };

    Because of = () => { users = UsersDao.GetUsers(context1, queryFilter); };

    It should_not_be_null = () => users.ShouldNotBeNull();
    It should_not_be_empty = () => users.ShouldNotBeEmpty();
}
[Subject(typeof(UsersDao))]
特定用户的公共类查询
{
私有静态上下文1;
专用静态过滤器查询过滤器;
私有静态列表用户;
建立上下文=()=>
{
context1=newcontext(){DatabaseId=1};
queryFilter=newfilter(){UserId=1223};
};
因为=()=>{users=UsersDao.GetUsers(context1,queryFilter);};
它不应该是null=()=>users.ShouldNotBeNull();
它不应该是空的=()=>用户。不应该是空的();
}

问题可能是MSpec runner和项目引用的MSpec.dll之间的版本不匹配。0.5.16(不记得很清楚)添加了对捕获控制台输出的支持,错误源于您的MSpec.dll还没有这种支持。请确保所有版本都匹配,然后重新运行测试,好吗

因为=()=>
那是有效的代码吗?我以前从未使用过
mspec
,所以可能是这样。事实上,您通常会使用Action。MSpec是关于“消除语言噪音”的。增加更大的噪音是一种有效的策略。尽管很难获得帮助,但肯定忽略了将此代码映射到异常消息的任何方法。一位专家在附近,他大约每月来一次。根据这些信息很难分析。你能提供更多的细节,比如完整的堆栈跟踪和测试中的代码吗?这很奇怪,因为这种测试格式在过去工作得很好。我也没有堆栈跟踪。这只是运行测试时单元测试会话窗口中显示的错误。调试时收到此警告,但我已检查DLL是否仍成功引用。警告8无法解析此引用。找不到程序集“Machine.Specifications.TDNetRunner”。检查以确保磁盘上存在程序集。如果代码需要此引用,则可能会出现编译错误。