我正在尝试使用 Nspec。我已按照以下说明进行操作:http://nspec.org/
- 创建类库项目
- Nuget:安装包 nspec
- Nuget:安装包 FluentAssertions
- 创建一个类文件并粘贴以下代码:
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 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");
};
};
}
}
关于c# - 流利的断言 : string does not contain a definition for ShouldBeEquivalentTo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49128388/