public AddressBLL(IAddressDAL addressDAL, AddressValidation addressValidation, IMapper mapper) : base(addressDAL) { _addressDAL = addressDAL; _addressValidation = addressValidation; _mapper = mapper; }
// Get Carrier Route private void button2_Click(object sender, EventArgs e) { List <string> userInput = new List <string>(); userInput.Clear(); // Get User Input string Street = textBox2.Text; string City = textBox1.Text; string State = textBox3.Text; string ZipCode = textBox4.Text; // Make list of User Input userInput.Add(Street); userInput.Add(City); userInput.Add(State); userInput.Add(ZipCode); // Create object for AddressValidation() and CarrierRoute() API_abstractHandler addValid = new AddressValidation(); API_abstractHandler carrRoute = new CarrierRoute(); addValid.SetNextObject(carrRoute); //create chain link carrRoute = new add_API_Name(carrRoute); //add decorator string output = ClientRequest.ClientInput(carrRoute, "carrierRoute", userInput); //get results of address validation + decorator textBox6.Text = string.Empty; //clear textbox textBox6.AppendText(output); //output to textbox }
public AddressValidation GeocodeAddress(Address address) { AddressValidation addressValidation = new AddressValidation() { AddressId = address.Id, IsValid = false, Condidates = new List<AddressValidationItem>() }; Country countryById = this.GetCountryById(address.Country.Id); State stateById = this.GetStateById(address.State.Id); City cityById = this.GetCityById(address.City.Id); LocationPoint locationPoint = AddressGeocoder.Geocode(countryById.Code, stateById.Code, cityById.Name, address.PostalCode, address.StreetAddress); addressValidation.IsValid = locationPoint != null; AddressValidationItem addressValidationItem = new AddressValidationItem() { AddressLine1 = address.StreetAddress, AddressLine2 = string.Format("{0} {1} {2} {3}", new object[] { cityById.Name, stateById.Code, address.PostalCode, countryById.Code }), CityId = cityById.Id, CountryId = countryById.Id, StateId = stateById.Id, Location = new Location() { Latitude = (addressValidation.IsValid ? locationPoint.Latitude : 0), Longitude = (addressValidation.IsValid ? locationPoint.Longitude : 0) }, PostalCode = address.PostalCode }; addressValidation.Condidates.Add(addressValidationItem); if (addressValidation.IsValid) { addressValidation.ValidAddress = addressValidation.Condidates.FirstOrDefault<AddressValidationItem>(); } return addressValidation; }
public ActionResult Create(Address address) { var validation = new AddressValidation(address); validation.Validate(); if (validation.HasError) { foreach (var errorDescription in validation.Errors) { ModelState.AddModelError(errorDescription.Field, errorDescription.Error); } } else { try { _addressService.Create(address); } catch (FieldValidationException error) { ModelState.AddModelError(error.Field, error.Error); } } if (ModelState.IsValid) { return(RedirectToAction("Index")); } return(View(address)); }
public static AnyType Create(string type) { // Design pattern :- Lazy loading != Eager loading if (ObjectsOfOurProjects == null) { ObjectsOfOurProjects = new UnityContainer(); //Lead IValidation <ICustomer> leadValidation = new PhoneValidation(new CustomerBasicValidation()); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("Lead", new InjectionConstructor(leadValidation, "Lead")); //SelfService IValidation <ICustomer> selfServiceValidation = new CustomerBasicValidation(); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("SelfService", new InjectionConstructor(selfServiceValidation, "SelfService")); //HomeDelivery IValidation <ICustomer> homeDeliveryValidation = new AddressValidation(new CustomerBasicValidation()); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("HomeDelivery", new InjectionConstructor(homeDeliveryValidation, "HomeDelivery")); //Customer IValidation <ICustomer> customerValidation = new AddressValidation(new BillDateValidation(new BillAmountValidation(new PhoneValidation(new CustomerBasicValidation())))); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("Customer", new InjectionConstructor(customerValidation, "Customer")); } // Design pattern :- RIP Replace If with Poly return(ObjectsOfOurProjects.Resolve <AnyType>(type)); }
public async Task MustCheckCountryValid(string country, bool result) { var model = new AddressValidation(); var address = new MF.Domain.Entities.Address("89600111", "rua geral", "Blumenau", "SC", country); var addressValidate = model.Validate(address).IsValid; addressValidate.Should().Be(result); }
public async Task MustCheckPostalCodeValid(string postalCode, bool result) { var model = new AddressValidation(); var address = new MF.Domain.Entities.Address(postalCode, "rua geral", "Blumenau", "SC", "BR"); var addressValidate = model.Validate(address).IsValid; addressValidate.Should().Be(result); }
public async Task MustCheckPostalCodeAdrressLineValid(string adrresLine, bool result) { var model = new AddressValidation(); var address = new MF.Domain.Entities.Address("89600111", adrresLine, "Blumenau", "SC", "BR"); var addressValidate = model.Validate(address).IsValid; addressValidate.Should().Be(result); }
public override bool IsValid() { ValidationResult = new AddPersonValidation().Validate(this); var addressValidationResult = new AddressValidation().Validate(this.Adress); ValidationResult.Errors.Concat(addressValidationResult.Errors); return(ValidationResult.IsValid && addressValidationResult.IsValid); }
public void TestGetGeopointBlank() { Mock <IGeopointManager> geoPointManagerMock = new Mock <IGeopointManager>(MockBehavior.Strict); AddressValidation addressValidation = new AddressValidation(geoPointManagerMock.Object); GeoPoint result = addressValidation.GetGeopoint(new Address()); geoPointManagerMock.Verify(a => a.GetGeopoint(It.IsAny <string>()), Times.Never); Assert.AreEqual(0, result.Latitude); Assert.AreEqual(0, result.Longitude); }
internal static AddressValidationVm MapToAddressValidationVm(this AddressValidation addressValidation) { AddressValidationVm result = new AddressValidationVm() { ValidationItems = new List <AddressValidationItemVm>(), SelectedValidationItem = 0, AddressId = addressValidation.AddressId, IsAddressValid = addressValidation.IsValid }; if (addressValidation.IsValid) { AddressValidationItemVm addressValidationItemVm = new AddressValidationItemVm() { AddressLine1 = addressValidation.ValidAddress.AddressLine1, AddressLine2 = addressValidation.ValidAddress.AddressLine2, CityId = addressValidation.ValidAddress.CityId, CountryId = addressValidation.ValidAddress.CountryId, Id = 0, Latitude = addressValidation.ValidAddress.Location.Latitude, Longitude = addressValidation.ValidAddress.Location.Longitude, PostalCode = addressValidation.ValidAddress.PostalCode, StateId = addressValidation.ValidAddress.StateId }; result.ValidationItems.Add(addressValidationItemVm); result.SelectedLatitude = addressValidation.ValidAddress.Location.Latitude; result.SelectedLongitude = addressValidation.ValidAddress.Location.Longitude; } else { for (int i = 0; i <= addressValidation.Condidates.Count - 1; i++) { AddressValidationItemVm addressValidationItemVm1 = new AddressValidationItemVm() { AddressLine1 = addressValidation.Condidates[i].AddressLine1, AddressLine2 = addressValidation.Condidates[i].AddressLine2, CityId = addressValidation.Condidates[i].CityId, CountryId = addressValidation.Condidates[i].CountryId, Id = i, Latitude = addressValidation.Condidates[i].Location.Latitude, Longitude = addressValidation.Condidates[i].Location.Longitude, PostalCode = addressValidation.Condidates[i].PostalCode, StateId = addressValidation.Condidates[i].StateId }; result.ValidationItems.Add(addressValidationItemVm1); } } return(result); }
public EmergencyBLL(IMapper mapper, IEmergencyDAL emergencyDAL, EmergencyValidation emergencyValidation, IPatientBLL patientBLL, IAddressBLL addressBLL, AddressValidation addressValidation, PatientValidation patientValidation, IEmergencyHistoryDAL emergencyHistoryDAL) : base(emergencyDAL) { _emergencyHistoryDAL = emergencyHistoryDAL; _addressValidation = addressValidation; _patientValidation = patientValidation; _addressBLL = addressBLL; _patientBLL = patientBLL; _mapper = mapper; _emergencyDAL = emergencyDAL; _emergencyValidation = emergencyValidation; }
public static ValidationResult ValidateAddress(List <string> roles, List <ParticipantRequest> participantRequests) { ValidationResult validationResult = new ValidationResult(); foreach (ParticipantRequest participantRequest in participantRequests) { if (roles.Contains(participantRequest.HearingRoleName)) { validationResult = new AddressValidation().Validate(participantRequest); if (!validationResult.IsValid) { return(validationResult); } } } return(validationResult); }
public void TestValidateState(string state, bool pass) { AddressValidation addressValidation = GetAddressValidation(); Address address = new Address() { State = state }; if (pass) { Valid(address, addressValidation.ValidateState); } else { Invalid(address, addressValidation.ValidateState); } }
public void TestAllVariableExistsScenario() { /* Error Suggestion: Unable to match: One or more of the values(suburb, postcode, state) invalid * 3). all variables exists in database => * Location:"AGNES WATER", PostCode:"4677", state:"QLD" */ try { AddressValidation val = new AddressValidation(); val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "AGNES WATER", "4677", "QLD", "sales_order"); Assert.AreEqual(true, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestScenarioWhenAllVariableMatchesIfStateIsStrippedFromLocation() { /* Error Suggestion: Unable to match: * 5). all variables matches with an entry in DB if varLocation is strip of state which is in parenthesis * Location:"AGNES BANKS (NSW)", PostCode: "2750", state: "" */ AddressValidation val = new AddressValidation(); try { val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "AGNES BANKS (NSW)", "2750", "", "sales_order"); Assert.AreEqual(true, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestValidateZipCode(string zip, bool pass) { AddressValidation addressValidation = GetAddressValidation(); Address address = new Address() { Zip = zip }; if (pass) { Valid(address, addressValidation.ValidateZipCode); } else { Invalid(address, addressValidation.ValidateZipCode); } }
public ActionResult ClaimPrizeStep2(AddressValidation av, int?selectedAddr) { if (selectedAddr.HasValue) { var dr = _uow.DrawingsService.Get(o => o.Id == av.DrawId.Value); if (dr == null) { throw new IchariException(string.Format("未找到相应的抽奖记录:drawId={0}", av.DrawId)); } dr.AddressId = selectedAddr.Value; _uow.Commit(); return(RedirectToAction("DrawDetail", "Account", new { id = dr.Id })); } if (ModelState.IsValid) { var usr = base.CurrentUser; if (_uow.UserInfoService.Get(o => o.Id == usr.Id && o.UserName == usr.UserName && o.Password == usr.Password) != null) { Address addr = new Address(); addr.UserId = usr.Id; addr.Address1 = av.Street; addr.Area = av.Area; addr.City = av.City; addr.Email = av.Email; addr.Mobile = av.Cell; addr.PostCode = av.Postal; addr.Province = av.Province; addr.Tel = av.Tel; addr.TrueName = av.Name; _uow.AddressService.Add(addr); _uow.Commit(); long drId = av.DrawId ?? 0; //long.Parse((string)Session[SessionKey.DrawId]); Drawings dr = _uow.DrawingsService.Get(o => o.Id == drId); dr.AddressId = addr.Id; dr.IsHandled = true; _uow.Commit(); return(RedirectToAction("DrawDetail", "Account", new { id = dr.Id })); } } return(View()); }
public void TestScenarioWhenAllVariableMatchesIfFirst5CharactersOfDB_LocationIsConsidered() { /* Error Suggestion: Unable to match: Invalid suburb value * 10). first 5 characters and post matches => * Location:"ASCOTabcd", PostCode:"3032", State:"VIC" */ AddressValidation val = new AddressValidation(); try { val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "ASCOT", "3032", "VIC", "sales_order"); //more than 1 value if we consider first 5 characters and match postcode and state Assert.AreEqual(false, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestAllVariableMatcheswithDB_LocationStrippedParenthesisPartScenario() { /* Error Suggestion: Unable to match: * 4). all variables matches with a entry in DB if db.location is strip of the parenthesis part * Location:"AGNES BANKS", PostCode:"2750", state:"NSW" */ AddressValidation val = new AddressValidation(); try { val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "AGNES BANKS", "2750", "NSW", "sales_order"); Assert.AreEqual(true, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestAllEmptyVariableScenario() { /* * 2). all variables are empty => * Location:"", PostCode:"", state:"" */ try { //throw new Exception("Testing Logger"); AddressValidation val = new AddressValidation(); val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "", "", "", "sales_order"); Assert.AreEqual(false, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestScenarioWhenLocationPostCodeMatchesStateMissingIfDb_LocationStrippedOfParenthesisPart() { /*Error Suggestion: Unable to match: Invalid state value * 8). location and postcode matches and state is missing and if DB.Location stripped out of parenthesis part * Location:"ASCOT", PostCode:"3551", state:"" */ AddressValidation val = new AddressValidation(); try { val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "ASCOT", "3551", "", "sales_order"); Assert.AreEqual(true, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestScenarioAllVariablesMatchesWhenDB_Location_ParenthesisPartStripped() { /*Error Suggestion: Unable to match: Invalid suburb value * 7). all variables matches if parenthesis part is stripped from DB.Location * Location:"ASCOT", PostCode:"4359", state:"QLD" */ AddressValidation val = new AddressValidation(); try { val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "ASCOT", "4359", "QLD", "sales_order"); Assert.AreEqual(true, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestInternationalCodeScenario() { /* * Testcase Scenarios: * 1). International Post Codes => * Location:"", PostCode:"9999", state:"" */ try { AddressValidation val = new AddressValidation(); val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "9999", "", "", "sales_order"); Assert.AreEqual(true, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
public void TestScenarioWhenLocationStateMatchesPostCodeEitherEmptyNotExistInDBIfLocationStrippedOutOfParenthesisPart() { /* Error Suggestion: Unable to match: Invalid postcode value * 9). location and state matches but postcode does not match and location matches only after stripping parenthesis part * Location & State matches => * Location:"ASCOT", PostCode:"1111", State:"VIC" */ AddressValidation val = new AddressValidation(); try { val.setupAddressValidator("OUP", "W3", "01", "0080000504", "20180503", "ASCOT", "1111", "VIC", "sales_order"); //because there are more than 1 value of ascot under state victoria Assert.AreEqual(false, val.ValidateAddressFields()); } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
/* the event for verify button click that show the result of the address validity */ private void verifyButton_Click(object sender, EventArgs e) { // set wait cursor Cursor.Current = Cursors.WaitCursor; bool flag = true; switch (CHANNEL) { case "Sears": flag = AddressValidation.Validate(searsValues.ShipTo); break; case "Shop.ca": flag = AddressValidation.Validate(shopCaValues.ShipTo); break; case "Giant Tiger": flag = AddressValidation.Validate(giantTigerValues.ShipTo); break; } if (flag) { verifyTextbox.Text = "Address Verified"; verifyTextbox.ForeColor = Color.FromArgb(100, 168, 17); } else { verifyTextbox.Text = "Address Not Valid"; verifyTextbox.ForeColor = Color.FromArgb(254, 126, 116); } verifyTextbox.Visible = true; // set default cursor after complete Cursor.Current = Cursors.Default; }
public void Address_Validate_isValid() { // Arrange var expectedIsValid = true; var address = new AddressViewModel() { CustomerID = Guid.NewGuid(), AddressID = Guid.NewGuid(), City = "São Paulo", Country = "Brasil", Number = 14, State = "São Paulo", Street = "Rua Fulano de Tal", Zipcode = "1111111" }; // Act var addressValidation = new AddressValidation(); var validationResult = addressValidation.Validate(address); // Assert Assert.Equal(expectedIsValid, validationResult.IsValid); }
public void Address_Validate_isNotValid() { // Arrange var expectedIsValid = false; var address = new AddressViewModel() { CustomerID = Guid.Empty, AddressID = Guid.Empty, City = "São", Country = "Br", Number = 1, State = "São", Street = "Rua", Zipcode = "1111111" }; // Act var addressValidation = new AddressValidation(); var validationResult = addressValidation.Validate(address); // Assert Assert.Equal(expectedIsValid, validationResult.IsValid); }
public void TestGetGeopoint() { Mock <IGeopointManager> geoPointManagerMock = new Mock <IGeopointManager>(MockBehavior.Strict); geoPointManagerMock.Setup(a => a.GetGeopoint(It.IsAny <string>())).Returns(new MapPoint() { Longitude = 10, Latitude = 10 }); AddressValidation addressValidation = new AddressValidation(geoPointManagerMock.Object); GeoPoint result = addressValidation.GetGeopoint(new Address() { Street = "here", City = "there", State = States.AK.ToString(), Zip = "12345" }); geoPointManagerMock.Verify(a => a.GetGeopoint(It.IsAny <string>()), Times.Once); Assert.IsNotNull(result.Latitude); Assert.IsNotNull(result.Longitude); }
public AddressService(IAddress repository, AddressValidation validation) { _repository = repository; _validation = validation; }