Beispiel #1
0
        public void CanGetUspsServiceCodes()
        {
            var provider     = new USPSProvider();
            var serviceCodes = provider.GetServiceCodes();

            Assert.NotNull(serviceCodes);
            Assert.NotEmpty(serviceCodes);
        }
        public void TestReplaceUnsafeCharacters()
        {
            USPSProvider provider = new USPSProvider();
            string       xml      = @"a;a/a?a:a@a=a&a<a>a#a%a{a}a|a\a^a~a[a]a`";

            string clean = provider.ReplaceUnsafeCharacters(xml);

            Assert.AreEqual("a a a a a a a a a a a a a a a a a a a a ", clean);
        }
 public UspsSetting GetSetting(int providerId, AspxCommonInfo commonInfo)
 {
     try
     {
         return(USPSProvider.GetSetting(providerId, commonInfo));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        static void Main(string[] args)
        {
            ILogger mLogger = LogManager.GetCurrentClassLogger();

            mLogger.Info("Starting address validation...");

            IProvider provider = new USPSProvider();

            using (UserAddressEntities addressContext = new UserAddressEntities())
            {
                using (AddressValidationEntities reportingContext = new AddressValidationEntities())
                {
                    var query = addressContext.UserAddresses.Where(x => x.EnterpriseID == 8);
                    foreach (var address in query)
                    {
                        try
                        {
                            var response = provider.Validate(address);
                            if (response == null)
                            {
                                mLogger.Error("An error occurred trying to validate address {0}. Response was null.", address.UserAddressID);
                            }
                            else
                            {
                                if (response.Error != null)
                                {
                                    mLogger.Info("Address {0} failed USPS validation. USPS Error Description: {1}", address.UserAddressID, response.Error.Description);
                                    mLogger.Info(address.ToString());
                                }
                                else
                                {
                                    mLogger.Debug("Address passed USPS validation, cleansed address below:");
                                    mLogger.Debug(response.CleansedAddress.ToString());
                                }
                                reportingContext.AddressValidations.Add(CreateReportRecord(address, response));
                                reportingContext.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            mLogger.Error(ex, "Caught exception validating address {0}.", address.UserAddressID);
                        }
                    }
                }
            }
            mLogger.Info("Ending address validation.");
            // Console.Read();
        }