首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FluentAssertions: string不包含ShouldBeEquivalentTo的定义

FluentAssertions: string不包含ShouldBeEquivalentTo的定义
EN

Stack Overflow用户
提问于 2018-03-06 10:17:25
回答 1查看 6.4K关注 0票数 5

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

  1. 创建类库项目
  2. Nuget:安装软件包nspec
  3. Nuget:安装包FluentAssertions
  4. 创建一个类文件并粘贴以下代码:
代码语言:javascript
复制
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类,但是我看到一个编译器错误,它说:

‘'string不包含ShouldBeEquivalentTo的定义’。

有什么问题吗?

我正在使用.NET 4.7.1和VisualStudio2017。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-06 10:52:59

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

有关建议的备选方案,请参阅最近的FluentAssertions文档。

https://fluentassertions.com/introduction

代码语言:javascript
复制
name.Should().BeEquivalentTo(...);

您的示例代码需要更新为

代码语言:javascript
复制
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");
            };
        };
    }
}
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49128388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档