我正在尝试使用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");
};
};
}
}
编辑器可以识别 namespace 和nspec类,但是我看到一个编译器错误,其中指出:
问题是什么?
我正在使用.NET 4.7.1和Visual Studio 2017。
我花了一些时间在Google上搜索,例如: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# - FluentAssertions : string does not contain a definition for ShouldBeEquivalentTo,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49128388/