public async Task <ResistorOhmResponse> GetOhmValue(ResistorOhmRequest request) { ResistorOhmResponse ohmResponse; try { if (request == null) { return(new ResistorOhmResponse() { Success = false, Error = "Bad Request" }); } ohmResponse = await _DataAccess.GetResistorOhmValue(request); } catch { ohmResponse = new ResistorOhmResponse() { Success = false, Error = "Service Error" }; } return(ohmResponse); }
// GET: Resistor public async Task <ActionResult> Index(ResistorViewModel viewModel) { ResistorOhmRequest request; ResistorOhmResponse respone; if (viewModel.btnResistorOhm != null) { request = new ResistorOhmRequest() { bandAColor = viewModel.bandAColor, bandBColor = viewModel.bandBColor, bandCColor = viewModel.bandCColor }; var model = new ResistorModel(_DataAccess); respone = await model.GetOhmValue(request); if (respone.Success) { viewModel.Ohm = respone.Ohm.ToString(); } else { ViewBag.Error = respone.Error; } } return(View(viewModel)); }
public async Task <ResistorOhmResponse> GetResistorOhmValue(ResistorOhmRequest request) { ResistorOhmResponse response = new ResistorOhmResponse(); switch (request.testScenario) { case TestScenarioEnum.validateBlackBlackBlack: response = new ResistorOhmResponse() { Ohm = 0, Success = true }; break; case TestScenarioEnum.validateRedOrangeBlack: response = new ResistorOhmResponse() { Ohm = 230, Success = true }; break; default: break; } return(response); }
public void TestRedOrangeBlack() { _Request = new ResistorOhmRequest() { testScenario = TestScenarioEnum.validateRedOrangeBlack }; var response = _Model.GetOhmValue(_Request).Result; Assert.True(response != null && response.Success == true); Assert.True(response.Ohm == 230); }
public async Task <ResistorOhmResponse> GetResistorOhmValue(ResistorOhmRequest request) { ResistorOhmResponse ohmResponse; var response = await _Client.GetAsync("/OhmCalculator/Ohmvalue?bandAColor=" + request.bandAColor.GetHashCode() + "&bandBColor=" + request.bandBColor.GetHashCode() + "&bandCColor=" + request.bandCColor.GetHashCode()); if (response.IsSuccessStatusCode) { var strResponse = await response.Content.ReadAsStringAsync(); ohmResponse = JsonConvert.DeserializeObject <ResistorOhmResponse>(strResponse); ohmResponse.Success = true; } else { ohmResponse = new ResistorOhmResponse() { Success = false, Error = "Service Error" }; } return(ohmResponse); }