Skip to content

Commit

Permalink
automerge
Browse files Browse the repository at this point in the history
  • Loading branch information
sumo300 committed Dec 10, 2013
2 parents 1184b10 + fec950f commit 13e58e0
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 48 deletions.
4 changes: 2 additions & 2 deletions SeeSharpShip.Tests/Properties/AssemblyInfo.cs
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.6.0")]
[assembly: AssemblyFileVersion("0.1.6.0")]
[assembly: AssemblyVersion("0.1.7.0")]
[assembly: AssemblyFileVersion("0.1.7.0")]
32 changes: 29 additions & 3 deletions SeeSharpShip.Tests/Usps/RateServiceTests.cs
@@ -1,4 +1,4 @@
#region SeeSharpShip.Tests is Copyright (C) 2011-2011 Michael J. Sumerano.
#region SeeSharpShip.Tests is Copyright (C) 2011-2013 Michael J. Sumerano.

// This file is part of SeeSharpShip.Tests.
//
Expand Down Expand Up @@ -80,6 +80,18 @@ public class RateServiceTests {
Assert.That(response.Count, Is.GreaterThan(0));
}

/// <summary>
/// Tests fix for defect #7 introduced by USPS API changes
/// </summary>
[Test]
[Category("Domestic")]
[Explicit("Integration test that hits the real API")]
public void DomesticServices_ValidCredentials_ReturnsListOfServicesContainingEncodedTrademark() {
List<ServiceInfo> response = _rateService.DomesticServices(_userId, _password, _sourceZipCode).ToList();
bool containsEncodedTrademark = response.Any(r => r.FullName.Contains("<sup>™</sup>"));
Assert.That(containsEncodedTrademark, Is.Not.True);
}

[Test]
[Category("Domestic")]
[Explicit("Integration test that hits the real API")]
Expand Down Expand Up @@ -116,7 +128,9 @@ public class RateServiceTests {
[Test]
[Category("Domestic")]
[Explicit("Integration test that hits the real API")]
public void Get_DomesticWithZipCodeNull_ThrowsNullReferenceException() { Assert.Throws(typeof (NullReferenceException), () => _rateService.Get(RateServiceTestsData.GetDomesticRequestWithZipDestinationNull())); }
public void Get_DomesticWithZipCodeNull_ThrowsNullReferenceException() {
Assert.Throws(typeof (NullReferenceException), () => _rateService.Get(RateServiceTestsData.GetDomesticRequestWithZipDestinationNull()));
}

[Test]
[Category("International")]
Expand Down Expand Up @@ -178,5 +192,17 @@ public class RateServiceTests {
List<ServiceInfo> response = _rateService.InternationalServices(_userId, _password, _sourceZipCode).ToList();
Assert.That(response.Count, Is.GreaterThan(0));
}

/// <summary>
/// Tests fix for defect #7 introduced by USPS API changes
/// </summary>
[Test]
[Category("International")]
[Explicit("Integration test that hits the real API")]
public void InternationalServices_ValidCredentials_ReturnsListOfServicesContainingEncodedTrademark() {
List<ServiceInfo> response = _rateService.InternationalServices(_userId, _password, _sourceZipCode).ToList();
bool containsEncodedTrademark = response.Any(r => r.FullName.Contains("<sup>™</sup>"));
Assert.That(containsEncodedTrademark, Is.Not.True);
}
}
}
}
4 changes: 2 additions & 2 deletions SeeSharpShip/Properties/AssemblyInfo.cs
Expand Up @@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.6.0")]
[assembly: AssemblyFileVersion("0.1.6.0")]
[assembly: AssemblyVersion("0.1.7.0")]
[assembly: AssemblyFileVersion("0.1.7.0")]
8 changes: 7 additions & 1 deletion SeeSharpShip/SeeSharpShip.csproj
Expand Up @@ -108,7 +108,13 @@
<None Include="Docs\USPS-Rate-Calculators-v1-5.pdf" />
<None Include="Docs\USPS-Track-Confirm-v4-1a.pdf" />
<None Include="license.txt" />
<None Include="SeeSharpShip.nuspec" />
<None Include="SeeSharpShip.nuspec">
<SubType>Designer</SubType>
</None>
<None Include="Service References\FedExRateService\RateServiceDefinitions.wsdl" />
<None Include="Service References\FedExRateService\SeeSharpShip.FedExRateService.RateReply.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</None>
<None Include="Service References\UpsFreightRateService\common.xsd">
<SubType>Designer</SubType>
</None>
Expand Down
84 changes: 44 additions & 40 deletions SeeSharpShip/Services/Usps/RateService.cs
@@ -1,4 +1,4 @@
#region SeeSharpShip is Copyright (C) 2011-2011 Michael J. Sumerano.
#region SeeSharpShip is Copyright (C) 2011-2013 Michael J. Sumerano.

