コード例 #1
0
        public AddrValidationResponseModel ValidateAddress(string addr1, string addr2, string city, string state, string zip, string country)
        {
            AddrValidationResponseModel avrModel = null;

            AddressModel addr = new AddressModel(addr1, addr2, city, state, zip, country);

            try
            {
                _log.Info("ASA.Web.Services.AddrValidationService.ValidateAddress() starting ...");

                if (addr != null && addr.IsValid() && (Config.QasOn == true))
                {
                    // only send US addrs to QAS
                    if (addr.CountryID.ToUpper() == "USA" || addr.CountryID.ToUpper() == "US" || addr.CountryID.ToUpper() == "UNITED STATES")
                    {
                        avrModel = _addressValidation.ValidateAddress(addr);
                    }
                    else //dont send foreign addrs to QAS.
                    {
                        //avrModel = new AddrValidationResponseModel(QasProWeb.VerifyLevelType.None);
                        avrModel = new AddrValidationResponseModel();
                        ErrorModel error = new ErrorModel("Foreign addresses are not validated by QAS.", "Web AddressValidation Service");
                        avrModel.ErrorList.Add(error);
                        _log.Info("Foreign addresses are not validated by QAS.");
                    }
                }
                else
                {
                    avrModel = new AddrValidationResponseModel();
                    ErrorModel error = new ErrorModel("Invalid search criteria", "Web AddressValidation Service");
                    if (Config.QasOn != true)
                    {
                        error = new ErrorModel("Qas is configured to bypass address validation.", "Web AddressValidation Service");
                    }
                    avrModel.ErrorList.Add(error);
                    _log.Info("ASA.Web.Services.AddrValidationService.ValidateAddress(): Invalid search criteria or QAS is currently disabled.");
                }

                _log.Info("ASA.Web.Services.AddrValidationService.ValidateAddress() ending ...");
            }
            catch (Exception ex)
            {
                avrModel = new AddrValidationResponseModel();
                ErrorModel error = new ErrorModel(ex.ToString(), "Web AddressValidation Service");
                avrModel.ErrorList.Add(error);
                _log.Error("ASA.Web.Services.AddrValidationService.ValidateAddress(): Exception => " + ex.ToString());
            }

            return(avrModel);
        }
コード例 #2
0
        public void ValidateAddress_Should_NotReturnErrors()
        {
            // Arrange
            var model = new AddressModel()
            {
                Street       = "Test one",
                StreetNumber = 123
            };

            // Act
            var result = model.IsValid();

            // Assert
            Assert.True(result);
        }
コード例 #3
0
        public void ValidateAddress_Should_ValidateIfThereIsCountryOrStateFilled(string country, string state)
        {
            // Arrange
            var model = new AddressModel()
            {
                Street       = "some street",
                StreetNumber = 123
            };

            // Act
            var result = model.IsValid();

            // Assert
            Assert.False(result);
        }