public void WhenRequestingAValidCurrency_AndNoErrorsHappen_ShouldReturnOk() { var currencyToBeConverted = new CurrencyValueToConvert(100m); var currencyConvertedModel = new DomainResponse <ConvertedValueModel>( new ConvertedValueModel(currencyToBeConverted.CurrencyValue, "one hundred dollars"), null); Mock.Arrange(() => _manager.ConvertToWords(currencyToBeConverted)). Returns(currencyConvertedModel); var response = _controller.ConvertFromCurrencyToWords(currencyToBeConverted); var result = response as OkObjectResult; Assert.IsNotNull(response); Assert.IsNotNull(result); Assert.IsInstanceOfType(response, typeof(OkObjectResult)); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.IsNotNull(result.Value); Assert.AreEqual(result.StatusCode, (int)HttpStatusCode.OK); }
public IActionResult ConvertFromCurrencyToWords([FromBody][Required] CurrencyValueToConvert currencyValue) { try { var response = _conversionToWordsManager.ConvertToWords(currencyValue); if (response.DomainError != null) { return(new BadRequestObjectResult(response.DomainError)); } return(new OkObjectResult(response.Result)); } catch { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }