public void specify_Measurement_can_receive_a_new_date() { DataTable tbl = new DataTable(); tbl.Columns.Add("date", typeof(String)); tbl.Columns.Add("remark", typeof(String)); tbl.Rows.Add("12-12-2012", "a date in past"); tbl.Rows.Add("10-10-2012", "another date in past"); Variables vars = new Variables(); foreach (DataRow row in tbl.Rows) { vars.resetParameters(); context["Given an existing measurement"] = () => { anExistingMeasurement(vars); it["OK"] = () => nop(); }; context["When I change the date to " + row["date"] + " which is " + row["remark"]] = () => { IChangeTheDateToWhichIsRemark((String)row["date"], vars); it["OK"] = () => nop(); it["The date is the current date"] = () => theDateIs(vars); }; } }
private void anExistingMeasurementWithDate(string date, Variables vars) { vars.measurement = new Measurement(_LENGTH, _WEIGHT, DateTime.Parse(date)); }
private void theNumber0IsReturned(Variables vars) { ((int)vars.result).should_be(0); }
private void anExistingMeasurementWithLengthAndWeightAndDate(int length, int weight, String date, Variables vars) { vars.measurement = new Measurement(length, weight, DateTime.Parse(date)); }
private void aPositiveNumberIsReturned(Variables vars) { ((int)vars.result).should_be_greater_than(0); }
private void IChangeTheDateToWhichIsRemark(String date, Variables vars) { try { vars.date = DateTime.Parse(date); vars.measurement.date = vars.date; } catch (Exception ex) { vars.ex = ex; } }
private void ICheckIfTheseMeasurementsAreEqualToEachOther(Variables vars) { vars.result = vars.measurement.@equals(vars.otherMeasurement); }
private void theBmiIs(Variables vars) { vars.measurement.getBMI().should_be(vars.BMI); }
private void TheLengthIsAndTheWeight(int length, int weight, Variables vars) { vars.measurement.length = length; vars.measurement.weight = weight; }
public void specify_One_measurement_is_equal_than_another_measurement_if_the_dates_of_both_measurements_are_the_same() { Variables vars = new Variables(); vars.resetParameters(); context["Given an existing measurement with date 10-10-2012"] = () => { anExistingMeasurementWithDate("10-10-2012", vars); it["OK"] = () => nop(); context["And another existing measurement with date 10-10-2012"] = () => { anotherExistingMeasurementWithDate("10-10-2012", vars); it["OK"] = () => nop(); }; }; context["When I compare the measurement with date 10-10-2012 with the measurement with date 10-10-2012"] = () => { ICompareTheMeasurementWithDateWithTheMeasurementWithDate(vars); it["Then the number 0 is returned"] = () => theNumber0IsReturned(vars); }; }
public void specify_Bmi_is_calculated_and_rounded_to_2_decimals() { DataTable tbl = new DataTable(); tbl.Columns.Add("length", typeof(int)); tbl.Columns.Add("weight", typeof(int)); tbl.Columns.Add("BMI", typeof(double)); tbl.Rows.Add(160, 65000, 25.39); tbl.Rows.Add(160, 65001, 25.39); tbl.Rows.Add(160, 65009, 25.39); tbl.Rows.Add(180, 75000, 23.15); Variables vars = new Variables(); foreach (DataRow row in tbl.Rows) { vars.resetParameters(); context["Given an existing measurement"] = () => { anExistingMeasurement(vars); it["OK"] = () => nop(); }; context["When the length is " + row["length"] + " and the weight is " + row["weight"]] = () => { TheLengthIsAndTheWeight((int)row["length"], (int)row["weight"], vars); vars.BMI = (double) row["BMI"]; it["Then the bmi is " + row["BMI"]] = () => theBmiIs(vars); }; } }
public void specify_One_measurement_is_smaller_than_another_measurement_if_the_date_of_the_first_measurement_is_older() { Variables vars = new Variables(); vars.resetParameters(); context["Given an existing measurement with date 10-10-2012"] = () => { anExistingMeasurementWithDate("10-10-2012", vars); it["OK"] = () => nop(); context["And another existing measurement with date 12-12-2012"] = () => { anotherExistingMeasurementWithDate("12-12-2012", vars); it["OK"] = () => nop(); }; }; context["When I compare the measurement with date 10-10-2012 with the measurement with date 12-12-2012"] = () => { ICompareTheMeasurementWithDateWithTheMeasurementWithDate(vars); it["Then a negative number is returned"] = () => aNegativeNumberIsReturned(vars); }; }
public void specify_Two_measurements_are_not_equal_to_each_other_if_the_date_is_different_even_if_the_lengths_or_weights_are_equal() { Variables vars = new Variables(); vars.resetParameters(); context["Given an existing measurement with length 180, weight 75000 and date 12-12-2012"] = () => { anExistingMeasurementWithLengthAndWeightAndDate(180, 75000, "12-12-2012", vars); it["OK"] = () => nop(); context["And another existing measurement with the same length 180, the same weight 75000 and another date 10-10-2012"] = () => { anotherExistingMeasurementWithAnotherLengthAndWeightAndTheSameDate(180, 75000, "10-10-2012", vars); it["OK"] = () => nop(); }; }; context["When I check if these measurements are equal to each other"] = () => { ICheckIfTheseMeasurementsAreEqualToEachOther(vars); it["Then false is returned"] = () => FalseIsReturned(vars); }; }
public void specify_Measurement_cannot_receive_an_invalid_date() { DataTable tbl = new DataTable(); tbl.Columns.Add("date", typeof(String)); tbl.Columns.Add("remark", typeof(String)); tbl.Rows.Add("10-10-3016", "a date in future"); Variables vars = new Variables(); foreach (DataRow row in tbl.Rows) { vars.resetParameters(); context["Given an existing measurement"] = () => { anExistingMeasurement(vars); it["OK"] = () => nop(); }; context["When I change the date to " + row["date"] + " which is " + row["remark"]] = () => { IChangeTheDateToWhichIsRemark((String)row["date"], vars); it["OK"] = () => nop(); it["An exception is thrown"] = () => anExceptionIsThrown(vars); }; } }
private void anExistingMeasurement(Variables vars) { vars.measurement = new Measurement(_LENGTH, _WEIGHT, _DATE); }
private void theDateIs(Variables vars) { vars.measurement.date.Day.should_be(vars.date.Day); vars.measurement.date.Month.should_be(vars.date.Month); vars.measurement.date.Year.should_be(vars.date.Year); }
private void IChangeTheWeightToWhichIsRemark(int weight, Variables vars) { try { vars.weight = weight; vars.measurement.weight = weight; } catch (Exception ex) { vars.ex = ex; } }
private void theWeightIs(Variables vars) { vars.measurement.weight.should_be(vars.weight); }
private void TrueIsReturned(Variables vars) { ((Boolean) vars.result).should_be(true); }
private void theLengthIs(Variables vars) { vars.measurement.length.should_be(vars.length); }
private void anotherExistingMeasurementWithAnotherLengthAndWeightAndTheSameDate(int length, int weight, String date, Variables vars) { vars.otherMeasurement = new Measurement(length, weight, DateTime.Parse(date)); }
private void aNewMeasurementIsCreated(Variables vars) { vars.measurement.should_not_be_null(); }
private void FalseIsReturned(Variables vars) { ((Boolean)vars.result).should_be(false); }
private void IWantToMakeANewMeasurementWithLengthAndWeightAndDate(int length, int weight, String date, Variables vars) { try { vars.length = length; vars.weight = weight; vars.date = DateTime.Parse(date); vars.measurement = new Measurement(vars.length, vars.weight, vars.date); } catch (Exception ex) { vars.ex = ex; } }
private void ICompareTheMeasurementWithDateWithTheMeasurementWithDate(Variables vars) { vars.result = vars.measurement.CompareTo(vars.otherMeasurement); }
private void anExceptionIsThrown(Variables vars) { vars.ex.should_not_be_null(); }
private void aNegativeNumberIsReturned(Variables vars) { ((int)vars.result).should_be_less_than(0); }
private void IChangeTheLengthToWhichIsRemark(int length, Variables vars) { try { vars.length = length; vars.measurement.length = vars.length; } catch (Exception ex) { vars.ex = ex; } }
public void specify_A_new_measurement_can_be_created_with_a_length_and_a_weight_and_a_date() { DataTable tbl = new DataTable(); tbl.Columns.Add("length", typeof(int)); tbl.Columns.Add("weight", typeof(int)); tbl.Columns.Add("date", typeof(String)); tbl.Rows.Add(180, 75000, "12-12-2012"); tbl.Rows.Add(160, 75000, "12-12-2012"); tbl.Rows.Add(50, 75000, "12-12-2012"); tbl.Rows.Add(300, 75000, "12-12-2012"); tbl.Rows.Add(180, 65000, "12-12-2012"); tbl.Rows.Add(180, 20000, "12-12-2012"); tbl.Rows.Add(180, 700000, "12-12-2012"); tbl.Rows.Add(180, 75000, "10-10-2012"); Variables vars = new Variables(); foreach (DataRow row in tbl.Rows) { vars.resetParameters(); context["When I want to make a new measurement with length " + row["length"] + ", weight " + row["weight"] + "and date " + row["date"]] = () => { IWantToMakeANewMeasurementWithLengthAndWeightAndDate((int)row["length"], (int)row["weight"], (String)row["date"], vars); it["OK"] = () => nop(); it["Then A new measurement is created"] = () => aNewMeasurementIsCreated(vars); it["And the length is " + row["length"]] = () => theLengthIs(vars); it["And the weight is " + row["weight"]] = () => theWeightIs(vars); it["And the date is " + row["date"]] = () => theDateIs(vars); }; } }
public void specify_Measurement_cannot_receive_an_invalid_weight() { DataTable tbl = new DataTable(); tbl.Columns.Add("weight", typeof(int)); tbl.Columns.Add("remark", typeof(String)); tbl.Rows.Add(-75000, "a negative weight"); tbl.Rows.Add(1999, "a just too small weight"); tbl.Rows.Add(700001, "a just too big weight"); Variables vars = new Variables(); foreach (DataRow row in tbl.Rows) { vars.resetParameters(); context["Given an existing measurement"] = () => { anExistingMeasurement(vars); it["OK"] = () => nop(); }; context["When I change the length to " + row["weight"] + " which is " + row["remark"]] = () => { IChangeTheWeightToWhichIsRemark((int)row["weight"], vars); it["OK"] = () => nop(); it["An exception is thrown"] = () => anExceptionIsThrown(vars); }; } }