FluentAssertions:字符串不包含ShouldBeEquivalentTo的定义

w00*_*977 2 c# fluent-assertions nspec

我正在尝试使用Nspec。我已按照以下说明进行操作:http : //nspec.org/

  1. 创建一个类库项目
  2. Nuget:安装软件包nspec
  3. Nuget:安装包FluentAssertions
  4. 创建一个类文件并粘贴以下代码:

using NSpec;
using FluentAssertions;

class my_first_spec : nspec
{
    string name;

    void before_each()
    {
        name = "NSpec";
    }

    void it_asserts_at_the_method_level()
    {
        name.ShouldBeEquivalentTo("NSpec");
    }

    void describe_nesting()
    {
        before = () => name += " Add Some Other Stuff";

        it["asserts in a method"] = () =>
        {
            name.ShouldBeEquivalentTo("NSpec Add Some Other Stuff");
        };

        context["more nesting"] = () =>
        {
            before = () => name += ", And Even More";

            it["also asserts in a lambda"] = () =>
            {
                name.ShouldBeEquivalentTo("NSpec Add Some Other Stuff, And Even More");
            };
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑器可以识别名称空间和nspec类,但是我看到一个编译器错误,指出:

“字符串不包含ShouldBeEquivalentTo的定义”。

问题是什么?

我正在使用.NET 4.7.1和Visual Studio 2017。

我花了一些时间在Google上搜索,例如在这里查看:https//github.com/fluentassertions/fluentassertions/issues/234

Nko*_*osi 9

FluentAssertions已删除ShouldBeEquivalentTo扩展,这是最新版本中的一项重大更改。

有关建议的替代方法,请参考最新的FluentAssertions文档。

https://fluentassertions.com/introduction

name.Should().BeEquivalentTo(...);
Run Code Online (Sandbox Code Playgroud)

您的示例代码将需要更新为

class my_first_spec : nspec {
    string name;

    void before_each() {
        name = "NSpec";
    }

    void it_asserts_at_the_method_level() {
        name.Should().BeEquivalentTo("NSpec");
    }

    void describe_nesting() {
        before = () => name += " Add Some Other Stuff";

        it["asserts in a method"] = () => {
            name.Should().BeEquivalentTo("NSpec Add Some Other Stuff");
        };

        context["more nesting"] = () => {
            before = () => name += ", And Even More";

            it["also asserts in a lambda"] = () => {
                name.Should().BeEquivalentTo("NSpec Add Some Other Stuff, And Even More");
            };
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @ w0051977:那不是堆栈溢出的工作方式!如果您还有其他问题,请发布一个新问题。这不是论坛,辅导或讨论站点。如果答案解决了您原来的问题,请接受。请再次执行必填[tour]来重述站点规则。 (2认同)