var homer = new Person { Name = "Homer", Salary = 30000 };
var denominator = 0;
Should.NotThrow(() =>
{
var y = homer.Salary / denominator;
});
|
Exception
`var y = homer.Salary / denominator;`
should not throw but threw
System.DivideByZeroException
with message
"Attempted to divide by zero."
ShouldNotThrow Action Extension
var homer = new Person { Name = "Homer", Salary = 30000 };
var denominator = 0;
var action = () =>
{
var y = homer.Salary / denominator;
};
action.ShouldNotThrow();
Exception
`action()`
should not throw but threw
System.DivideByZeroException
with message
"Attempted to divide by zero."
ShouldNotThrowFunc
string? name = null;
Should.NotThrow(() => new Person(name!));
Exception
`new Person(name!)`
should not throw but threw
System.ArgumentNullException
with message
"Value cannot be null. (Parameter 'name')"
ShouldNotThrow Func Extension
string? name = null;
var func = () => new Person(name!);
func.ShouldNotThrow();
Exception
`func()`
should not throw but threw
System.ArgumentNullException
with message
"Value cannot be null. (Parameter 'name')"
ShouldNotThrowFuncOfTask
var homer = new Person { Name = "Homer", Salary = 30000 };
var denominator = 0;
Should.NotThrow(() =>
{
var task = Task.Factory.StartNew(
() =>
{
var y = homer.Salary / denominator;
});
return task;
});
Exception
`var task = Task.Factory.StartNew( () => { var y = homer.Salary / denominator; }); return task;`
should not throw but threw
System.DivideByZeroException
with message
"Attempted to divide by zero."