.net - MSTest 是否有流畅的断言 API?

标签 .net unit-testing mstest fluent fluent-interface

我最近接触了 nUnit 中流畅的界面,我喜欢它;但是,我正在使用 msTest。

有谁知道是否有一个流畅的界面可以测试框架不可知或 msTest?

最佳答案

Fluent Assertions .你可以做这样的事情

"ABCDEFGHI".Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

new[] { 1, 2, 3 }.Should().HaveCount(4, "because we thought we put three items in the 
collection"))

dtoCollection.Should().Contain(dto => dto.Id != null);

collection.Should().HaveCount(c => c >= 3);

dto.ShouldHave().AllPropertiesBut(d => d.Id).EqualTo(customer);

dt1.Should().BeWithin(TimeSpan.FromHours(50)).Before(dt2); 

Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon);
action
   .ShouldThrow<RuleViolationException>()
   .WithMessage("Cannot change the unit of an existing ingredient")
   .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity

关于.net - MSTest 是否有流畅的断言 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/302166/

相关文章:

c# - 一路async await async

c# - lambda 表达式和事件处理程序?

c# - 如何模拟 C# 应用程序的配置

java - 如何使用服务和存储库为 Spring Data 设置单元测试?

.net - 如何在asp.net 中加密查询字符串?

.net - ASP + 限制子页面使用 css 文件

java - 对数据库中条目的创建进行单元测试

.net - DirectoryInfo.Exists 在 MSTest 期间总是返回 false

visual-studio - 无法初始化客户端代理 : could not connect to vstest. discoveryengine.x86.exe

asp.net-mvc - 我可以使用同一解决方案中单元测试项目中的 Selenium 来测试 ASP.NET MVC Web 项目吗?