0

I am trying to create a system test for an old code base where there is no interfaces and most functions are private. The application gets data from another system, transforms it to a "better format" and saves it to a cache.

I want to read the value that is about to be written to the database and then skip the write step.

I have however found a function that returns the value I need.:

public virtual List<string> MyFunction(XmlDocument input) 
{
    var x = DoSomethingWithInput();

    return x;
}

So my question is, is there any mocking method (with NSubstitute, Moq, or others) that let me read the return value? I have mostly seen reading inputs and replacing outputs.

The return value I get from this function will be compared to my expected value. But since there is a lot of code before this function I can't just run this function, I need to run the entire application but halt it here.

The class that writes to the database is using static functions only so no possibility to mock that and get the input there as far as I know.

Nings
  • 355
  • 1
  • 2
  • 12
  • This should help: https://stackoverflow.com/questions/38738511/validate-moq-unit-test-method-return-value – peeyush singh Feb 28 '19 at 08:06
  • 2
    As hard as it might seem to be, you have no good option other than to start refactoring. Bolting unit-tests onto a static monolithic legacy application is going to be a **much** worse situation to be in and the cost of doing so is going to far outweigh the cost of refactoring bits and pieces, it's just that the cost is largely discovered a ways down the road, which means that right now it *seems* cheaper to try to add some ad-hoc testing without rewriting but it won't be. – Lasse V. Karlsen Feb 28 '19 at 08:40
  • You should get started by introducing 1 dependency that you can mock out for this particular scenario and take it bit by bit. – Lasse V. Karlsen Feb 28 '19 at 08:41

0 Answers0