Exemplo n.º 1
0
        public void ShippingZones_GetOne_When_OKExpected()
        {
            IShippingZoneLookupEntry zone = _serviceClient.GetOne("55556");

            Assert.IsNotNull(zone);
            Assert.IsTrue(zone.Zone == "3");
        }
Exemplo n.º 2
0
        public void ShippingZones_GetAll_Should_Succeed()
        {
            IEnumerable <IShippingZoneLookupEntry> zones = _serviceClient.GetAll();

            Assert.IsNotNull(zones);
            IShippingZoneLookupEntry zone = zones.FirstOrDefault(z => z.Zip == "55555");

            Assert.IsTrue(zone.Zone == "4");
        }
Exemplo n.º 3
0
        /// <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;
            }
        }
Exemplo n.º 4
0
        /// <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;
            }
        }
Exemplo n.º 5
0
        public void ShippingZones_GetOne_When_NotFoundExpected()
        {
            IShippingZoneLookupEntry zone = _serviceClient.GetOne("AAAA");

            Assert.IsNull(zone);
        }