first commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Xunit;
|
||||
using USPS.ApiCalls;
|
||||
using USPS.Configuration;
|
||||
using USPS.Parsers;
|
||||
using Landmark.OLA.Models.Addresses;
|
||||
using Landmark.OLA.Models.Addresses.Enums;
|
||||
|
||||
namespace USPS.Tests
|
||||
{
|
||||
public class AddressValidationTest
|
||||
{
|
||||
private readonly IResponseParser<Address> AddressParser;
|
||||
|
||||
|
||||
public AddressValidationTest()
|
||||
{
|
||||
AddressParser = new AddressValidationResponseParser();
|
||||
}
|
||||
|
||||
private readonly Address address = new Address()
|
||||
{
|
||||
Address1 = "109 N Hancock St",
|
||||
Address2 = "Apt 2",
|
||||
City = "Madison",
|
||||
State = StateOption.WI,
|
||||
PostalCode = "53703",
|
||||
PostalCodeExt = "2466",
|
||||
Country = CountryOption.UnitedStates
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ErrorResponseParse()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load("ExampleXML" + System.IO.Path.DirectorySeparatorChar + "USPSAddressError.xml");
|
||||
|
||||
XDocument response;
|
||||
|
||||
using (XmlNodeReader reader = new XmlNodeReader(doc))
|
||||
{
|
||||
response = XDocument.Load(reader);
|
||||
}
|
||||
|
||||
Exception ex = Assert.Throws<FormatException>(() => AddressParser.Parse(response.Root));
|
||||
|
||||
Assert.Equal("Attempt to parse address that is in error.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SuccessResponseParse()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load("ExampleXML" + System.IO.Path.DirectorySeparatorChar + "USPSAddressSuccess.xml");
|
||||
|
||||
XDocument response;
|
||||
|
||||
using (XmlNodeReader reader = new XmlNodeReader(doc))
|
||||
{
|
||||
response = XDocument.Load(reader);
|
||||
}
|
||||
|
||||
var parsedAddress = AddressParser.Parse(response.Root);
|
||||
|
||||
Assert.Equal("MADISON", parsedAddress.City);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddressValidationBuild()
|
||||
{
|
||||
UspsSettings settings = new UspsSettings();
|
||||
settings.Username = "TestUser";
|
||||
settings.EndpointUrl = "http://production.shippingapis.com/ShippingAPI?";
|
||||
AddressValidationRequestBuilder api = new AddressValidationRequestBuilder(settings, address);
|
||||
string expectedURI = "http://production.shippingapis.com/ShippingAPI?API=Verify&XML=%3cAddressValidateRequest+USERID%3d%22TestUser%22%3e%3cAddress%3e%3cAddress1%3eApt+2%3c%2fAddress1%3e%3cAddress2%3e109+N+Hancock+St%3c%2fAddress2%3e%3cCity%3eMadison%3c%2fCity%3e%3cState%3eWI%3c%2fState%3e%3cZip5%3e53703%3c%2fZip5%3e%3cZip4+%2f%3e%3c%2fAddress%3e%3c%2fAddressValidateRequest%3e";
|
||||
Assert.Equal(expectedURI, api.BuildGET());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<AddressValidateResponse>
|
||||
<Address>
|
||||
<Error>
|
||||
<Number>-2147219403</Number>
|
||||
<Source>clsAMS</Source>
|
||||
<Description>Multiple addresses were found for the information you entered, and no default exists.</Description>
|
||||
<HelpFile/>
|
||||
<HelpContext/>
|
||||
</Error>
|
||||
</Address>
|
||||
</AddressValidateResponse>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<AddressValidateResponse>
|
||||
<Address>
|
||||
<Address1>APT 2</Address1>
|
||||
<Address2>109 N HANCOCK ST</Address2>
|
||||
<City>MADISON</City>
|
||||
<State>WI</State>
|
||||
<Zip5>53703</Zip5>
|
||||
<Zip4>2466</Zip4>
|
||||
</Address>
|
||||
</AddressValidateResponse>
|
||||
@@ -0,0 +1,35 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
|
||||
<PackageReference Include="XmlUnit.Core" Version="2.11.1" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\USPS\USPS.csproj" />
|
||||
<ProjectReference Include="..\Landmark.OLA.Models\Landmark.OLA.Models.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="ExampleXML\USPSAddressError.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="ExampleXML\USPSAddressSuccess.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- additional settings used during the dotnet test execution step in the azure dev ops pipeline -->
|
||||
|
||||
<RunSettings>
|
||||
|
||||
<DataCollectionRunSettings>
|
||||
<DataCollectors>
|
||||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<Configuration>
|
||||
<CodeCoverage>
|
||||
|
||||
|
||||
<CompanyNames>
|
||||
<Exclude>
|
||||
<CompanyName>.*microsoft.*</CompanyName>
|
||||
</Exclude>
|
||||
</CompanyNames>
|
||||
|
||||
</CodeCoverage>
|
||||
</Configuration>
|
||||
</DataCollector>
|
||||
|
||||
</DataCollectors>
|
||||
</DataCollectionRunSettings>
|
||||
|
||||
</RunSettings>
|
||||
Reference in New Issue
Block a user