예제 #1
0
 public static Task<SipPeer[]> List(Client client, string siteId)
 {
     if (siteId == null) throw new ArgumentNullException("siteId");
     var site = new Site { Id = siteId };
     site.SetClient(client);
     return site.GetSipPeers();
 }
예제 #2
0
 public static Task<SipPeer> Create(Client client, SipPeer item)
 {
     if (item.SiteId == null) throw new ArgumentException("SiteId is required");
     var site = new Site {Id = item.SiteId};
     site.SetClient(client);
     return site.CreateSipPeer(item);
 }
예제 #3
0
        public static Task <SipPeer> Create(Client client, SipPeer item)
        {
            if (item.SiteId == null)
            {
                throw new ArgumentException("SiteId is required");
            }
            var site = new Site {
                Id = item.SiteId
            };

            site.SetClient(client);
            return(site.CreateSipPeer(item));
        }
예제 #4
0
        public static Task <SipPeer[]> List(Client client, string siteId)
        {
            if (siteId == null)
            {
                throw new ArgumentNullException("siteId");
            }
            var site = new Site {
                Id = siteId
            };

            site.SetClient(client);
            return(site.GetSipPeers());
        }
예제 #5
0
        public static Task <SipPeer> Update(Client client, string siteId, string id, SipPeer sipPeer)
        {
            if (siteId == null)
            {
                throw new ArgumentNullException("siteId");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            var site = new Site {
                Id = siteId
            };

            site.SetClient(client);
            return(site.UpdateSipPeer(id, sipPeer));
        }
예제 #6
0
 public void GetSipPeersWithXmlTest()
 {
     using (var server = new HttpServer(new[]
     {
         new RequestHandler
         {
             EstimatedMethod = "GET",
             EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1/sippeers", Helper.AccountId),
             ContentToSend = new StringContent(TestXmlStrings.ValidSipPeersResponseXml, Encoding.UTF8, "application/xml")
         }
     }))
     {
         var client = Helper.CreateClient();
         var i = new Site { Id = "1" };
         i.SetClient(client);
         var r = i.GetSipPeers().Result[0];
         if (server.Error != null) throw server.Error;
         Assert.AreEqual("12345", r.Id);
         Assert.AreEqual("SIP Peer 1", r.Name);
         Assert.AreEqual("Sip Peer 1 description", r.Description);
         Assert.IsTrue(r.IsDefaultPeer);
         Assert.AreEqual("SIP", r.ShortMessagingProtocol);
         Assert.AreEqual("70.62.112.156", r.VoiceHosts[0].HostName);
         Assert.AreEqual("70.62.112.156", r.SmsHosts[0].HostName);
         Assert.AreEqual("70.62.112.156", r.TerminationHosts[0].HostName);
         Assert.AreEqual(5060, r.TerminationHosts[0].Port);
         Assert.AreEqual("DOMESTIC", r.TerminationHosts[0].CustomerTrafficAllowed);
         Assert.IsTrue(r.TerminationHosts[0].DataAllowed);
         Assert.IsFalse(r.CallingName.Enforced);
         Assert.IsTrue(r.CallingName.Display);
     }
 }
예제 #7
0
        public void GetSipPeersTest()
        {
            var items = new[]{
                new SipPeer
                {
                    Id = "10",
                    SiteId = "1",
                    Name = "test",
                    IsDefaultPeer = true
                },
                new SipPeer
                {
                    Id = "11",
                    SiteId = "1",
                    Name = "test2",
                    IsDefaultPeer = false
                }

            };
            using (var server = new HttpServer(new[]
            {
                new RequestHandler
                {
                    EstimatedMethod = "GET",
                    EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1/sippeers", Helper.AccountId),
                    ContentToSend = Helper.CreateXmlContent(new SipPeersResponse{SipPeers = items})
                }
            }))
            {
                var client = Helper.CreateClient();
                var i = new Site { Id = "1" };
                i.SetClient(client);
                var r = i.GetSipPeers().Result;
                if (server.Error != null) throw server.Error;
                Helper.AssertObjects(items[0], r[0]);
                Helper.AssertObjects(items[1], r[1]);
            }
        }
예제 #8
0
 public void GetSipPeerWithXmlTest()
 {
     using (var server = new HttpServer(new[]
     {
         new RequestHandler
         {
             EstimatedMethod = "GET",
             EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1/sippeers/10", Helper.AccountId),
             ContentToSend = new StringContent(TestXmlStrings.ValidSipPeerResponseXml, Encoding.UTF8, "application/xml")
         }
     }))
     {
         var client = Helper.CreateClient();
         var i = new Site { Id = "1" };
         i.SetClient(client);
         var r = i.GetSipPeer("10").Result;
         if (server.Error != null) throw server.Error;
         Assert.AreEqual("10", r.Id);
         Assert.AreEqual("SIP Peer 1", r.Name);
         Assert.AreEqual("Sip Peer 1 description", r.Description);
         Assert.IsTrue(r.IsDefaultPeer);
         Assert.AreEqual("SIP", r.ShortMessagingProtocol);
     }
 }
예제 #9
0
 public void CreateSipPeerTest()
 {
     var item = new SipPeer
     {
         Name = "test",
         IsDefaultPeer = true
     };
     var createdItem = new SipPeer
     {
         Id = "1",
         SiteId = "1",
         Name = "test",
         IsDefaultPeer = true
     };
     using (var server = new HttpServer(new[]
     {
         new RequestHandler
         {
             EstimatedMethod = "POST",
             EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1/sippeers", Helper.AccountId),
             EstimatedContent = Helper.ToXmlString(item),
             HeadersToSend = new Dictionary<string, string>
             {
                 {"Location", string.Format("/v1.0/accounts/{0}/sites/1/sippeers/10", Helper.AccountId)}
             },
             StatusCodeToSend = 201
         },
         new RequestHandler
         {
             EstimatedMethod = "GET",
             EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1/sippeers/10", Helper.AccountId),
             ContentToSend = Helper.CreateXmlContent(new SipPeerResponse{SipPeer = createdItem})
         }
     }))
     {
         var client = Helper.CreateClient();
         var i = new Site { Id = "1" };
         i.SetClient(client);
         var r = i.CreateSipPeer(item).Result;
         Helper.AssertObjects(createdItem, r);
         if (server.Error != null) throw server.Error;
     }
 }
예제 #10
0
 public void DeleteTest()
 {
     using (var server = new HttpServer(new[]
     {
         new RequestHandler
         {
             EstimatedMethod = "DELETE",
             EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1", Helper.AccountId),
         }
     }))
     {
         var client = Helper.CreateClient();
         var i = new Site { Id = "1" };
         i.SetClient(client);
         i.Delete().Wait();
         if (server.Error != null) throw server.Error;
     }
 }
예제 #11
0
        public void UpdateTest()
        {
            var item = new Site
            {
                Name = "Name",
                Address = new Address
                {
                    City = "City",
                    StateCode = "State"
                }
            };

            using (var server = new HttpServer(new[]
            {
                new RequestHandler
                {
                    EstimatedMethod = "PUT",
                    EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1", Helper.AccountId),
                    EstimatedContent = Helper.ToXmlString(item)
                }
            }))
            {
                var client = Helper.CreateClient();
                var i = new Site {Id = "1"};
                i.SetClient(client);
                i.Update(item).Wait();
                if (server.Error != null) throw server.Error;
            }
        }