public void ExecutesQueriesViaHttpClient() { var httpClient = new Mock<IHttpClient>(MockBehavior.Strict); var client = new WikimediaClient(httpClient.Object, "Foo", 5); var task = client.Query("foo=bar"); httpClient.Verify(s => s.Get(client.BaseQueryUrl + "&foo=bar", "Foo")); }
public async Task ReturnsQueryResponsesWithPages() { var httpClient = new Mock<IHttpClient>(MockBehavior.Strict); var client = new WikimediaClient(httpClient.Object, "Foo", 5); httpClient.Setup(c => c.Get(client.BaseQueryUrl + "&foo=bar", "Foo")).ReturnsAsync("{'query':{'pages':{}}}"); var response = await client.Query("foo=bar"); Assert.NotNull(response.Pages); }
public async Task RetriesHttpQueryWhileHasMaxLagError() { var httpClient = new Mock<IHttpClient>(MockBehavior.Strict); var client = new WikimediaClient(httpClient.Object, "FooAgent", 5, minimumDelaySeconds: 0); // To avoid delays during tests var errorResponse = "{'error':{'code':'maxlag','info':'0 seconds lagged'}}"; var successResponse = "{'query':{}}"; // Sets up mock responses in sequence to simulate a maxlag errors followed by a success response the third time around httpClient .SetupSequence(c => c.Get(client.BaseQueryUrl + "&foo=bar", "FooAgent")) .Returns(Task.FromResult(errorResponse)) .Returns(Task.FromResult(errorResponse)) .Returns(Task.FromResult(successResponse)); var response = await client.Query("foo=bar"); Assert.NotNull(response); }
public async Task ReturnsQueryResponsesWithPageData() { var httpClient = new Mock<IHttpClient>(MockBehavior.Strict); var client = new WikimediaClient(httpClient.Object, "Foo", 5); httpClient.Setup(c => c.Get(client.BaseQueryUrl + "&foo=bar", "Foo")).ReturnsAsync("{'query':{'pages':{'a':{'title':'Hello world'}}}}"); var response = await client.Query("foo=bar"); Assert.AreEqual("Hello world", response.Pages["a"].Title); }