FluentAssertions:字符串不包含ShouldBeEquivalentTo

时间:2018-03-06 10:17:25

标签: c# fluent-assertions nspec

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

  1. 创建一个类库项目
  2. Nuget:Install-Package nspec
  3. Nuget:Install-Package FluentAssertions
  4. 创建一个类文件并粘贴以下代码:
  5. 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

1 个答案:

答案 0 :(得分:4)

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

有关建议的替代

,请参阅最近的FluentAssertions文档

https://fluentassertions.com/documentation/

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