/// <summary> /// initialises an instance of the <see cref="PostcodesClientWrapper"/> /// using the principle of poor man's DI /// </summary> /// <param name="theClient">the client</param> public PostcodesClientWrapper(IPostcodesIOClient theClient) { It.IsNull(theClient) .AsGuard <ArgumentNullException>(nameof(theClient)); Client = theClient; }
public async Task <IActionResult> SetAddress([FromServices] IPostcodesIOClient postcodesIoClient, AddressModel addressModel) { bool validPostcode = await postcodesIoClient.ValidateAsync(addressModel.Postcode); if (!string.IsNullOrWhiteSpace(addressModel.Address1)) { TempData[AddressTag] = addressModel.Address1; } if (!string.IsNullOrWhiteSpace(addressModel.Address2)) { TempData[Address2Tag] = addressModel.Address2; } if (!string.IsNullOrWhiteSpace(addressModel.Town)) { TempData[Town] = addressModel.Town; } if (!string.IsNullOrWhiteSpace(addressModel.County)) { TempData[County] = addressModel.County; } if (!string.IsNullOrWhiteSpace(addressModel.Postcode)) { if (validPostcode) { TempData[Postcode] = addressModel.Postcode; } else { ModelState.AddModelError("Postcode", "Enter a valid postcode or leave this space blank."); } } if (ModelState.IsValid) { return(RedirectToAction(LightingLevelTag)); } else { return(RedirectToAction(AddressTag)); } }
/// <summary> /// make a 'system under test' /// </summary> /// <returns>a system under test</returns> internal PostcodesClientWrapper MakeSUT(IPostcodesIOClient client) => new PostcodesClientWrapper(client);
public PostcodeLookupService() { _postcoder = new PostcodesIOClient(); }