public IActionResult div([FromBody] CalcDiv par) { var headers = Request.Headers; string track = headers.Where(x => x.Key == "X-Evi-Tracking-Id").FirstOrDefault().Value; if (par.Dividend == 0 || par.Divisor == 0) { return(BadRequest(new BadCalc { ErrorCode = "InternalError", ErrorStatus = 400, ErrorMessage = "Unable to process request: can't divide any number by 0." })); } int total = par.Dividend / par.Divisor; int remainder = par.Dividend % par.Divisor; string msg = "(" + par.Dividend + " / " + par.Divisor + " = " + total.ToString() + " remainder : " + remainder.ToString() + ")"; if (!string.IsNullOrEmpty(track)) { _trk.Operations.Add(new Operations { Id = track, Operation = "Div", Calculation = msg, Date = DateTime.Now }); } return(Ok(new { Quotient = total, Remainder = remainder })); }
public void TestDiv() { string[] numsAsStrings = { "/", "3", "12" }; //TextBox tBox = new TextBox(); CalcDiv calcM = new CalcDiv(); int num = calcM.Calculate(numsAsStrings, null); Assert.AreEqual(num, 4); }
/// <summary> /// Divide two operands and retrieve the result /// </summary> /// <param name="id">Id Tracking</param> /// <returns></returns> public static string Div(string id) { CalcDiv par = new CalcDiv(); List <double> numbers = GetNumbers("div", 2); if (numbers.Count == 2) { par.Dividend = (int)numbers[0]; par.Divisor = (int)numbers[1]; return(CallRestApi <CalcDiv>(par, "div", id)); } else { return(BadCalculate()); } }