public IActionResult add([FromBody] CalcAdd par) { var headers = Request.Headers; string track = headers.Where(x => x.Key == "X-Evi-Tracking-Id").FirstOrDefault().Value; if (par.Addends.Count < 2) { return(BadRequest(new BadCalc { ErrorCode = "InternalError", ErrorStatus = 400, ErrorMessage = "Unable to process request: it's necessary at least 2 numbers for add." })); } string msg = "("; double total = 0; for (int i = 0; i < par.Addends.Count; i++) { total += par.Addends[i]; msg += par.Addends[i] + (i < (par.Addends.Count - 1) ? " + " : ""); } msg += ") = " + total.ToString("0.#####"); if (!string.IsNullOrEmpty(track)) { _trk.Operations.Add(new Operations { Id = track, Operation = "Sum", Calculation = msg, Date = DateTime.Now }); } return(Ok(new { Sum = total })); }
public void TestPlus2() { string[] numsAsStrings = { "+", "70000", "1004" }; //TextBox tBox = new TextBox(); CalcAdd calcM = new CalcAdd(); int num = calcM.Calculate(numsAsStrings, null); Assert.AreEqual(num, 71004); }
/// <summary> /// Add two or more operands and retrieve the result /// </summary> /// <param name="id">Id Tracking</param> /// <returns>result</returns> public static string Add(string id) { CalcAdd par = new CalcAdd(); par.Addends = GetNumbers("add", 0); if (par.Addends.Count >= 2) { return(CallRestApi <CalcAdd>(par, "add", id)); } else { return(BadCalculate()); } }