// This file is part of SeeSharpShip.
//
Expand All @@ -20,7 +20,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SeeSharpShip.Extensions;
using SeeSharpShip.Models.Usps;
using SeeSharpShip.Models.Usps.Domestic;
Expand All @@ -34,10 +33,11 @@ public class RateService : IRateService {
private readonly string _apiUrl;
private readonly IRequest _request;

// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Global
[Obsolete("Remove this constructor once an IoC container is implemented. Consider what to do about API url as well.")]
public RateService() : this("http://production.shippingapis.com/ShippingAPI.dll", new PostRequest()) { }
// ReSharper restore UnusedMember.Global
public RateService() : this("http://production.shippingapis.com/ShippingAPI.dll", new PostRequest()) {}

// ReSharper restore UnusedMember.Global

public RateService(string apiUrl, IRequest request) {
if (string.IsNullOrWhiteSpace(apiUrl)) {
Expand Down Expand Up @@ -68,18 +68,18 @@ public class RateService : IRateService {

public IEnumerable<ServiceInfo> DomesticServices(string userId, string password, string zip) {
var request = new RateV4Request {
UserId = userId,
Password = password,
Packages = new List<DomesticPackage> {
new DomesticPackage {
Id = "1",
SelectedServiceType = ServiceTypes.All,
Pounds = 1,
ZipOrigination = zip,
ZipDestination = zip,
}
}
};
UserId = userId,
Password = password,
Packages = new List<DomesticPackage> {
new DomesticPackage {
Id = "1",
SelectedServiceType = ServiceTypes.All,
Pounds = 1,
ZipOrigination = zip,
ZipDestination = zip,
}
}
};

string response = DoRequest(request);

Expand All @@ -89,28 +89,26 @@ public class RateService : IRateService {

var rateResponse = response.ToObject<RateV4Response>();
return (rateResponse.Packages.SelectMany(package => package.Postages, (package, postage) => new ServiceInfo {
Id = postage.ClassId,
FullName =
HttpUtility.HtmlDecode(
postage.MailService),
})).Distinct();
Id = postage.ClassId,
FullName = postage.MailService,
})).Distinct();
}

public IEnumerable<ServiceInfo> InternationalServices(string userId, string password, string zip) {
var request = new IntlRateV2Request {
UserId = userId,
Password = password,
Packages = new List<InternationalPackage> {
new InternationalPackage {
Id = "1",
SelectedMailType = MailType.All,
Pounds = 1,
OriginZip = zip,
Country = "CANADA",
ValueOfContents = "1.00",
}
}
};
UserId = userId,
Password = password,
Packages = new List<InternationalPackage> {
new InternationalPackage {
Id = "1",
SelectedMailType = MailType.All,
Pounds = 1,
OriginZip = zip,
Country = "CANADA",
ValueOfContents = "1.00",
}
}
};

string response = DoRequest(request);

Expand All @@ -121,15 +119,21 @@ public class RateService : IRateService {
var rateResponse = response.ToObject<IntlRateV2Response>();
return (from package in rateResponse.Packages
from service in package.Services
select new ServiceInfo {Id = service.Id, FullName = HttpUtility.HtmlDecode(service.SvcDescription)}).Distinct();
select new ServiceInfo {Id = service.Id, FullName = service.SvcDescription}).Distinct();
}

#endregion

private static bool HasError(string response) { return response.IndexOf("<Error>", StringComparison.InvariantCultureIgnoreCase) != -1; }
private static bool HasError(string response) {
return response.IndexOf("<Error>", StringComparison.InvariantCultureIgnoreCase) != -1;
}

private string DoRequest(IntlRateV2Request request) { return _request.GetResponse(_apiUrl, string.Format("API=IntlRateV2&XML={0}", request.ToXmlString())); }
private string DoRequest(IntlRateV2Request request) {
return _request.GetResponse(_apiUrl, string.Format("API=IntlRateV2&XML={0}", request.ToXmlString()));
}

private string DoRequest(RateV4Request request) { return _request.GetResponse(_apiUrl, string.Format("API=RateV4&XML={0}", request.ToXmlString())); }
private string DoRequest(RateV4Request request) {
return _request.GetResponse(_apiUrl, string.Format("API=RateV4&XML={0}", request.ToXmlString()));
}
}
}
}

0 comments on commit 13e58e0

Please sign in to comment.