C# How to pass ulong argument to unit test via TestCase decorator

0
443
Asked By William Rossbach On

I have a unit test where I want to pass some arguments into the test method via the TestCase decorator. The argument I need for this is of type ulong but the tests are failing because it doesn't like the argument that is being passed via the TestCase because it is int32 instead of ulong. How do you pass a ulong when it is the same thing as an int anyway, particularly when I am only passing a single-digit value into the method.

[Test]
[TestCase(10, 1, 2)]
public void MyTestMethod(int quantity, ulong itemId, ulong parentId)
{
    //do stuff
}

 

1 Answer

Answered By Amaresh Kulkarni On

You can do the same thing that you do when you want to differentiate an integer from a decimal. Instead, you will just put a u after the integer value and this will satisfy the compiler that you are using a long instead of an int.

The following should fix your problem by putting u after the arguments in the TestCase

[Test]
[TestCase(10, 1u, 2u)]
public void MyTestMethod(int quantity, ulong itemId, ulong parentId)
{
    //do stuff
}

 

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.