Roy Osherove

View Original

Poll: Do you use NUnit’s fluent API?

if you use NUnit, did you know it has a fluent API option? Do you use it?

you can write the following:

Assert.That( someString,
      Is.Not.Null

      .And.Not.Empty
      .And.EqualTo("foo")
      .And.Not.EqualTo("bar")
      .And.StartsWith("f"));


Assert.That(someEnumerable,
    Has.Count.EqualTo(2),
    .And.Contains.Some.Matches(x => x.FirstName == "Jim")
    .And.Contains.None.Matches(x => x.LastName == "Jones"));

Assert.That( x => <some code>,

    Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Too Bad!");