user5699258
user5699258

Reputation:

Unit test a controller that calls another controller through the Startup class

I have an asp.net web api project, and i want to unit test an action in a controller.

This action calls another static method in a ServiceManager class which calls another action in another controllerApi! a Configuration(IAppBuilder app) method from the startup class has to be called to properly set a couple properties in the ServiceManager in order for the action to return something !

The following diagram illustrate that:

diagram

What i want to unit test is to make sure that when actionFoo is called, than actionBoo is also called. I don't want to do an integration test, and i don't want to moq the whole configuration so that the unit test will be useless.

What is the right approach to test these kind of scenarios ?

Any help would be appreciated.

Upvotes: 1

Views: 510

Answers (1)

matt_lethargic
matt_lethargic

Reputation: 2786

As mentioned in the comments to the OP, testing a controller that calls another API is an integration test, so not a unit test as you talked about. Testing each controller in isolation is usually the domain of a unit test, mocking the dependencies and testing the outputs against the inputs.

Upvotes: 1

Related Questions