Search code examples
c#.netstringunit-testingsonarqube

Why Sonarqube is shhowing this Warning S4056: "Use the overload that takes a 'CultureInfo' or 'IFormatProvider' parameter"


I'm having this warning S4056: Use the overload that takes a 'CultureInfo' or 'IFormatProvider' parameter when I do the assert in this line of code:

Assert.AreEqual((int)HttpStatusCode.OK, statusCode);

both parameters are integers and I can't overload this method to accept the FormarProvider that is required to solve this warning, what is the best way to solve this warning?

Sonarqube warning


Solution

  • Seems like there is no overload of AreEqual method for type of int, so the parameters are being parsed to String. That's why is requires cultural parameter. Why not using that:

    Assert.IsTrue(((int)HttpStatusCode.OK) == statusCode);