public void ThenTheResultShouldBe(object result) { answerNode ans = _scenarioContext.Get <answerNode>("result"); //if the result was supposed to be null, check if (result == null) { //check to see if the answer was null bool isNull = ans.getIsNull(); isNull.Should().Be((bool)result); } else { int answer = ans.getNumber(); answer.Should().Be((int)result); } }
public void WhenOperation_IsDoneToTheNumber(char oper, int n2) { //get the previous answer answerNode tempAns = _scenarioContext.Get <answerNode>("testTempAns"); if (tempAns.getIsNull()) { //then the previous answer was null, and the only thing I can do about it is to continue to make the answer null. return; } //tempAns must be an int, because it was not null. // proceed to process the number and perform a calculator operation. else { int tAns = tempAns.getNumber(); answerNode ans = new answerNode(); // to hold temporary answer. //Determine which operator it is. if (oper == '*') { ans.setNumber(tAns * n2, false); //set the number as the product, false because does not need to be set to null. _scenarioContext.Set <answerNode>(ans, "testTempAns"); } if (oper == '/') { //We are not allowed to divide by zero!!!!!!!!! Return null if (n2 == 0) { //set the answer to null!!!!!!!!! ans.setNumber(n2, true); // pass n2 as the number we were trying to divide by (zero). } else { ans.setNumber(tAns / n2, false); _scenarioContext.Set <answerNode>(ans, "testTempAns"); } } if (oper == '+') { ans.setNumber(tAns + n2, false); _scenarioContext.Set <answerNode>(ans, "testTempAns"); } if (oper == '-') { ans.setNumber(tAns - n2, false); _scenarioContext.Set <answerNode>(ans, "testTempAns"); } if (oper == '%') { //We are not allowed to divide by zero!!!!!!!!! Return null if (n2 == 0) { //set the answer to null!!!!!!!!! ans.setNumber(n2, true); // pass n2 as the number we were trying to modulo by (zero). } else { ans.setNumber(tAns % n2, false); _scenarioContext.Set <answerNode>(ans, "testTempAns"); } } if (_scenarioContext.ContainsKey("result")) { _scenarioContext.Set <answerNode>(ans, "result"); } else { _scenarioContext.Add("result", ans); } } }