public void ShippingCosts_GetOne_When_WeightAtLowLimit() { IShippingCostLookupEntry rate = _serviceClient.GetOne("3", 1.00001m); Assert.IsNotNull(rate); Assert.IsTrue(rate.Cost == 2.25m); }
public void ShippingCosts_GetOne_When_WeightAtHighLimit() { IShippingCostLookupEntry rate = _serviceClient.GetOne("4", 1.50m); Assert.IsNotNull(rate); Assert.IsTrue(rate.Cost == 2m); }
public void ShippingCosts_GetAll_Should_Succeed() { IEnumerable <IShippingCostLookupEntry> rates = _serviceClient.GetAll(); Assert.IsNotNull(rates); IShippingCostLookupEntry rate = rates.FirstOrDefault(r => r.Zone == "4" && r.MaxWeight == 2m); Assert.IsTrue(rate.Cost == 3.25m); Assert.IsTrue(rates.Count() == 5); }
/// <summary> /// Does the computation once the Inputs object has been set. Validates the inputs. /// The exceptions thrown are handled by the by the method and are reflected in /// the value of the Status and ErrorMessage properties in the Results object. /// </summary> /// <exception cref="System.ArgumentOutOfRangeException"> /// zip;Zip code must be 5 digits /// or /// zip;Zone not available for specified zip code /// or /// weight;Weight must be greater than 0 and less than 100 lbs /// or /// weight;Shipping cost not available for the specified zone and weight /// </exception> private void DoCompute() { try { if (!Regex.IsMatch(Inputs.ZipCode, @"^\d{5}$")) { Results.Status = StatusType.InvalidZipCode; Results.ErrorMessage = String.Format("{0} is an invalid zipcode specification. Must be five digits.", Inputs.ZipCode); throw new ArgumentOutOfRangeException("zip", Inputs.ZipCode, "Zip code must be 5 digits"); } //determine the zone for the specified zone by calling the service _zipZone = _zoneLookupClient.GetOne(Inputs.ZipCode); if (_zipZone == null) { Results.Status = StatusType.ZoneUnknownForSpecifiedZipCode; Results.ErrorMessage = String.Format("The zone associated with zipcode {0} is not on file.", Inputs.ZipCode); throw new ArgumentOutOfRangeException("zip", Inputs.ZipCode, "Zone not available for specified zip code"); } Results.Zone = _zipZone.Zone; if (Inputs.Weight < 0.01m || Inputs.Weight > 99.99m) { Results.Status = StatusType.InvalidWeight; Results.ErrorMessage = String.Format("{0} is not a valid weight. The weight must be a positive number less than 100.", Inputs.Weight); throw new ArgumentOutOfRangeException("weight", Inputs.Weight, "Weight must be greater than 0 and less than 100 lbs"); } _costTier = _costLookupClient.GetOne(Results.Zone, Inputs.Weight); if (_costTier == null) { Results.Status = StatusType.CostUnknownForZipCodeAndWeight; Results.ErrorMessage = String.Format("Zipcode {0} is in zone {1}. There is no shipping cost information on file for a package weighing {2} lbs in that zone", Inputs.ZipCode, Results.Zone, Inputs.Weight); throw new ArgumentOutOfRangeException("weight", Inputs.Weight, "Shipping cost not available for the specified zone and weight"); } Results.Cost = _costTier.Cost; Results.Status = StatusType.Success; } catch (ArgumentOutOfRangeException ex) { if (Results.Status == StatusType.Unknown) { Results.Status = StatusType.UnknownError; Results.ErrorMessage = ex.Message; } } catch (Exception ex) { Results.Status = StatusType.UnknownError; Results.ErrorMessage = ex.Message; } }
public void ShippingCosts_GetOne_When_ZoneInvalid() { IShippingCostLookupEntry rate = _serviceClient.GetOne("AAAA", 1.5m); Assert.IsNull(rate); }
public void ShippingCosts_GetOne_When_ZoneValidAndWeightOutOfRange() { IShippingCostLookupEntry rate = _serviceClient.GetOne("4", 5m); Assert.IsNull(rate); }
public void ShippingCosts_GetOne_When_WeightZero_ShouldBe_Null() { IShippingCostLookupEntry rate = _serviceClient.GetOne("4", 0m); Assert.IsNull(rate); }
public void ShippingCosts_GetOne_When_WeightJustOverHighLimit() { IShippingCostLookupEntry rate = _serviceClient.GetOne("4", 2.001m); Assert.IsNull(rate); }
/// <summary> /// Does the computation once the Inputs object has been set. Validates the inputs. /// The exceptions thrown are handled by the by the method and are reflected in /// the value of the Status and ErrorMessage properties in the Results object. /// </summary> /// <exception cref="System.ArgumentOutOfRangeException"> /// zip;Zip code must be 5 digits /// or /// zip;Zone not available for specified zip code /// or /// weight;Weight must be greater than 0 and less than 100 lbs /// or /// weight;Shipping cost not available for the specified zone and weight /// </exception> private void DoCompute() { try { if (!Regex.IsMatch(Inputs.ZipCode, @"^\d{5}$")) { Results.Status = StatusType.InvalidZipCode; Results.ErrorMessage = String.Format("{0} is an invalid zipcode specification. Must be five digits.", Inputs.ZipCode); throw new ArgumentOutOfRangeException("zip", Inputs.ZipCode, "Zip code must be 5 digits"); } //determine the zone for the specified zone by calling the service _zipZone = _zoneLookupClient.GetOne(Inputs.ZipCode); if (_zipZone == null) { Results.Status = StatusType.ZoneUnknownForSpecifiedZipCode; Results.ErrorMessage = String.Format("The zone associated with zipcode {0} is not on file.", Inputs.ZipCode); throw new ArgumentOutOfRangeException("zip", Inputs.ZipCode, "Zone not available for specified zip code"); } Results.Zone = _zipZone.Zone; if (Inputs.Weight < 0.01m || Inputs.Weight > 99.99m ) { Results.Status = StatusType.InvalidWeight; Results.ErrorMessage = String.Format("{0} is not a valid weight. The weight must be a positive number less than 100.", Inputs.Weight); throw new ArgumentOutOfRangeException("weight", Inputs.Weight, "Weight must be greater than 0 and less than 100 lbs"); } _costTier = _costLookupClient.GetOne(Results.Zone, Inputs.Weight); if (_costTier == null) { Results.Status = StatusType.CostUnknownForZipCodeAndWeight; Results.ErrorMessage = String.Format("Zipcode {0} is in zone {1}. There is no shipping cost information on file for a package weighing {2} lbs in that zone",Inputs.ZipCode, Results.Zone, Inputs.Weight); throw new ArgumentOutOfRangeException("weight",Inputs.Weight, "Shipping cost not available for the specified zone and weight"); } Results.Cost = _costTier.Cost; Results.Status = StatusType.Success; } catch (ArgumentOutOfRangeException ex) { if (Results.Status == StatusType.Unknown) { Results.Status = StatusType.UnknownError; Results.ErrorMessage = ex.Message; } } catch (Exception ex) { Results.Status = StatusType.UnknownError; Results.ErrorMessage = ex.Message; } }