Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass UInt32 as a parameter TestCase NUnit

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?

like image 622
Daniel Botero Correa Avatar asked Sep 12 '25 00:09

Daniel Botero Correa


1 Answers

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)

like image 183
Ferdinand Brunauer Avatar answered Sep 13 '25 15:09

Ferdinand Brunauer