Mocking Restease #199
-
Hi, The specific trouble I'm having is mocking the calls to an endpoint. How can I mock the restease client so I can unit test it, instead of having to pass a real endpoint? I realise I might be asking the wrong question, but any suggestions / nudges in the right direction would be appreciated. I'm quite new to this so I'm still trying to wrap my head around it. I'm using moq and nunit. The example below is just a simplified version of what I'm trying. Eg:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your BrandfolderClient constructor does: _brandFolderApi = RestClient.For<IBrandFolderApi >(url); So your BrandfolderClient will always use a "real" IBrandFolderApi, and the mock you create in your unit test is unrelated to anything. This is general programming help unrelated to RestEase, but if you want to test BrandfolderClient, you'll need a way to get it to use a mock IBrandFolderApi, rather than always calling |
Beta Was this translation helpful? Give feedback.
Your BrandfolderClient constructor does:
So your BrandfolderClient will always use a "real" IBrandFolderApi, and the mock you create in your unit test is unrelated to anything.
This is general programming help unrelated to RestEase, but if you want to test BrandfolderClient, you'll need a way to get it to use a mock IBrandFolderApi, rather than always calling
RestClient.For<IBrandFolderApi >(url)
. That's normally done by having a constructor which accepts an instance ofIBrandFolderApi
: this might be the only constructor, or you might have one constructor which takes a string, and one which takes aIBrandFolderApi
.