Help archiving the API client under test
I need to interact with a web API. It accepts post requests and returns XML data. This requires a lot of asynchronous processing on the client side so that it can retry multiple times in case of failure without interrupting the main client process. The code should be well tested. I am creating a mock version of the API for testing locally and recording unit tests that connect to it. Is this a good approach for testing? Should I also have versions of the client API that fake a connection to the server and don't actually connect? (just return the mock data)
I am also trying to determine the best architecture for the request / response classes. Should I just serialize the response in the class? Should have some sort of mapping file that maps XML fields to class properties? I thought about having a request class for every request that follows the interface. Then I could have an ApiRequestSender class as well as an AsyncApiRequestSender class that sends a request and receives a response. The only thing I'm confused with is how to get the correct typed answer, since there are 4.
Thanks in advance. I hope to get answers, but usually when I ask architecture based questions I don't get any answers: <
source to share
Definitely a good way to get this far.
- Mocking helps you get a lot of things to do without clicking on a service.
- If possible, check if you can embed the API I / O in your own class for your code so you can code your classes and not worry about response states getting wrapped.
- Typically I would turn it into an implementation
IService
orIRepository
and abstract your code from the web API and use a DI container to inject your mock implementation for testing and the real API for the application. - As @Gerrie said, don't reinvent the wheel if it's not square :)
NTN
source to share