Dot-Net

MSTest 是否有流暢的斷言 API?

  • September 14, 2015

我最近接觸了 nUnit 中的流利界面,我喜歡它;但是,我正在使用 msTest。

有誰知道是否有一個流暢的介面是測試框架不可知的還是用於 msTest 的?

請參閱流利的斷言。你可以做類似的事情

"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

引用自:https://stackoverflow.com/questions/302166