예제 #1
0
        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");
        }
예제 #2
0
        public void RequiredFieldNotSetTest()
        {
            var apiRequestMock = new ApiRequest(
                TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) =>
            {
                return(TestingUtils.GetResponse("number_lookup.json"));
            })
                );

            var mocean = TestingUtils.GetClientObj(apiRequestMock);

            Assert.Throws <RequiredFieldException>(() =>
            {
                mocean.NumberLookup.Inquiry(new NumberLookupRequest());
            });
        }
예제 #3
0
        public void RequiredFieldNotSetTest()
        {
            var apiRequestMock = new ApiRequest(
                TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) =>
            {
                return(TestingUtils.GetResponse("message.json"));
            })
                );

            var mocean = TestingUtils.GetClientObj(apiRequestMock);

            Assert.Throws <RequiredFieldException>(() =>
            {
                mocean.Sms.Send(new SmsRequest());
            });
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        public void RecordingErrorTest()
        {
            var apiRequestMock = new ApiRequest(
                TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) =>
            {
                Assert.AreEqual(HttpMethod.Get, httpRequest.Method);
                Assert.AreEqual(TestingUtils.GetTestUri("/voice/rec"), httpRequest.RequestUri.LocalPath);
                return(TestingUtils.GetResponse("error_response.json"));
            })
                );

            var mocean = TestingUtils.GetClientObj(apiRequestMock);

            Assert.Throws <MoceanErrorException>(() =>
            {
                mocean.Voice.Recording("xxx-xxx-xxx-xxx");
            });
        }
예제 #7
0
        public void ResendTest()
        {
            var apiRequestMock = new ApiRequest(
                TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) =>
            {
                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);

            mocean.SendCode.Resend(new SendCodeRequest
            {
                mocean_reqid = "test req id"
            });
        }
예제 #8
0
        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");
        }
예제 #9
0
        public void RecordingCallTest()
        {
            var apiRequestMock = new ApiRequest(
                TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) =>
            {
                Assert.AreEqual(HttpMethod.Get, httpRequest.Method);
                Assert.AreEqual(TestingUtils.GetTestUri("/voice/rec"), httpRequest.RequestUri.LocalPath);
                var mockResponse = TestingUtils.GetResponse("recording.json");
                mockResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("audio/mpeg");
                return(mockResponse);
            })
                );

            var mocean = TestingUtils.GetClientObj(apiRequestMock);
            var res    = mocean.Voice.Recording("xxx-xxx-xxx-xxx");

            Assert.IsNotNull(res.RecordingBuffer);
            Assert.AreEqual(res.Filename, "xxx-xxx-xxx-xxx.mp3");
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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);
        }
예제 #13
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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
        public void SendCodeAsSmsTest()
        {
            var apiRequestMock = new ApiRequest(
                TestingUtils.GetMockHttpClient((HttpRequestMessage httpRequest) =>
            {
                Assert.AreEqual(HttpMethod.Post, httpRequest.Method);
                Assert.AreEqual(TestingUtils.GetTestUri("/verify/req/sms"), httpRequest.RequestUri.LocalPath);
                return(TestingUtils.GetResponse("send_code.json"));
            })
                );

            var mocean   = TestingUtils.GetClientObj(apiRequestMock);
            var sendCode = mocean.SendCode;

            Assert.AreEqual(Channel.Auto, sendCode.Channel);
            sendCode.SendAs(Channel.Sms);
            Assert.AreEqual(Channel.Sms, sendCode.Channel);
            sendCode.Send(new SendCodeRequest
            {
                mocean_to    = "testing to",
                mocean_brand = "testing brand"
            });
        }