Is there anything I can do in NUnit that I can't do in MSTest?

后端 未结 12 1453
南笙
南笙 2020-12-23 20:10

This question has been asked in various forms in a number of different forums, but, IMHO, I haven\'t been able to find a place where it\'s really answered clearly, so I\'m g

12条回答
  •  独厮守ぢ
    2020-12-23 21:14

    See http://fluentassertions.codeplex.com. You can do stuff like

    "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()
       .WithMessage("Cannot change the unit of an existing ingredient")
       .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity
    

提交回复
热议问题