w00*_*977 2 c# fluent-assertions nspec
我正在尝试使用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");
};
};
}
}
Run Code Online (Sandbox Code Playgroud)
编辑器可以识别名称空间和nspec类,但是我看到一个编译器错误,指出:
“字符串不包含ShouldBeEquivalentTo的定义”。
问题是什么?
我正在使用.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(...);
Run Code Online (Sandbox Code Playgroud)
您的示例代码将需要更新为
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");
};
};
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2429 次 |
| 最近记录: |