public void BaseTestCalculation(decimal amount, string expected) { var combination = _service.GetSmallestCombination(amount); Assert.IsTrue(combination.HasResult()); Assert.IsTrue(combination.Count() == 1); var result = combination.ElementAt(0); Assert.IsNotNull(result); Assert.IsTrue(result.Quantity == 1); Assert.IsTrue(result.Money.Amount == amount); Assert.AreEqual(result.Money.ToString(), expected); }
/// <summary> /// GET api/calculate/1000.00 /// Returns a combination that define how the amount could be splitted in the minimun total quantity of all types /// </summary> /// <param name="amount"> /// Amount to manage /// </param> /// <returns> /// An HttpResponseMessage that contains the JSON value of the calculated combination /// </returns> public HttpResponseMessage Get(decimal amount) { HttpResponseMessage response; if (amount < 0 || amount > 1000) { response = GetResponseMessage( HttpStatusCode.BadRequest, new StringContent("The value of amount must be between p0.01 and £1000.")); } else { var combination = _service.GetSmallestCombination(amount); var jsonCombination = JsonConvert.SerializeObject(combination); response = GetResponseMessage( HttpStatusCode.OK, new StringContent(jsonCombination, Encoding.UTF8, "application/json")); } return(response); }