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

FluentAssertions: string does not contain a definition for ShouldBeEquivalentTo

我正在尝试使用 Nspec。我已遵循以下说明:http://nspec.org/

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

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

编辑器识别命名空间和 nspec class,但是我看到一个编译器错误:

'string does not contain a definition for ShouldBeEquivalentTo'.

有什么问题?

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

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

FluentAssertions 已删除 ShouldBeEquivalentTo 扩展作为更新版本中的重大更改。

请参阅最新的 FluentAssertions 文档以了解建议的替代方案

https://fluentassertions.com/introduction

name.Should().BeEquivalentTo(...);

您的示例代码需要更新为

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