I have a class and method viz. -
public class Class1
{
public void SomeMethod(int x, int y)
{
using(var scope = new TransactionScope())
{
if(x == 0 && y == 0)
{
//Do Something
}
if(x ==1)
{
//Do something
}
// Need to throw an exception for running a test case to check
// rollback scenario
if(y == 2)
{
//Do something
}
scope.Complete();
}
}
}
I want to test the transaction scope rollback stuff and so I want to inject an exception in between the above code (i.e. want to replace the " // Need to throw an exception for running a test case..." part with throw new Exception("some message")) and run the in memory re-complied method to test if something goes wrong in between the code execution then there will be roll back.I don't want to change anything in my existing code just for testing the rollback scenario.
Whatever I have read about Roslyn(I am very new to this .NET space), I think it can be done using some Roslyn API. But I am not sure exactly how to do it since I am not much acquainted with the same.If any one can give some sample based suggestion, that would be really helpful.