-
-
Save Tirael/498c235676960d7d42e769c4ee67b7f0 to your computer and use it in GitHub Desktop.
Example for mocking RestSharps IRestClient ExecuteAsync method using Moq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Moq; | |
| using NUnit.Framework; | |
| using RestSharp; | |
| using System; | |
| using System.Net; | |
| namespace RestsharpTests | |
| { | |
| [TestFixture] | |
| public class RestsharpExecuteAsyncMoq | |
| { | |
| [Test] | |
| public void ExecuteAsyncWithMoq() | |
| { | |
| var restClient = new Mock<IRestClient>(); | |
| restClient | |
| .Setup(x => x.ExecuteAsync( | |
| It.IsAny<IRestRequest>(), | |
| It.IsAny<Action<IRestResponse, RestRequestAsyncHandle>>())) | |
| .Callback<IRestRequest, Action<IRestResponse, RestRequestAsyncHandle>>((request, callback) => | |
| { | |
| callback(new RestResponse { StatusCode = HttpStatusCode.OK }, null); | |
| }); | |
| restClient.Object.ExecuteAsync(new RestRequest(), (response, handle) => | |
| { | |
| Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); | |
| }); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment