Reputation: 586
I am using NUnit 3.8.1 and I am trying to do a really simple test:
[TestCase(0)]
[TestCase(11)]
[TestCase(12)]
[TestCase(13)]
[TestCase(14)]
public void GivenUserCreatesPinWhenItIsInWrongPositionThenThrowArgumentException(uint position)
{
//Assert
Assert.Throws<ArgumentException>(() =>
{
new PositionPin(position);
});
}
And I get this exception:
Message: System.ArgumentException : Object of type 'System.Int32' cannot be converted to type 'System.UInt32'
As soon as I change uint by int and cast the int to uint inside the method it works. I don't really want to do this, is there a way to keep my uint?
Upvotes: 4
Views: 999
Reputation: 371
Just use an u
to directly tell the compiler, that the number is a System.UInt32
number.
[TestCase(0u)]
[TestCase(11u)]
//...
Or: Use int as parameter and cast with (uint)
Upvotes: 11