It seems that nUnit have removed the ExpectedException attribute in nUnit 3. So my question is: how can I catch and, therefore, test that my constructor throws an ArgumentOutOfRangeException when I past invalid parameters to my class?
public Year(int value)
{
if (value < 1) throw new ArgumentOutOfRangeException(nameof(value), "Cannot be less than 1.");
if (value > 9999) throw new ArgumentOutOfRangeException(nameof(value), "Cannot be greater than 9999.");
Value = value;
AddMonths();
}
My test:
[Test]
public void ShouldNotBeAbleToCreateYear()
{
// Arrange...
const int yearValue = 0;
// Act...
var year = new Year(yearValue);
// Assert...
// Need to test that an ArgumentOutOfRangeException was thrown!?
}
I have checked nUnits documentation and the answer to this eludes me!
Many thanks in advance...