Пример #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 void GetTest()
 {
     var item = new Site
     {
         Id = "1",
         Name = "Name",
         Address = new Address
         {
             City = "City",
             Country = "County"
         }
     };
     using (var server = new HttpServer(new RequestHandler
     {
         EstimatedMethod = "GET",
         EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1", Helper.AccountId),
         ContentToSend = Helper.CreateXmlContent(new SiteResponse{Site = item})
     }))
     {
         var client = Helper.CreateClient();
         var result = Site.Get(client, "1").Result;
         if (server.Error != null) throw server.Error;
         Helper.AssertObjects(item, result);
     }
 }
Пример #4
0
 public static async Task<Site> Create(Client client, Site item)
 {
     using (var response = await client.MakePostRequest(client.ConcatAccountPath(SitePath), item))
     {
         return await Get(client, client.GetIdFromLocationHeader(response.Headers.Location));
     }
 }
Пример #5
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);
     }
 }
Пример #6
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]);
            }
        }
Пример #7
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);
     }
 }
Пример #8
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;
     }
 }
Пример #9
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;
     }
 }
Пример #10
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;
            }
        }
Пример #11
0
        public void CreateWithDefaultClientTest()
        {
            var item = new Site
            {
                Name = "Name",
                Address = new Address
                {
                    City = "City",
                    StateCode = "State"
                }
            };

            using (var server = new HttpServer(new[]
            {
                new RequestHandler
                {
                    EstimatedMethod = "POST",
                    EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites", Helper.AccountId),
                    EstimatedContent = Helper.ToXmlString(item),
                    HeadersToSend =
                        new Dictionary<string, string>
                        {
                            {"Location", string.Format("/v1.0/accounts/{0}/sites/1", Helper.AccountId)}
                        }
                },
                new RequestHandler
                {
                    EstimatedMethod = "GET",
                    EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/sites/1", Helper.AccountId),
                    ContentToSend = Helper.CreateXmlContent(new SiteResponse{Site = new Site {Id = "1"}})
                }
            }))
            {
                var i = Site.Create(item).Result;
                if (server.Error != null) throw server.Error;
                Assert.AreEqual("1", i.Id);
            }
        }
Пример #12
0
 public Task Update(Site site)
 {
     return Client.MakePutRequest(Client.ConcatAccountPath(string.Format("{0}/{1}", SitePath, Id)),
         site, true);
 }
Пример #13
0
 public static Task<Site> Create(Site item)
 {
     return Create(Client.GetInstance(), item);
 }