Example #1
0
        public void ConferencesConnectorListConferencesTest()
        {
            const string methodName = "listConferences";

            using (new MockServer(Port, "Accounts/{accountSid}/Conferences.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(
                        assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileNameConference}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List conferences using conferences connector
                var conferenceList = service.ConferencesConnector.ListConferences("TestConference",
                                                                                  jsonRequest.QueryParameter("FriendlyName"),
                                                                                  EnumHelper.ParseEnum <ConferenceStatus>(jsonRequest.QueryParameter("Status")),
                                                                                  ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateCreated>")),
                                                                                  ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateCreated<")),
                                                                                  ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateUpdated>")),
                                                                                  ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateUpdated<")),
                                                                                  Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                                                                                  Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(2, conferenceList.Total);

                var conference = conferenceList.Elements.First();

                Assert.AreEqual("TestConferenceSid", conference.Sid);
                Assert.AreEqual(ConferenceStatus.COMPLETED, conference.Status);
                Assert.AreEqual("TestConference", conference.FriendlyName);
            }
        }
        public void CallsConnectorListCalls()
        {
            const string methodName = "listCalls";

            using (new MockServer(Port, "Accounts/{accountSid}/Calls.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                //// Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List calls using calls connector
                var callList = service.CallsConnector.ListCalls(jsonRequest.QueryParameter("To"),
                                                                jsonRequest.QueryParameter("From"), EnumHelper.ParseEnum <CallStatus>(jsonRequest.QueryParameter("Status")),
                                                                ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("StartTime>")),
                                                                ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("StartTime<")), Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                                                                Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(1, callList.Total);
                Assert.AreEqual(1, callList.Numpages);
                Assert.AreEqual(jsonRequest.QueryParameter("Page"), callList.Page.ToString());
                Assert.AreEqual(jsonRequest.QueryParameter("PageSize"), callList.Pagesize.ToString());

                var call = callList.Elements.First();

                Assert.AreEqual(jsonRequest.QueryParameter("To"), call.To);
                Assert.AreEqual(AnsweredBy.TBD, call.AnsweredBy);
                Assert.AreEqual(Convert.ToDecimal(0.1872), call.Price);
                Assert.AreEqual(CallStatus.COMPLETED, call.Status);
            }
        }
Example #3
0
        public void TranscriptionsConnectorListTranscriptionsTest()
        {
            const string methodName = "listTranscriptions";

            using (new MockServer(Port, "Accounts/{accountSid}/Transcriptions.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List transcriptions using transcriptions connector
                var transcriptionsList = service.TranscriptionsConnector.ListTranscriptions(
                    EnumHelper.ParseEnum <TranscriptionStatus>(jsonRequest.QueryParameter("Status")),
                    ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateTranscribed>")),
                    ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateTranscribed<")),
                    Convert.ToInt32(jsonRequest.QueryParameter("Page")), Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("PageSize")), transcriptionsList.Pagesize);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), transcriptionsList.Page);
                Assert.AreEqual(2, transcriptionsList.Total);

                var transcription = transcriptionsList.Elements.First();

                Assert.AreEqual("http://dev.calyx.hr/~vprenner/zang.mp3", transcription.AudioUrl);
                Assert.AreEqual(TranscriptionStatus.COMPLETED, transcription.Status);
                Assert.AreEqual(50, transcription.Duration);
            }
        }
        public void IncomingPhoneNumbersConnectorPurchaseIncomingNumberTest()
        {
            const string methodName = "purchaseIncomingPhoneNumber";

            using (new MockServer(Port, "/Accounts/{accountSid}/IncomingPhoneNumbers.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Purchase incoming phone number using incoming phone numbers connector
                var phoneNumber = service.IncomingPhoneNumbersConnector.PurchaseIncomingNumber("TestAccountSid",
                                                                                               jsonRequest.BodyParameter("PhoneNumber"), jsonRequest.BodyParameter("AreaCode"), jsonRequest.BodyParameter("FriendlyName"),
                                                                                               jsonRequest.BodyParameter("VoiceUrl"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("VoiceMethod")),
                                                                                               jsonRequest.BodyParameter("VoiceFallbackUrl"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("VoiceFallbackMethod")),
                                                                                               Convert.ToBoolean(jsonRequest.BodyParameter("VoiceCallerIdLookup")),
                                                                                               jsonRequest.BodyParameter("SmsUrl"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("SmsMethod")),
                                                                                               jsonRequest.BodyParameter("SmsFallbackUrl"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("SmsFallbackMethod")),
                                                                                               jsonRequest.BodyParameter("HeartbeatUrl"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("HeartbeatMethod")),
                                                                                               jsonRequest.BodyParameter("StatusCallback"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("StatusCallbackMethod")),
                                                                                               jsonRequest.BodyParameter("HangupCallback"), EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("HangupCallbackMethod")),
                                                                                               jsonRequest.BodyParameter("VoiceApplicationSid"), jsonRequest.BodyParameter("SmsApplicationSid"));

                Assert.AreEqual("(989) 494-5633", phoneNumber.FriendlyName);
                Assert.AreEqual(jsonRequest.BodyParameter("PhoneNumber"), phoneNumber.PhoneNumber);
                Assert.AreEqual(jsonRequest.BodyParameter("SmsUrl"), phoneNumber.SmsUrl);
            }
        }
