public void ResendThroughResponseObjectTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { var dictBody = TestingUtils.RewindBody(httpRequest.Content); Assert.AreEqual("CPASS_restapi_C0000002737000000.0002", dictBody["mocean-reqid"]); Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/verify/resend/sms"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("resend_code.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var sendCodeResponse = (SendCodeResponse)ResponseFactory.CreateObjectfromRawResponse <SendCodeResponse>(TestingUtils.ReadFile("resend_code.json")) .SetRawResponse(TestingUtils.ReadFile("resend_code.json")); sendCodeResponse.Client = mocean.SendCode; var resendCodeResponse = sendCodeResponse.Resend(); Assert.AreEqual(resendCodeResponse.Status, "0"); Assert.AreEqual(resendCodeResponse.ReqId, "CPASS_restapi_C0000002737000000.0002"); Assert.AreEqual(resendCodeResponse.To, "60123456789"); Assert.AreEqual(resendCodeResponse.ResendNumber, "1"); }
public void ErrorResponseWith2xxStatusCodeTest() { string jsonErrorResponse = TestingUtils.ReadFile("error_response.json"); var apiRequest = new ApiRequest(); try { apiRequest.FormatResponse(jsonErrorResponse, System.Net.HttpStatusCode.Accepted, false, null); Assert.Fail(); } catch (MoceanErrorException ex) { Assert.AreEqual(ex.Message, ex.ErrorResponse.ToString()); Assert.AreEqual(jsonErrorResponse, ex.ErrorResponse.ToString()); Assert.AreEqual("1", ex.ErrorResponse.Status); } try { apiRequest.FormatResponse(jsonErrorResponse, System.Net.HttpStatusCode.OK, false, null); Assert.Fail(); } catch (MoceanErrorException ex) { Assert.AreEqual(ex.Message, ex.ErrorResponse.ToString()); Assert.AreEqual(jsonErrorResponse, ex.ErrorResponse.ToString()); Assert.AreEqual("1", ex.ErrorResponse.Status); } string xmlErrorResponse = TestingUtils.ReadFile("error_response.xml"); try { apiRequest.FormatResponse(xmlErrorResponse, System.Net.HttpStatusCode.Accepted, false, null); Assert.Fail(); } catch (MoceanErrorException ex) { Assert.AreEqual(ex.Message, ex.ErrorResponse.ToString()); Assert.AreEqual(xmlErrorResponse, ex.ErrorResponse.ToString()); Assert.AreEqual("1", ex.ErrorResponse.Status); } try { apiRequest.FormatResponse(xmlErrorResponse, System.Net.HttpStatusCode.OK, false, null); Assert.Fail(); } catch (MoceanErrorException ex) { Assert.AreEqual(ex.Message, ex.ErrorResponse.ToString()); Assert.AreEqual(xmlErrorResponse, ex.ErrorResponse.ToString()); Assert.AreEqual("1", ex.ErrorResponse.Status); } }
public void JsonInquiryTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Get, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/account/pricing"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("price.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Pricing.Inquiry(); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("price.json")); TestObject(res); }
public void XmlSendTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/sms", "1"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("message.xml")); }) ); apiRequestMock.ApiRequestConfig.Version = "1"; var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Sms.Send(new SmsRequest { mocean_from = "testing from", mocean_text = "testing text", mocean_to = "testing to", mocean_resp_format = "xml" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("message.xml")); TestObject(res); //V2 Test apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/sms"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("message_v2.xml")); }) ); apiRequestMock.ApiRequestConfig.Version = "2"; mocean = TestingUtils.GetClientObj(apiRequestMock); res = mocean.Sms.Send(new SmsRequest { mocean_from = "testing from", mocean_text = "testing text", mocean_to = "testing to", mocean_resp_format = "xml" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("message_v2.xml")); TestObject(res); }
public void XmlHangupTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { var dictBody = TestingUtils.RewindBody(httpRequest.Content); Assert.AreEqual("xxx-xxx-xxx-xxx", dictBody["mocean-call-uuid"]); Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/voice/hangup"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("hangup.xml")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Voice.Hangup("xxx-xxx-xxx-xxx"); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("hangup.xml")); Assert.AreEqual(res.Status, "0"); }
public void XmlInquiryTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Get, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/account/balance"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("balance.xml")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Balance.Inquiry(new BalanceRequest { mocean_resp_format = "xml" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("balance.xml")); TestObject(res); }
public void JsonCallTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/voice/dial"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("voice.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Voice.Call(new VoiceRequest { mocean_to = "testing to" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("voice.json")); TestObject(res); }
public void JsonInquiryTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Get, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/report/message"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("message_status.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.MessageStatus.Inquiry(new MessageStatusRequest { mocean_msgid = "test msg id" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("message_status.json")); TestObject(res); }
public void JsonInquiryTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/nl"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("number_lookup.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.NumberLookup.Inquiry(new NumberLookupRequest { mocean_to = "testing to" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("number_lookup.json")); TestObject(res); }
public void JsonSendTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/verify/check"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("verify_code.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.VerifyCode.Send(new VerifyCodeRequest { mocean_code = "testing code", mocean_reqid = "testing reqid" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("verify_code.json")); TestObject(res); }
public void XmlInquiryTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Get, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/account/pricing", "1"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("price.xml")); }) ); apiRequestMock.ApiRequestConfig.Version = "1"; var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Pricing.Inquiry(new PricingRequest { mocean_resp_format = "xml" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("price.xml")); TestObject(res); //V2 Test apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Get, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/account/pricing"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("price_v2.xml")); }) ); apiRequestMock.ApiRequestConfig.Version = "2"; mocean = TestingUtils.GetClientObj(apiRequestMock); res = mocean.Pricing.Inquiry(new PricingRequest { mocean_resp_format = "xml" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("price_v2.xml")); TestObject(res); }
public void JsonSendTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/sms"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("message.json")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.Sms.Send(new SmsRequest { mocean_from = "testing from", mocean_text = "testing text", mocean_to = "testing to" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("message.json")); TestObject(res); }
public void XmlSendTest() { var apiRequestMock = new ApiRequest( TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) => { Assert.AreEqual(HttpMethod.Post, httpRequest.Method); Assert.AreEqual(TestingUtils.GetTestUri("/verify/req"), httpRequest.RequestUri.LocalPath); return(TestingUtils.GetResponse("send_code.xml")); }) ); var mocean = TestingUtils.GetClientObj(apiRequestMock); var res = mocean.SendCode.Send(new SendCodeRequest { mocean_to = "testing to", mocean_brand = "testing brand", mocean_resp_format = "xml" }); Assert.AreEqual(res.ToString(), TestingUtils.ReadFile("send_code.xml")); TestObject(res); }