今天在升级 nuget 包时发现 FluentAssertions 从 8.0 版本开始针对商业使用收费了
Versions 8 and beyond are/will be free for open-source projects and non-commercial use, but commercial use requires a paid license. Check out the license page for more information.
详见 https://fluentassertions.com/releases/#license-change
需要找一个替代
开源社区做了一个完美替代 —— AwesomeAssertions
FluentAssertions, up to version 7.x, was licensed under Apache 2.0. Starting with later versions, licensing changes introduced potential fees for developers.
In response to these changes, this community project was created.
只要把 nuget 包换成 AwesomeAssertions 就行,连命名空间都不需要修改
dotnet add package AwesomeAssertions
需要注意的一个地方,如果在针对 HttpResponseMessage 的测试中使用了 FluentAssertions,需要进行一些改动
The support for assertions on this type was removed in Awesome Assertions 8.0. If you need to do assertions like these, we recommend you adopt FluentAssertions.Web.
比如下面的测试用例
// Act
var client = app.GetTestClient();
var response = await client.GetAsync("/robots.txt");
// Assert
response.Should().BeSuccessful();
需要安装下面的 nuget 包
dotnet add package FluentAssertions.Web.v8
并改为
response.Should().Be200Ok();