Skip to content

Commit

Permalink
DX-2798: Fix ImportTnCheckerPayload XML Serialization (#69)
Browse files Browse the repository at this point in the history
DX-2798: Fix ImportTnCheckerPayload XML Serialization
  • Loading branch information
matthewkmartin authored Sep 6, 2022
2 parents 736e320 + 0b3dbf5 commit 06e4050
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@ FakesAssemblies/
.tmproj
nbproject
Thumbs.db
.vscode

.vs
42 changes: 34 additions & 8 deletions Bandwidth.Iris.Tests/Models/ImportTnCheckerTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Net.Http;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using Bandwidth.Iris.Model;
using Xunit;

namespace Bandwidth.Iris.Tests.Models
{

public class ImportTnCheckerTests
{
[Fact]
Expand All @@ -15,13 +17,12 @@ public void TestCreate()

var order = new ImportTnCheckerPayload
{
TelephoneNumbers = new TelephoneNumber[]
{
new TelephoneNumber
{
FullNumber = "3032281000"
}
}
SiteId = "486",
SipPeerId = "500025",
TelephoneNumbers = new string[]
{
"3032281000"
}
};

using (var server = new HttpServer(new RequestHandler
Expand All @@ -44,5 +45,30 @@ public void TestCreate()

}
}

[Fact]
public void TestSerialize()
{
var order = new ImportTnCheckerPayload
{
SiteId = "486",
SipPeerId = "500025",
TelephoneNumbers = new string[]
{
"3032281000"
}
};

XmlSerializer xs = new XmlSerializer(typeof(ImportTnCheckerPayload));

string xmlStringResult = null;
using (StringWriter writer = new StringWriter())
{
xs.Serialize(writer, order);
xmlStringResult = writer.ToString();

Assert.Equal(TestXmlStrings.ImportTnCheckerSampleSerialization, xmlStringResult);
}
}
}
}
2 changes: 2 additions & 0 deletions Bandwidth.Iris.Tests/TestXmlStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ public static class TestXmlStrings

public static string ImportTnCheckerResponse = $"<ImportTnCheckerResponse>{ImportTnCheckerPayload}</ImportTnCheckerResponse>";

public static string ImportTnCheckerSampleSerialization = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<ImportTnCheckerPayload xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n <SiteId>486</SiteId>\n <SipPeerId>500025</SipPeerId>\n <TelephoneNumbers>\n <TelephoneNumber>3032281000</TelephoneNumber>\n </TelephoneNumbers>\n</ImportTnCheckerPayload>";

public static string RemoveImportedOrder = @"<RemoveImportedTnOrder>
<CustomerOrderId>SJM000001</CustomerOrderId>
<OrderCreateDate>2018-01-20T02:59:54.000Z</OrderCreateDate>
Expand Down
9 changes: 8 additions & 1 deletion Bandwidth.Iris/Model/ImportTnChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ public static Task<ImportTnCheckerResponse> Create(ImportTnCheckerPayload payloa

public class ImportTnCheckerPayload
{
public TelephoneNumber[] TelephoneNumbers { get; set; }
public string SiteId { get; set; }

public string SipPeerId { get; set; }

[XmlArray("TelephoneNumbers")]
[XmlArrayItem("TelephoneNumber")]
public string[] TelephoneNumbers { get; set; }

[XmlArray("ImportTnErrors")]
[XmlArrayItem("ImportTnError")]
public ImportTnError[] ImportTnErrors { get; set; }
Expand Down

0 comments on commit 06e4050

Please sign in to comment.