5

我正在尝试使用 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");
            };
        };
    }
}

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

'字符串不包含 ShouldBeEquivalentTo 的定义'。

问题是什么?

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

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

4

1 回答 1

15

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");
            };
        };
    }
}
于 2018-03-06T10:52:59.753 回答