-1

I'm using Rhinomock in C#, I would like to ignore a call inside a method. Lets see, Does anybody knows how to ignore (or skip) the method MyMethodToIgnore in following code sample? Is that posible with Rhinomock?

public void MyMethod()
{
 string sample = string.Empty;

 var n = MyMethodToIgnore(sample);

 // Rest of code...

}

Let's infer that MyMethodToIgnore do and return something.

Rand Random
  • 7,300
  • 10
  • 40
  • 88

1 Answers1

0

Based on the code sample you provided, no!

The mocking library you mention is to provide fake data classes so your test cases don't depend on the status and availability of e.g. a database. The don't interact with the program flow.

It's purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing. Source

So if you want your tests to mock the behavior of MyMethodToIgnore, you need to change the source code to make the MyMethod pure (so that it doesn't depend on intermediate results.

One possibility would be to add another method to the class, like this: (I'm using var and dynamic since you haven't given any implementation details yet.)

public void MyMethod()
{
    var n = MyMethodToIgnore(sample);
    MyTestedMethod(n);
}

public void MyTestedMethod(dynamic n) {
  // do the calculation
}

This way, you can override/mock the behavior of the MyMethodToIgnore and use mocked results to test your MyTestedMethod.

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38