Example #5
0
        public void SipDomainsConnectorCreateDomainTest()
        {
            const string methodName = "createDomain";

            using (new MockServer(Port, "Accounts/{accountSid}/SIP/Domains.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileNameDomain}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Create domain using domains connector
                var domain = service.SipDomainsConnector.CreateDomain("TestAccountSid",
                                                                      jsonRequest.BodyParameter("DomainName"), jsonRequest.BodyParameter("FriendlyName"),
                                                                      jsonRequest.BodyParameter("VoiceUrl"),
                                                                      EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("VoiceMethod")),
                                                                      jsonRequest.BodyParameter("VoiceFallbackUrl"),
                                                                      EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("VoiceFallbackMethod")),
                                                                      jsonRequest.BodyParameter("HeartbeatUrl"),
                                                                      EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("HeartbeatMethod")),
                                                                      jsonRequest.BodyParameter("VoiceStatusCallback"),
                                                                      EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("VoiceStatusCallbackMethod")));

                Assert.AreEqual(jsonRequest.BodyParameter("DomainName"), domain.DomainName);
                Assert.AreEqual(jsonRequest.BodyParameter("FriendlyName"), domain.FriendlyName);
                Assert.AreEqual(EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("VoiceMethod")), domain.VoiceMethod);
            }
        }
        public void IncomingPhoneNumbersConnectorListIncomingPhoneNumbersTest()
        {
            const string methodName = "listIncomingPhoneNumbers";

            using (new MockServer(Port, "Accounts/{accountSid}/IncomingPhoneNumbers.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List View incoming phone numbers using incoming phone numbers connector
                var phoneNumbersList =
                    service.IncomingPhoneNumbersConnector.ListIncomingNumbers(jsonRequest.QueryParameter("Contains"),
                                                                              jsonRequest.QueryParameter("FriendlyName"), Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                                                                              Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("PageSize")), phoneNumbersList.Pagesize);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), phoneNumbersList.Page);

                Assert.AreEqual(1, phoneNumbersList.Total);

                var phoneNumber = phoneNumbersList.Elements.First();

                Assert.AreEqual("(989) 494-5633", phoneNumber.FriendlyName);
                Assert.AreEqual(IncomingPhoneNumberType.LOCAL, phoneNumber.Type);
            }
        }
