public JsonResult CalculateOhmValue() { string band1 = Request.Form["band1Color"]; string band2 = Request.Form["band2Color"]; string band3 = Request.Form["band3Color"]; string band4 = Request.Form["toleranceBandColor"]; CalculateOhmValueUseCaseRequest request = new CalculateOhmValueUseCaseRequest(); request.bandAColor = band1; request.bandBColor = band2; request.bandCColor = band3; request.toleranceBandColor = band4; CalculateOhmValueUseCase useCase = new CalculateOhmValueUseCase(); CalculateOhmValueUseCaseResponse response = useCase.Execute(request); return(Json(new { success = response.success, message = response.message, result = response.calculatedValue, tolerance = response.toleranceValue, }, JsonRequestBehavior.AllowGet )); }
public void CalculateOhmValueUseCase_ExecuteTest_WithInvalidInputs_BandGap_ProducesFailureResponseWithAccurateDescriptiveMessage() { CalculateOhmValueUseCaseRequest request = new CalculateOhmValueUseCaseRequest(); CalculateOhmValueUseCase calculateUseCase = new CalculateOhmValueUseCase(); CalculateOhmValueUseCaseResponse response; // set up request request.bandAColor = "red"; request.bandBColor = ""; request.bandCColor = "blue"; request.toleranceBandColor = "gold"; // execute use case response = calculateUseCase.Execute(request); // assert response matching expectations for requested scenario Assert.IsFalse(response.success); Assert.IsNotNull(response.message); Assert.AreEqual("Can not specify third band without a second", response.message); }
public void CalculateOhmValueUseCase_ExecuteTest_WithInvalidInputs_InvalidToleranceBand_ProducesFailureResponseWithAccurateDescriptiveMessage() { CalculateOhmValueUseCaseRequest request = new CalculateOhmValueUseCaseRequest(); CalculateOhmValueUseCase calculateUseCase = new CalculateOhmValueUseCase(); CalculateOhmValueUseCaseResponse response; // set up request request.bandAColor = "brown"; request.bandBColor = "red"; request.bandCColor = "blue"; request.toleranceBandColor = "wisteria"; // execute use case response = calculateUseCase.Execute(request); // assert response matching expectations for requested scenario Assert.IsFalse(response.success); Assert.IsNotNull(response.message); Assert.AreEqual("Tolerance band color is invalid. Cannot be wisteria.", response.message); }
public void CalculateOhmValueUseCase_ExecuteTest_WithValidInputs_ProducesSuccessResponseWithAccurateResults() { CalculateOhmValueUseCaseRequest request = new CalculateOhmValueUseCaseRequest(); CalculateOhmValueUseCase calculateUseCase = new CalculateOhmValueUseCase(); CalculateOhmValueUseCaseResponse response; // set up request request.bandAColor = "red"; // execute use case response = calculateUseCase.Execute(request); // assert response matching expectations for requested scenario Assert.IsTrue(response.success); Assert.IsNotNull(response.calculatedValue); Assert.IsNotNull(response.toleranceValue); Assert.AreNotEqual(0, response.calculatedValue); Assert.AreNotEqual(0, response.toleranceValue); Assert.IsNull(response.message); }
public void CalculateOhmValueUseCase_ExecuteTest_WithInvalidInputs_ProducesFailureResponseWithMessage() { CalculateOhmValueUseCaseRequest request = new CalculateOhmValueUseCaseRequest(); CalculateOhmValueUseCase calculateUseCase = new CalculateOhmValueUseCase(); CalculateOhmValueUseCaseResponse response; // set up request request.bandAColor = "red"; request.bandBColor = ""; request.bandCColor = "blue"; request.toleranceBandColor = "gold"; // execute use case response = calculateUseCase.Execute(request); // assert response matching expectations for requested scenario Assert.IsFalse(response.success); Assert.IsNotNull(response.calculatedValue); Assert.IsNotNull(response.toleranceValue); Assert.AreEqual(0, response.calculatedValue); Assert.AreEqual(0, response.toleranceValue); Assert.IsNotNull(response.message); }