vendredi 23 septembre 2016

How to handle multiple exception testing in nUnit 3 according to Arrage Act Assert paradigm?

In nUnit 3, there's been considerable changes made, among which the ExpectedException has been dropped to be replaced by the assertion model.

I've found this and this example but the recommendation is to use Assert.That() instead so I want to use this approach as shown below.

//Arrange
string data = "abcd";
//Act
ActualValueDelegate<object> test = () => data.MethodCall();
//Assert
Assert.That(test, Throws.TypeOf<ExceptionalException>());

However, I'd like to test the assert for a number of different parameters but I can't seem to get it to work. I've tried the following.

List<List<Stuff>> sets = new[] { 0, 1, 2 }
  .Select(_ => Enumerable.Repeat(new Stuff(_), _).ToList())
  .ToList();
Assert.Throws(() => Transform.ToThings(new List<Stuff>()));

The above works as to creating the list of lists, as desired and testing the Transform.Stuff() call. However, I haven't figured out a way to plug sets into things.

Is it possible? Where are the examples? (Most of the searches drown in nUnit 2.x and on the official documentation site, I see nothing that helps me.)

Aucun commentaire:

Enregistrer un commentaire