Example #7
0
        public void RecordingsConnectorListRecordingsTest()
        {
            const string methodName = "listRecordings";

            using (new MockServer(Port, "Accounts/{accountSid}/Recordings.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List recordings using recordings connector
                var recordingsList = service.RecordingsConnector.ListRecordings("TestCallSid",
                                                                                ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateCreated>")),
                                                                                ParametersHelper.GetDateFromString(jsonRequest.QueryParameter("DateCreated<")),
                                                                                Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                                                                                Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("PageSize")), recordingsList.Pagesize);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), recordingsList.Page);
                Assert.AreEqual(1, recordingsList.Total);

                var recording = recordingsList.Elements.First();

                Assert.AreEqual("http://recordings.telapi.com/RBfcc94a3e2b5d4e4c89f7017d6387ffb8/RE4288908463cd614b41084509ad8893a7.mp3", recording.RecordingUrl);
                Assert.AreEqual(15, recording.Duration);
            }
        }
        public void CallsConnectorRecordLiveCall()
        {
            const string methodName = "recordLiveCall";

            using (new MockServer(Port, "Accounts/{accountSid}/Calls/{callSid}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                //// Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Record live call using calls connector
                var call = service.CallsConnector.RecordLiveCall("TestCallSid",
                                                                 Convert.ToBoolean(jsonRequest.BodyParameter("Record")),
                                                                 EnumHelper.ParseEnum <RecordingAudioDirection>(jsonRequest.BodyParameter("Direction")),
                                                                 Convert.ToInt32(jsonRequest.BodyParameter("TimeLimit")),
                                                                 jsonRequest.BodyParameter("CallbackUrl"),
                                                                 EnumHelper.ParseEnum <RecordingFileFormat>(jsonRequest.BodyParameter("FileFormat")),
                                                                 Convert.ToBoolean(jsonRequest.BodyParameter("TrimSilence")),
                                                                 Convert.ToBoolean(jsonRequest.BodyParameter("Transcribe")),
                                                                 EnumHelper.ParseEnum <TranscribeQuality>(jsonRequest.BodyParameter("TranscribeQuality")),
                                                                 jsonRequest.BodyParameter("TranscribeCallback"));

                Assert.AreEqual(AnsweredBy.TBD, call.AnsweredBy);
                Assert.AreEqual(Convert.ToDecimal(0.1872), call.Price);
                Assert.AreEqual(CallStatus.COMPLETED, call.Status);
            }
        }
Example #9
0
        public void UsagesConnectorListUsagesTest()
        {
            const string methodName = "listUsages";

            using (new MockServer(Port, "Accounts/{accountSid}/Usages.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List usages using usages connector
                var usageList = service.UsagesConnector.ListUsages(Convert.ToInt32(jsonRequest.QueryParameter("Day")),
                                                                   Convert.ToInt32(jsonRequest.QueryParameter("Month")), Convert.ToInt32(jsonRequest.QueryParameter("Year")),
                                                                   ProductStringConverter.GetProduct(Convert.ToInt32(jsonRequest.QueryParameter("Product"))),
                                                                   Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                                                                   Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(jsonRequest.QueryParameter("Page"), usageList.Page.ToString());
                Assert.AreEqual(jsonRequest.QueryParameter("PageSize"), usageList.Pagesize.ToString());

                var usage = usageList.Elements.First();

                Assert.AreEqual(ProductStringConverter.GetProduct(Convert.ToInt32(jsonRequest.QueryParameter("Product"))), usage.Product);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Year")), usage.Year);
            }
        }
Example #10
0
        public void ConferencesConnectorListParticipantsTest()
        {
            const string methodName = "listParticipants";

            using (new MockServer(Port, "Accounts/{accountSid}/Conferences/{conferenceSid}/Participants.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(
                        assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileNameParticipant}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List participants using conferences connector
                var participantList = service.ConferencesConnector.ListParticipants("TestConferenceSid",
                                                                                    Convert.ToBoolean(jsonRequest.QueryParameter("Muted")), Convert.ToBoolean(jsonRequest.QueryParameter("Deaf")),
                                                                                    Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                                                                                    Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(1, participantList.Total);

                var participant = participantList.Elements.First();

                Assert.AreEqual("TestParticipantSid", participant.Sid);
                Assert.AreEqual("TestConferenceSid", participant.ConferenceSid);
                Assert.IsFalse(participant.Muted);
            }
        }
Example #11
0
        public void SmsConnectorListSmsMessages()
        {
            const string methodName = "listSms";

            using (new MockServer(Port, "Accounts/{accountSid}/SMS/Messages.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List messages using sms connector
                var smsList = service.SmsConnector.ListSmsMessages(to: jsonRequest.QueryParameter("To"), page: int.Parse(jsonRequest.QueryParameter("Page")), pageSize: int.Parse(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(2, smsList.Total);
                Assert.AreEqual(1, smsList.Numpages);
                Assert.AreEqual(jsonRequest.QueryParameter("Page"), smsList.Page.ToString());
                Assert.AreEqual(jsonRequest.QueryParameter("PageSize"), smsList.Pagesize.ToString());

                var message = smsList.Elements.Last();

                Assert.AreEqual(jsonRequest.QueryParameter("To"), message.To);
                Assert.AreEqual(SmsStatus.SENT, message.Status);
                Assert.AreEqual(SmsDirection.OUTBOUND_API, message.Direction);
                Assert.AreEqual(Convert.ToDecimal(0.0616), message.Price);
            }
        }
        public void FraudControlConnectorListFraudControlResourcesTest()
        {
            const string methodName = "listFraudControlResources";

            using (new MockServer(Port, "Accounts/{accountSid}/Fraud.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List resources using fraud control connector
                var fraudControlResourcesList = service.FraudControlConnector.ListFraudControlResources(
                    Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                    Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(4, fraudControlResourcesList.Total);

                var fraudControlRule = fraudControlResourcesList.Authorized.First();

                Assert.AreEqual("TestFraudControlRuleSid", fraudControlRule.Sid);
                Assert.AreEqual(false, fraudControlRule.MobileEnabled);
                Assert.AreEqual(true, fraudControlRule.SmsEnabled);
            }
        }
        public void NotificationsConnectorListNotificationsTest()
        {
            const string methodName = "listNotifications";

            using (new MockServer(Port, "Accounts/{accountSid}/Notifications.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List notifications using notifications connector
                var notificationList = service.NotificationsConnector.ListNotifications(EnumHelper.ParseEnum <Log>(jsonRequest.QueryParameter("Log")),
                                                                                        Convert.ToInt32(jsonRequest.QueryParameter("Page")), Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("PageSize")), notificationList.Pagesize);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), notificationList.Page);
                Assert.AreEqual(23, notificationList.Total);

                var notification = notificationList.Elements.First();

                Assert.AreEqual(EnumHelper.ParseEnum <Log>(jsonRequest.QueryParameter("Log")), notification.Log);
                Assert.AreEqual(21227, notification.ErrorCode);
            }
        }
Example #14
0
        public void CarrierServicesConnectorListBnaLookups()
        {
            const string methodName = "listBnaLookups";

            using (new MockServer(Port, "Accounts/{accountSid}/Lookups/Bna.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileNameBna}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List bna lookups using carrier services connector
                var bnaLookupsList = service.CarrierServicesConnector.BnaLookupList(
                    Convert.ToInt32(jsonRequest.QueryParameter("Page")),
                    Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(1, bnaLookupsList.Total);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), bnaLookupsList.Page);

                var bnaLookup = bnaLookupsList.Elements.First();

                Assert.AreEqual("+14086474636", bnaLookup.PhoneNumber);
                Assert.AreEqual("Saratoga", bnaLookup.City);
            }
        }
Example #15
0
        public void TranscriptionsConnectorTranscribeAudioUrlTest()
        {
            const string methodName = "transcribeAudioUrl";

            using (new MockServer(Port, "/Accounts/{accountSid}/Transcriptions.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Transcribe audio url using transcriptions connector
                var transcription = service.TranscriptionsConnector.TranscribeAudioUrl(
                    jsonRequest.BodyParameter("AudioUrl"),
                    jsonRequest.BodyParameter("TranscribeCallback"),
                    EnumHelper.ParseEnum <HttpMethod>(jsonRequest.BodyParameter("CallbackMethod")),
                    Convert.ToInt32(jsonRequest.BodyParameter("SliceStart")),
                    Convert.ToInt32(jsonRequest.BodyParameter("SliceDuration")),
                    EnumHelper.ParseEnum <TranscribeQuality>(jsonRequest.BodyParameter("Quality")));

                Assert.AreEqual("http://dev.calyx.hr/~vprenner/zang.mp3", transcription.AudioUrl);
                Assert.AreEqual(TranscriptionStatus.COMPLETED, transcription.Status);
                Assert.AreEqual(50, transcription.Duration);
            }
        }
        public void MmsConnectorSendMms()
        {
            const string methodName = "sendMms";

            using (new MockServer(Port, "/Accounts/{accountSid}/MMS/Messages.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Send mms using mms connector
                var message = service.MmsConnector.SendMms(jsonRequest.BodyParameter("To"),
                                                           jsonRequest.BodyParameter("MediaUrl"), from: jsonRequest.BodyParameter("From"),
                                                           body: jsonRequest.BodyParameter("Body"));

                Assert.AreEqual(jsonRequest.BodyParameter("To"), message.To);
                Assert.AreEqual(jsonRequest.BodyParameter("MediaUrl"), message.MediaUrl);
                Assert.AreEqual(jsonRequest.BodyParameter("Body"), message.Body);
                Assert.AreEqual(jsonRequest.BodyParameter("From"), message.From);
                Assert.AreEqual(MmsStatus.QUEUED, message.Status);
                Assert.AreEqual(MmsDirection.OUTBOUND, message.Direction);
            }
        }
Example #17
0
        public void CarrierServicesConnectorListCnamLookups()
        {
            const string methodName = "listCnamLookups";

            using (new MockServer(Port, "Accounts/{accountSid}/Lookups/Cnam.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileNameCnam}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List cnam lookups using carrier services connector
                var cnamLookupsList = service.CarrierServicesConnector.CnamLookupList(
                    Convert.ToInt32(jsonRequest.QueryParameter("Page")), Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(4, cnamLookupsList.Total);

                var cnamLookup = cnamLookupsList.Elements.First();

                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), cnamLookupsList.Page);
                Assert.AreEqual("+19093900002", cnamLookup.PhoneNumber);
                Assert.AreEqual("/v2/Accounts/ACe1889084056167d57a944486a50ceb46/CNAM/CL6588908407bcc1991e244475aaadec39", cnamLookup.Uri);
            }
        }
        public void ApplicationClientsConnectorListApplicationClientsTest()
        {
            const string methodName = "listApplicationClients";

            using (new MockServer(Port, "Accounts/{accountSid}/Applications/{applicationSid}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List application clients using application clients connector
                var applicationClientsList = service.ApplicationClientsConnector.ListApplicationClients("TestAccountSid", "TestApplicationSid");

                Assert.AreEqual(1, applicationClientsList.Total);

                var applicationClient = applicationClientsList.Elements.First();

                Assert.AreEqual("TestApplicationClientSid", applicationClient.Sid);
                Assert.AreEqual("MyApplicationClient", applicationClient.Nickname);
                Assert.AreEqual("10.0.0.1", applicationClient.RemoteIp);
                Assert.AreEqual(PresenceStatus.INIT, applicationClient.PresenceStatus);
            }
        }
Example #19
0
        public void SipIpAccessControlListsConnectorListIpAclsTest()
        {
            const string methodName = "listIpAcls";

            using (new MockServer(Port, "Accounts/{accountSid}/SIP/IpAccessControlLists.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileNameIPAccesControlList}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List IP access control lists using ip acls connector
                var ipAclsList = service.SipIpAccessControlListsConnector.ListIpAccessControlLists(
                    Convert.ToInt32(jsonRequest.QueryParameter("Page")), Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Page")), ipAclsList.Page);
                Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("PageSize")), ipAclsList.Pagesize);

                var ipAcl = ipAclsList.Elements.First();

                Assert.AreEqual(1, ipAcl.IpAddressesCount);
                Assert.AreEqual("MyAclList", ipAcl.FriendlyName);
            }
        }
Example #20
0
        public void RecordingsConnectorRecordCallTest()
        {
            const string methodName = "recordCall";

            using (new MockServer(Port, "/Accounts/{accountSid}/Calls/{callSid}/Recordings.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Record call using recordings connector
                var recording = service.RecordingsConnector.RecordCall("TestCallSid",
                                                                       Convert.ToBoolean(jsonRequest.BodyParameter("Record")), EnumHelper.ParseEnum <RecordingAudioDirection>(jsonRequest.BodyParameter("Direction")),
                                                                       Convert.ToInt32(jsonRequest.BodyParameter("TimeLimit")), jsonRequest.BodyParameter("CallbackUrl"),
                                                                       EnumHelper.ParseEnum <RecordingFileFormat>(jsonRequest.BodyParameter("FileFormat")), Convert.ToBoolean(jsonRequest.BodyParameter("TrimSilence")),
                                                                       Convert.ToBoolean(jsonRequest.BodyParameter("Transcribe")), EnumHelper.ParseEnum <TranscribeQuality>(jsonRequest.BodyParameter("TranscribeQuality")),
                                                                       jsonRequest.BodyParameter("TranscribeCallback"));

                Assert.AreEqual("http://recordings.telapi.com/RBfcc94a3e2b5d4e4c89f7017d6387ffb8/RE4288908463cd614b41084509ad8893a7.mp3", recording.RecordingUrl);
                Assert.AreEqual(15, recording.Duration);
            }
        }
Example #21
0
        public void SipDomainsConnectorListDomainsTest()
        {
            const string methodName = "listDomains";

            using (new MockServer(Port, "Accounts/{accountSid}/SIP/Domains.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileNameDomains}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List domains using domainsconnector
                var domainsList = service.SipDomainsConnector.ListDomains();

                Assert.AreEqual(2, domainsList.Total);

                var domain = domainsList.Elements.First();

                Assert.AreEqual("mytestdomain.com", domain.DomainName);
                Assert.AreEqual("http://telapi.com/ivr/welcome/call", domain.VoiceUrl);
                Assert.AreEqual("POST", domain.VoiceFallbackMethod.ToString());
            }
        }
Example #22
0
        public void SendSms(string msj, string number)
        {
            var configuration = new APIConfiguration("AC777c3e32444fc276f957416e87de72d0", "9b7bdfe125fa4703901d136011681d17");
            var service       = new CPaaSService(configuration);

            try
            {
                // Send sms message using sms connector
                var smsMessage = service.SmsConnector.SendSms("+57", "Buenos días usuario. No olvide que tiene una cita con el doctor Juan a las 16h en el hospital 1. Gracias!", from: "+573234411715");
                Console.WriteLine(smsMessage.Body);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public void FraudControlConnectorBlockDestinationTest()
        {
            const string methodName = "blockDestination";

            using (new MockServer(Port, "Accounts/{accountSid}/Fraud/Block/{countryCode}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileNameBlocked}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Block destination using fraud control connector
                var fraudControlRule = service.FraudControlConnector.BlockDestination("HR",
                                                                                      Convert.ToBoolean(jsonRequest.BodyParameter("MobileEnabled")),
                                                                                      Convert.ToBoolean(jsonRequest.BodyParameter("LandlineEnabled")),
                                                                                      Convert.ToBoolean(jsonRequest.BodyParameter("SmsEnabled")));

                Assert.AreEqual("TestFraudControlRuleSid", fraudControlRule.Sid);
                Assert.AreEqual(Convert.ToBoolean(jsonRequest.BodyParameter("MobileEnabled")), fraudControlRule.MobileEnabled);
                Assert.AreEqual(Convert.ToBoolean(jsonRequest.BodyParameter("SmsEnabled")), fraudControlRule.SmsEnabled);
            }
        }
        public void AvailablePhoneNumbersConnectorListAvailablePhoneNumbersTest()
        {
            const string methodName = "listAvailablePhoneNumbers";

            using (new MockServer(Port, "Accounts/{accountSid}/AvailablePhoneNumbers/{country}/{typeString}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List available phone numbers using available phone numbers connector
                var availablePhoneNumbersList = service.AvailablePhoneNumbersConnector.ListAvailableNumbers("TestAccountSid",
                                                                                                            "HR", AvailablePhoneNumberType.TOLLFREE,
                                                                                                            jsonRequest.QueryParameter("Contains"), jsonRequest.QueryParameter("AreaCode"), jsonRequest.QueryParameter("InRegion"),
                                                                                                            jsonRequest.QueryParameter("InPostalCode"), Convert.ToInt32(jsonRequest.QueryParameter("Page")), Convert.ToInt32(jsonRequest.QueryParameter("PageSize")));

                var availablePhoneNumber = availablePhoneNumbersList.Elements.First();

                Assert.AreEqual("HR", availablePhoneNumber.IsoCountry);
            }
        }
Example #25
0
        public void SipCredentialsConnectorListCredentialsTest()
        {
            const string methodName = "listCredentials";

            using (new MockServer(Port, "Accounts/{accountSid}/SIP/CredentialLists/{clSid}/Credentials.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // List credentials using credentials connector
                var credentialList = service.SipCredentialsConnector.ListCredentials("TestCredentialsListSid");

                Assert.AreEqual(1, credentialList.Total);

                var credential = credentialList.Elements.First();

                Assert.AreEqual("TestCredentialSid", credential.Sid);
                Assert.AreEqual("testuser123", credential.FriendlyName);
            }
        }
Example #26
0
        public void ConferencesConnectorViewConferenceTest()
        {
            const string methodName = "viewConference";

            using (new MockServer(Port, "Accounts/{accountSid}/Conferences/{conferenceSid}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("GET"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(
                        assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileNameConference}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // View conference using conferences connector
                var conference = service.ConferencesConnector.ViewConference("TestConferenceSid");

                Assert.AreEqual("TestConferenceSid", conference.Sid);
                Assert.AreEqual(ConferenceStatus.COMPLETED, conference.Status);
                Assert.AreEqual("TestConference", conference.FriendlyName);
            }
        }
Example #27
0
        public void SipIpAccessControlListsConnectorAddAclIpTest()
        {
            const string methodName = "addAclIp";

            using (new MockServer(Port, "Accounts/{accountSid}/SIP/IpAccessControlLists/{aclSid}/IpAddresses.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileNameAccessControlListIP}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Add access control list IP using ip acls connector
                var aclIp = service.SipIpAccessControlListsConnector.AddAccessControlListIp("TestIpAccessControlListSid",
                                                                                            jsonRequest.BodyParameter("FriendlyName"), jsonRequest.BodyParameter("IpAddress"));

                Assert.AreEqual(jsonRequest.BodyParameter("IpAddress"), aclIp.IPAddress);
                Assert.AreEqual(jsonRequest.BodyParameter("FriendlyName"), aclIp.FriendlyName);
            }
        }
Example #28
0
        public void CarrierServicesConnectorCarrierLookupTest()
        {
            const string methodName = "carrierLookup";

            using (new MockServer(Port, "Accounts/{accountSid}/Lookups/Carrier.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("POST"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileNameCarrier}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Retrieve carrier lookup using carrier services connector
                var carrierLookup = service.CarrierServicesConnector.CarrierLookup(jsonRequest.BodyParameter("PhoneNumber"));

                Assert.AreEqual(jsonRequest.BodyParameter("PhoneNumber"), carrierLookup.PhoneNumber);
                Assert.AreEqual(22607, carrierLookup.CarrierId);
            }
        }
        public void IncomingPhoneNumbersConnectorDeleteIncomingNumberTest()
        {
            const string methodName = "deleteIncomingPhoneNumber";

            using (new MockServer(Port, "/Accounts/{accountSid}/IncomingPhoneNumbers/{incomingPhoneNumberSid}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("DELETE"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileName}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Delete incoming phone number application using applications connector
                var phoneNumber = service.IncomingPhoneNumbersConnector.DeleteIncomingNumber("TestIncomingPhoneNumberSid");

                Assert.AreEqual("(989) 494-5633", phoneNumber.FriendlyName);
                Assert.AreEqual(IncomingPhoneNumberType.LOCAL, phoneNumber.Type);
            }
        }
Example #30
0
        public void SipDomainsConnectorDeleteIPAccessControlListTest()
        {
            const string methodName = "deleteIpAcl";

            using (new MockServer(Port, "Accounts/{accountSid}/SIP/Domains/{domainSid}/IpAccessControlListMappings/{alSid}.json", (req, rsp, prm) =>
            {
                // Check http method
                if (!req.HttpMethod.Equals("DELETE"))
                {
                    throw new ArgumentException();
                }

                // Check parameter equality
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req);
                ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req);

                // Define server response
                var assembly = Assembly.GetExecutingAssembly();
                var streamReader =
                    new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseJsonFileNameIPAccesControlList}"));
                var json = streamReader.ReadToEnd();

                var buffer = Encoding.ASCII.GetBytes(json);
                rsp.Content(buffer);
            }))
            {
                // Create configuration
                var configuration = new APIConfiguration(AccountSid, AuthToken);
                configuration.BaseUrl = $"http://localhost:{Port}/";

                // Get json request from json file
                var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName);

                // Create service
                var service = new CPaaSService(configuration);

                // Delete mapped IP access control list using domains connector
                var ipAcl = service.SipDomainsConnector.DeleteMappedIpAccessControlList("TestDomainSid", "TestIpAccessControlListSid");

                Assert.AreEqual("TestIpAccessControlListSid", ipAcl.Sid);
            }
        }