Let’s say, I have this class
public class MyClass
{
public int MyMethod(int? i)
{
throw new NotImplementedException();
}
}
I have also a test class
[TestClass]
public class MyClassTest
{
Public void Retur_Int_Greater_Than_Zero_When_Input_Is_Not_Null_And_Zero_Otherwise()
{
// Arrange
var myVar = new MyClass();
int? i = 3;
// Act
var result = myVar.MyMethod(i)
//Assert
//
}
}
I’d like to check – if the input is null or 0, the result must be 0 – if the input is not null nor 0, the result must the absolute value of that number.
How do I express those assertions?
Can I write something like:
if(i.HasValue)
{
//Define the Assert statement inside a If, else constructions...
}
Thanks for helping
You will need to create three tests instead of one to test three different scenarios
If the input is null or 0, the result must be 0
If the input is not null nor 0, the result must the absolute value of that number.
The same using TestCase attribute from NUnit