public void TestQueryWithSuccess() { // ARRANGE var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); handlerMock .Protected() // Setup the PROTECTED method to mock .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent("{\"data\": {\"user\": {\"id\": \"1\",\"firstname\": \"Mike\"}}}"), }) .Verifiable(); using (var client = new SimpleGraphQLClient.SimpleGraphQLClient(new HttpClient(handlerMock.Object))) { client.ServiceUrl = "https://fakeql.com/rest/8085b4e0c4f41b997bda34805bc006dd"; client.OperationName = "getElement"; client.Parameters.Add("id", 16); var result = client.Post <User>(); Assert.IsNotNull(result); Assert.AreEqual("Mike", result.FirstName); } Assert.Pass(); }
public void CallFakeQLService() { using (var client = new SimpleGraphQLClient.SimpleGraphQLClient()) { client.ServiceUrl = "https://fakeql.com/rest/8085b4e0c4f41b997bda34805bc006dd"; client.OperationName = "user"; client.Parameters.Add("id", "1"); var result = client.Post <User>(); Assert.AreEqual("Mike", result.FirstName); } }
public void TestOperationNameNotSet() { using (var client = new SimpleGraphQLClient.SimpleGraphQLClient()) { client.ServiceUrl = "http://example.com/"; client.Parameters.Add("id", 16); var ex = Assert.Throws <ApplicationException>(() => { var result = client.Post <User>(); }); Assert.AreEqual("OperationName is required!", ex.Message); } }
public void TestServiceUrlNotSet() { using (var client = new SimpleGraphQLClient.SimpleGraphQLClient()) { client.OperationName = "getElement"; client.Parameters.Add("id", 16); var ex = Assert.Throws <ApplicationException>(() => { var result = client.Post <User>(); }); Assert.AreEqual("ServiceUrl is required!", ex.Message); } }