public void GetFile2Test() { const string data = "hello"; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/loas/test", Helper.AccountId), ContentToSend = new StringContent(data, Encoding.UTF8, "media/type") })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); using (var r = portIn.GetFile("test", true).Result) using (var reader = new StreamReader(r.Stream, Encoding.UTF8)) { Assert.AreEqual("media/type", r.MediaType); Assert.AreEqual(data, reader.ReadToEnd()); } if (server.Error != null) { throw server.Error; } } }
public void GetNotesTest() { using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/notes", Helper.AccountId), ContentToSend = new StringContent(TestXmlStrings.NotesResponse, Encoding.UTF8, "application/xml") })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); var list = portIn.GetNotes().Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual(2, list.Length); Assert.AreEqual("11299", list[0].Id); Assert.AreEqual("customer", list[0].UserId); Assert.AreEqual("Test", list[0].Description); Assert.AreEqual("11301", list[1].Id); Assert.AreEqual("customer", list[1].UserId); Assert.AreEqual("Test1", list[1].Description); } }
public void PutFileMetadataTest() { using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "PUT", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/loas/test/metadata", Helper.AccountId), EstimatedContent = TestXmlStrings.FileMetadataPut })) { var fileMetadata = new FileMetadata { DocumentType = "INVOICE", DocumentName = "docName" }; var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); var r = portIn.PutFileMetadata("test", fileMetadata).Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual("OK", r.StatusCode.ToString()); } }
public void UpdateFile2Test() { const string data = "hello"; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "PUT", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/loas/test", Helper.AccountId), EstimatedContent = data, EstimatedHeaders = new Dictionary <string, string> { { "Content-Type", "media/type" } } })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); portIn.UpdateFile("test", Encoding.UTF8.GetBytes(data), "media/type").Wait(); if (server.Error != null) { throw server.Error; } } }
public void CreateWithDefaultClientTest() { var order = new LnpOrderResponse { BillingTelephoneNumber = "1111", Subscriber = new Subscriber { SubscriberType = "BUSINESS", BusinessName = "Company", ServiceAddress = new Address { City = "City", StateCode = "State", Country = "County" } }, SiteId = "1" }; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "POST", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins", Helper.AccountId), EstimatedContent = Helper.ToXmlString(order), ContentToSend = Helper.CreateXmlContent(order) })) { var r = PortIn.Create(order).Result; if (server.Error != null) { throw server.Error; } Helper.AssertObjects(order, r); } }
public void UpdateTest() { var data = new LnpOrderSupp { RequestedFocDate = DateTime.Parse("2014-11-18T00:00:00.000Z"), WirelessInfo = new [] { new WirelessInfo { AccountNumber = "77129766500001", PinNumber = "0000" } } }; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "PUT", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1", Helper.AccountId), EstimatedContent = Helper.ToXmlString(data) })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); portIn.Update(data).Wait(); if (server.Error != null) { throw server.Error; } } }
public void CreateFile2Test() { const string data = "hello"; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "POST", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/loas", Helper.AccountId), EstimatedContent = data, EstimatedHeaders = new Dictionary <string, string> { { "Content-Type", "media/type" } }, ContentToSend = Helper.CreateXmlContent(new FileResult { FileName = "test" }) })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); var fileName = portIn.CreateFile(Encoding.UTF8.GetBytes(data), "media/type").Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual("test", fileName); } }
public void GetPortInTest() { var portIn = new PortIn { Id = "1" }; using (var server = new HttpServer(new[] { new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/{1}", Helper.AccountId, portIn.Id), EstimatedContent = "", ContentToSend = new StringContent(TestXmlStrings.xmlLnpOrderResponseNoErrors, Encoding.UTF8, "application/xml") } })) { var client = Helper.CreateClient(); portIn.SetClient(client); var r = portIn.GetOrder().Result; Assert.AreEqual("SJM00002", r.CustomerOrderId); Assert.AreEqual("CANCELLED", r.ProcessingStatus); Assert.AreEqual(DateTime.Parse("2014-08-04T13:37:06.323"), r.OrderCreateDate); Assert.AreEqual(DateTime.Parse("2014-08-04T13:37:08.676"), r.LastModifiedDate); Assert.AreEqual(DateTime.Parse("2014-08-04T13:37:08.676"), r.RequestedFocDate); Assert.AreEqual("The Authguy", r.LoaAuthorizingPerson); Assert.AreEqual("9195551234", r.BillingTelephoneNumber); Assert.AreEqual("9175131245", r.NewBillingTelephoneNumber); Assert.AreEqual("Foo", r.AlternateSpid); Assert.AreEqual("20", r.AccountId); Assert.AreEqual("2857", r.SiteId); Assert.AreEqual("317771", r.PeerId); Assert.AreEqual("Mock Carrier", r.LosingCarrierName); Assert.AreEqual("Bandwidth CLEC", r.VendorName); Assert.AreEqual("jbm", r.UserId); Assert.AreEqual("jbm", r.LastModifiedBy); Assert.AreEqual(false, r.PartialPort); Assert.AreEqual(false, r.Triggered); Assert.AreEqual(PortType.AUTOMATED, r.PortType); //TnAttributes Assert.AreEqual(1, r.TnAttributes.Length); Assert.AreEqual("Protected", r.TnAttributes[0]); //Suscriber Assert.AreEqual("BUSINESS", r.Subscriber.SubscriberType); Assert.AreEqual("First", r.Subscriber.FirstName); Assert.AreEqual("Last", r.Subscriber.LastName); Assert.AreEqual("11235", r.Subscriber.ServiceAddress.HouseNumber); Assert.AreEqual("Back", r.Subscriber.ServiceAddress.StreetName); Assert.AreEqual("Denver", r.Subscriber.ServiceAddress.City); Assert.AreEqual("CO", r.Subscriber.ServiceAddress.StateCode); Assert.AreEqual("27541", r.Subscriber.ServiceAddress.Zip); Assert.AreEqual("Canyon", r.Subscriber.ServiceAddress.County); Assert.AreEqual("United States", r.Subscriber.ServiceAddress.Country); Assert.AreEqual("Service", r.Subscriber.ServiceAddress.AddressType); } }
/// <summary> /// Stops the queue listening for messages and deletes the proxy on the bus. /// </summary> public void Stop() { ExceptionHandler.Stop = true; IsEnabled = false; PortIn.Close(); Logger.Info("Connection closed"); JmsPort.CloseAll(connectorId); }
/// <summary> /// Blocks an waits for messages. /// </summary> public override void Listen() { try { while (IsEnabled) { String textMsg; textMsg = PortIn.Receive(); if (textMsg == null) { continue; } MethodCallMessage methodCallRequest = Marshaller.UnmarshallObject <MethodCallMessage>(textMsg); if (methodCallRequest.MethodCall.Args == null) { methodCallRequest.MethodCall.Args = new List <Object>(); } MethodResultMessage methodReturnMessage = CallMethod(methodCallRequest); if (methodCallRequest.Answer) { string returnMsg = Marshaller.MarshallObject(methodReturnMessage); JmsDestination dest = new JmsDestination(Destination); IOutgoingPort portOut = new JmsOutgoingPort(JmsDestination.CreateDestinationString(dest.Host, methodCallRequest.CallId), ExceptionHandler, ConnectorId); portOut.Send(returnMsg); portOut.Close(); if (methodReturnMessage.Result.Type.Equals(ReturnType.Exception)) { throw new BridgeException("A exception occurs, while the message has been created", new BridgeException(methodReturnMessage.Result.Arg.ToString())); } } } } catch (Exception e) { if (IsEnabled) { ExceptionHandler.Changed += delegate(object[] obj) { Listen(); return(null); }; ExceptionHandler.HandleException(e); } } }
/* * Open the sockets and make the connection */ public override int Open() { int Result = 0; RemoteIP = Server; RemotePort = PortOut.ToString(); LocalPort = PortIn.ToString(); try { sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); LocalIP = GetLocalIP(); } catch (Exception ex) { AddError(Result = 801, ex.Message, GetType().Name + ".SocketClient", "Failed to set socket"); } try { // binding socket epLocal = new IPEndPoint(IPAddress.Parse(LocalIP), Convert.ToInt32(LocalPort)); sck.Bind(epLocal); // connect to remote IP and port epRemote = new IPEndPoint(IPAddress.Parse(RemoteIP), Convert.ToInt32(RemotePort)); sck.Connect(epRemote); Connected = true; if (DebugLevel > 5) { WriteDebug("Waiting..."); } // starts to listen to an specific port buffer = new byte[1500]; sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer); } catch (Exception ex) { AddError(Result = 802, ex.Message, GetType().Name + ".SocketClient", "Failed to open socket"); } return(Result); }
public void GetPortInsTest() { var portIn = new PortIn(); DateTime startdate = DateTime.Parse("2014-11-21T14:00:33.836Z"); DateTime enddate = DateTime.Parse("2014-11-21T14:00:33.835Z"); DateTime date = DateTime.Parse("2014-11-21T14:00:33.834Z"); using (var server = new HttpServer(new[] { new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/?page={1}&size={2}&date={3}&enddate={4}&startdate={5}&pon={6}&status={7}&tn={8}", Helper.AccountId, 1, 300, Uri.EscapeDataString(date.ToString()), Uri.EscapeDataString(enddate.ToString()), Uri.EscapeDataString(startdate.ToString()), "ponstr", "completed", "9199199191"), EstimatedContent = "", ContentToSend = new StringContent(TestXmlStrings.xmlLNPResponseWrapper, Encoding.UTF8, "application/xml") } })) { var client = Helper.CreateClient(); portIn.SetClient(client); var r = portIn.GetPortIns(Helper.AccountId, date, enddate, startdate, "ponstr", "completed", "9199199191").Result; Assert.AreEqual(" -- link -- ", r.Links.First); Assert.AreEqual(" -- link -- ", r.Links.Next); Assert.AreEqual(3176, r.TotalCount); Assert.AreEqual(1, r.lnpPortInfoForGivenStatuses[0].CountOfTNs); Assert.AreEqual("Neustar", r.lnpPortInfoForGivenStatuses[0].UserId); Assert.AreEqual(DateTime.Parse("2014-11-21T14:00:33.836"), r.lnpPortInfoForGivenStatuses[0].LastModifiedDate); Assert.AreEqual(DateTime.Parse("2014-11-05T19:34:53.176"), r.lnpPortInfoForGivenStatuses[0].OrderDate); Assert.AreEqual("982e3c10-3840-4251-abdd-505cd8610788", r.lnpPortInfoForGivenStatuses[0].OrderId); Assert.AreEqual("port_out", r.lnpPortInfoForGivenStatuses[0].OrderType); Assert.AreEqual(200, r.lnpPortInfoForGivenStatuses[0].ErrorCode); Assert.AreEqual("Port out successful.", r.lnpPortInfoForGivenStatuses[0].ErrorMessage); Assert.AreEqual("9727717577", r.lnpPortInfoForGivenStatuses[0].FullNumber); Assert.AreEqual("COMPLETE", r.lnpPortInfoForGivenStatuses[0].ProcessingStatus); Assert.AreEqual(DateTime.Parse("2014-11-20T00:00:00.000"), r.lnpPortInfoForGivenStatuses[0].RequestedFOCDate); Assert.AreEqual("512E", r.lnpPortInfoForGivenStatuses[0].VendorId); } }
public static void Main(string[] args) { // Get the IHost which will host this application. var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { // Get the instance of DbContext var services = scope.ServiceProvider; var context = services.GetRequiredService <ApiDbContext>(); // Call the PortIn to create port in data PortIn.Initialize(services); } // Continue to run the application host.Run(); }
public void CreateWithXmlTest() { var order = new PortIn { BillingTelephoneNumber = "1111", Subscriber = new Subscriber { SubscriberType = "BUSINESS", BusinessName = "Company", ServiceAddress = new Address { City = "City", StateCode = "State", Country = "County" } }, SiteId = "1" }; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "POST", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins", Helper.AccountId), EstimatedContent = Helper.ToXmlString(order), ContentToSend = new StringContent(TestXmlStrings.ValidCreatePostInResponse, Encoding.UTF8, "application/xml") })) { var client = Helper.CreateClient(); var r = PortIn.Create(client, order).Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual("d28b36f7-fa96-49eb-9556-a40fca49f7c6", r.Id); Assert.AreEqual("201", r.Status.Code); Assert.AreEqual("Order request received. Please use the order id to check the status of your order later.", r.Status.Description); Assert.AreEqual("PENDING_DOCUMENTS", r.ProcessingStatus); Assert.AreEqual("John Doe", r.LoaAuthorizingPerson); Assert.AreEqual("6882015002", r.BillingTelephoneNumber); CollectionAssert.AreEqual(new[] { "6882015025", "6882015026" }, r.ListOfPhoneNumbers); Assert.IsFalse(r.Triggered); Assert.AreEqual("PORTIN", r.BillingType); } }
public void DeleteTest() { using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "DELETE", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1", Helper.AccountId) })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); portIn.Delete().Wait(); if (server.Error != null) { throw server.Error; } } }
public void AddNoteTest() { var item = new Note { UserId = "customer", Description = "Test" }; using (var server = new HttpServer(new [] { new RequestHandler { EstimatedMethod = "POST", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/notes", Helper.AccountId), EstimatedContent = Helper.ToXmlString(item), HeadersToSend = new Dictionary <string, string> { { "Location", string.Format("/v1.0/accounts/{0}/portins/1/notes/11299", Helper.AccountId) } } }, new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/notes", Helper.AccountId), ContentToSend = new StringContent(TestXmlStrings.NotesResponse, Encoding.UTF8, "application/xml") } })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); var r = portIn.AddNote(item).Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual("11299", r.Id); Assert.AreEqual("customer", r.UserId); Assert.AreEqual("Test", r.Description); } }
public void GetFileMetadataTest() { using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/loas/test/metadata", Helper.AccountId), ContentToSend = new StringContent(TestXmlStrings.FileMetadataResponse, Encoding.UTF8, "application/xml") })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); var r = portIn.GetFileMetadata("test").Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual("LOA", r.DocumentType); } }
public void GetFilesTest() { using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "GET", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/portins/1/loas?metadata=true", Helper.AccountId), ContentToSend = new StringContent(TestXmlStrings.FileListResponse, Encoding.UTF8, "application/xml") })) { var client = Helper.CreateClient(); var portIn = new PortIn { Id = "1" }; portIn.SetClient(client); var list = portIn.GetFiles(true).Result; if (server.Error != null) { throw server.Error; } Assert.AreEqual(6, list.Length); Assert.AreEqual("d28b36f7-fa96-49eb-9556-a40fca49f7c6-1416231534986.txt", list[0].FileName); Assert.AreEqual("LOA", list[0].FileMetadata.DocumentType); } }
static async Task PortInDemo() { var numberToCheck = "9192971001"; var lnpResult = await LnpChecker.Check(_client, new [] { numberToCheck }, true); if (lnpResult.PortableNumbers != null && lnpResult.PortableNumbers[0].Equals(numberToCheck)) { var sites = await Site.List(_client); var site = sites[0]; var sipPeers = await site.GetSipPeers(); var sipPeer = sipPeers[0]; var data = new PortIn { BillingTelephoneNumber = numberToCheck, LoaAuthorizingPerson = "Joe Blow", Subscriber = new Subscriber { SubscriberType = "BUSINESS", BusinessName = "Company", ServiceAddress = new Address { HouseNumber = "123", StreetName = "Anywhere St", City = "Raleigh", StateCode = "NC", Zip = "27609" } }, ListOfPhoneNumbers = new string[] { numberToCheck }, PeerId = sipPeer.Id, SiteId = site.Id }; var order = await PortIn.Create(_client, data); Console.WriteLine("Created PortIn Order ID: {0}", order.Id); var fileName = await order.CreateFile(new byte[] { 0, 1, 2, 3, 4, 5 }, "application/pdf"); var metadata = await order.GetFileMetadata(fileName); using (var content = await order.GetFile(fileName)) { var fileContent = content.Buffer; } await order.UpdateFile(fileName, new byte[] { 10, 11, 12, 13, 14, 15 }, "application/pdf"); await order.DeleteFile(fileName); await order.Update(new LnpOrderSupp { RequestedFocDate = DateTime.Parse("2015-07-18T00:00:00.000Z"), WirelessInfo = new[] { new WirelessInfo { AccountNumber = "77129766500001", PinNumber = "0000" } } }); await order.Delete(); } }