I am trying to come up with the way to implement a way to perform a Mutation test on my class (yes I am aware of Stryker .NET).
For the sake of simplicity, let's say that I want to write a Mutator class that some service will inherit from, and it will convert all additions to subtraction. I am wondering whether it is possible to achieve this without doing any changes to the service class.
I have this service that performs a simple addition
public class Service : Mutator
{
public int AddTwoNumbers(int firstNum, int secondNum)
{
return firstNum + secondNum;
}
}
at first, I simply tried to write Mutator class as follows:
public class Mutator
{
public static int operator +(int a, int b)
{
return a - b;
}
}
but of course quickly discovered that following code produces compiler error ("One of the parameters of a binary operator must be the containing type")
So I wonder, if there is a way to achieve this kind of mutation trough inheritance without changing the actual Service class.
The reason I choose operator overloading instead of method overloading or something like that is because I want to be able to inherit from this Mutator from any random class and to just simply change all + into -