我正在尝试使用Nspec。我已按照以下说明操作:http://nspec.org/
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
答案 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");
};
};
}
}