public void CallServiceTestBadOutput() { var testJObject = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success"), }; var input = new JObject() { new JProperty("token", "abc123"), new JProperty("serviceUrl", ServiceUrl.Url) }; var outputReference = new JObject() { }; var messageHandler = new FakeHttpMessageHandler(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(testJObject), Encoding.UTF8, "application/json") }); var mockServiceClient = new MockServiceClient(messageHandler); var ezPassService = new EzPassService.EzPassService(mockServiceClient, MockGraphService, MockB2CGraphService, _serviceId); Assert.Throws <ArgumentException>(() => ezPassService.CallService("AccountDetails", "GetAccountDetails", input, ref outputReference)); }
public void GetServiceIdTest() { var testJObject = new JObject() { new JProperty("LoginUser", new JObject() { new JProperty("AccessId", "abc123") }), new JProperty("AuthorizeUser", new JObject() { new JProperty("ServiceId", "abc123") }) }; var messageHandler = new FakeHttpMessageHandler(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(testJObject), Encoding.UTF8, "application/json") }); var mockServiceClient = new MockServiceClient(messageHandler); var mockGraphService = new MockGraphService(); var mockB2CGraphService = new MockB2CGraphService(); var serviceId = new ServiceId(mockGraphService, mockB2CGraphService, mockServiceClient); const string expectedOutput = "abc123"; var result = serviceId.GetServiceId(ServiceUrl.Url, "fakeToken").Result; Assert.Equal(expectedOutput, result); }
public void GetUserByObjectIdTest() { var mockServiceClient = new MockServiceClient(_goodMessageHandler); var b2CGraphService = new B2CGraphService(mockServiceClient); var expected = JsonConvert.SerializeObject(TestObj); var response = b2CGraphService.GetUserByObjectId("").Result; Assert.Equal(expected, response); }
public void PayWithCardOnFileTest() { var testJObject = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success"), new JProperty("transactionId", "123"), new JProperty("creditCardListType", new JObject() { new JProperty("cardsList", new JArray(new List <JObject>() { new JObject() { new JProperty("cardNumber", "123") } })) }) }; var messageHandler = new FakeHttpMessageHandler(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(testJObject), Encoding.UTF8, "application/json") }); var mockServiceClient = new MockServiceClient(messageHandler); var mockGraphService = new MockGraphService(); var mockB2CGraphService = new MockB2CGraphService(); var serviceId = new ServiceId(mockGraphService, mockB2CGraphService, _mockServiceClientServiceId); var payment = new Payment(serviceId, mockServiceClient); var input = new JObject() { new JProperty("token", "123"), new JProperty("serviceUrl", ServiceUrl.Url), new JProperty("transactionAmount", "1") }; var expectedOutput = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success"), new JProperty("transactionId", "123") }; var response = payment.PayWithCardOnFile(input); var responseObj = JObject.Parse(response); foreach (var item in responseObj) { Assert.True(expectedOutput.ContainsKey(item.Key)); var value = expectedOutput.GetValue(item.Key); Assert.Equal(value, item.Value); } }
public async Task GetServiceIdTestBadTokenAsync() { var messageHandler = new FakeHttpMessageHandler(); var mockServiceClient = new MockServiceClient(messageHandler); var mockGraphService = new MockGraphService(); var mockB2CGraphService = new MockB2CGraphService(); var serviceId = new ServiceId(mockGraphService, mockB2CGraphService, mockServiceClient); await Assert.ThrowsAsync <ArgumentException>(async() => await serviceId.GetServiceId(ServiceUrl.Url, "")); }
public void CallServiceBadMethodName() { var messageHandler = new FakeHttpMessageHandler(); var mockServiceClient = new MockServiceClient(messageHandler); var ezPassService = new EzPassService.EzPassService(mockServiceClient, MockGraphService, MockB2CGraphService, _serviceId); var input = new JObject(); var outputReference = new JObject(); Assert.Throws <ArgumentException>(() => ezPassService.CallService("AccountDetails", "BadMethodName", input, ref outputReference)); }
public void GetCurrentBalanceTest() { var testJObject = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success"), new JProperty("accountDetail", new JObject() { new JProperty("currentBalance", "123") }) }; var messageHandler = new FakeHttpMessageHandler(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(testJObject), Encoding.UTF8, "application/json") }); var mockServiceClient = new MockServiceClient(messageHandler); var mockGraphService = new MockGraphService(); var mockB2CGraphService = new MockB2CGraphService(); var serviceId = new ServiceId(mockGraphService, mockB2CGraphService, _mockServiceClientServiceId); var accountDetails = new AccountDetails(serviceId, mockServiceClient); var input = new JObject() { new JProperty("token", "123"), new JProperty("serviceUrl", ServiceUrl.Url) }; var expectedOutput = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success"), new JProperty("currentBalance", "123") }; var response = accountDetails.GetCurrentBalance(input); var responseObj = JObject.Parse(response); foreach (var item in responseObj) { Assert.True(expectedOutput.ContainsKey(item.Key)); var value = expectedOutput.GetValue(item.Key); Assert.Equal(value, item.Value); } }
public void OrderTollTagTest() { var testJObject = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success"), }; var messageHandler = new FakeHttpMessageHandler(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(testJObject), Encoding.UTF8, "application/json") }); var mockServiceClient = new MockServiceClient(messageHandler); var mockGraphService = new MockGraphService(); var mockB2CGraphService = new MockB2CGraphService(); var serviceId = new ServiceId(mockGraphService, mockB2CGraphService, _mockServiceClientServiceId); var tollTag = new TollTag(serviceId, mockServiceClient); var input = new JObject() { new JProperty("token", "123"), new JProperty("serviceUrl", ServiceUrl.Url), new JProperty("quantity", "1"), new JProperty("transponderType", "interior") }; var expectedOutput = new JObject() { new JProperty("statusCode", "0"), new JProperty("message", "Success") }; var response = tollTag.OrderTollTag(input); var responseObj = JObject.Parse(response); foreach (var item in responseObj) { Assert.True(expectedOutput.ContainsKey(item.Key)); var value = expectedOutput.GetValue(item.Key); Assert.Equal(value, item.Value); } }