Assert.That with Throws should allow asserting on lambda property

Bug #1099517 reported by Stecy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
Triaged
Medium
Unassigned

Bug Description

To assert a property name, one can use the following
    Assert.That (testDelegate, Throws.ArgumentException.With.Property("ParamName").EqualTo ("name"));
or this one, as a refactor-friendly way
    Assert.That (testDelegate, Throws.ArgumentException.And.Matches<ArgumentException> (x => x.ParamName == "name"));
It works but the error text reported when the assert is not satisfied is rather generic:
     Expected: <System.ArgumentException> and value matching lambda expression

There should be an easier way to express the intent and have a better error message, something like:
     Assert.That (testDelegate, Throws.ArgumentException.And.Property(ex => ex.ParamName).EqualTo ("name"));

with the error reporting:
     Expected: Property lambda ex.ParamName with value "name"
     but got
     Property lambda ex.ParamName with value "myParam"

TestCaseData migh also benefit from this if it implemented the lambda property functionality.

As discussed here: https://groups.google.com/forum/#!topic/nunit-discuss/Fg0oFzR8owE

Stecy (stecy-dube)
Changed in nunitv2:
status: New → Incomplete
status: Incomplete → New
Changed in nunitv2:
status: New → Triaged
importance: Undecided → Medium
affects: nunitv2 → nunit-3.0
tags: added: github
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.