0

Below is the Scenario.
I have a public class which contains 2 static methods.

public class Helper{    
public static string (string args1, Datetime dt)
{
string computedValue = GetSomeValue(args1);
return dt.ToString(computedValue);
}        
public static GetSomeValue(string args2){
//Perform Computation and return a string
}
}

Now I want to unit test the GetSomeValue method. I am not sure if we can mock the static method or if we should be unit testing this method.
Please help.

Shaurya
  • 103
  • 6
  • We can´t know **which** methods you want to test, only you can. Anyway mocking a static member has been asked here: https://stackoverflow.com/questions/2416362/mock-static-property-with-moq – MakePeaceGreatAgain May 20 '20 at 08:40

1 Answers1

0

Moq can't mock static methods. Recently, I faced the same problem and wrote a special lib for it. Try to use it GitHub link NuGet link. If we consider your example specifically you can try this:

Mock.Setup(() => Helper.GetSomeValue("SomeValue"), () =>
{
    var mockResult= Helper.GetSomeValue("SomeValue"); // mockResult returns "MockResult"
}).Returns("MockResult");