public void CalculateResultDataTest(double topleft, double topRight, double botLeft, bool isDirectProp, double expectedResult) { PropCalculator c = new PropCalculator(); PropDataValidator vali = new PropDataValidator(); PropData data = new PropData(); data.TopLeft = topleft; data.TopRight = topRight; data.BottomLeft = botLeft; data.IsDirectProp = isDirectProp; try { c.CalculateResult(data, vali); // compare the results Assert.Equal(expectedResult, data.BottomRight); } catch (PropException) { Assert.True(false, "Exception was thrown but must not!!"); return; } catch (Exception e) { Assert.True(false, "Wrong Exception was thrown!!" + e.Message); return; } }
public void ValidateDataNullData() { PropDataValidator v = new PropDataValidator(); ErrorCodes err = v.ValidateData(null); Assert.Equal(ErrorCodes.NO_DATA_GIVEN, err); }
public void CalculateResult(PropData data, PropDataValidator validator) { if (data == null) { throw new PropException.PropException(ErrorCodes.NO_DATA_GIVEN); } if (validator == null) { throw new PropException.PropException(ErrorCodes.NO_VALIDATOR_GIVEN); } ErrorCodes valid = validator.ValidateData(data); if (!valid.Equals(ErrorCodes.OK)) { throw new PropException.PropException(valid); } // Calculate now the result if (data.IsDirectProp) { data.BottomRight = data.TopRight / data.TopLeft * data.BottomLeft; } else { data.BottomRight = data.TopRight / data.BottomLeft * data.TopLeft; } }
public void ValidateData(bool isDirectProp, double topleft, double botleft, ErrorCodes expectedResult) { PropData data = new PropData(); data.TopLeft = topleft; data.BottomLeft = botleft; data.IsDirectProp = isDirectProp; PropDataValidator v = new PropDataValidator(); ErrorCodes err = v.ValidateData(data); Assert.Equal(expectedResult, err); }
public void CalculateResultNullDataTest() { PropCalculator c = new PropCalculator(); PropDataValidator vali = new PropDataValidator(); try { c.CalculateResult(null, vali); } catch (PropException e) { Assert.Equal(ErrorCodes.NO_DATA_GIVEN, e.Error); return; } catch (Exception) { Assert.True(false, "Wrong Exception was thrown!!"); return; } Assert.True(false, "No Exception was thrown!!"); }
protected void OnCalcBtnClick(object sender, EventArgs e) { // Collect the Data from View BottomLeftLbl.Text = ""; resultLbl.Text = ""; PropData data = new PropData(); try { data.TopLeft = Convert.ToDouble(TopLeftTxf.Text); data.TopRight = Convert.ToDouble(TopRightTxf.Text); data.BottomLeft = Convert.ToDouble(BottomLeftTxf.Text); data.IsDirectProp = IsdirectPropCbx.Active; PropDataValidator vali = new PropDataValidator(); PropCalculator calculator = new PropCalculator(); calculator.CalculateResult(data, vali); // write back the results to the view BottomLeftLbl.Text = data.BottomLeft.ToString(); resultLbl.Text = data.BottomRight.ToString(); } catch (PropException pe) { resultLbl.Text = "A problem occurred. ErrorCode:" + pe.Error; } catch (Exception ex) { resultLbl.Text = "Invalid Data provided." + ex.Message; } // Caclulate the Data // Write results }