public CambioBusinessUnitTest() { mock = Substitute.For <ICambioBusiness>(); mock.GetTaxasDeCambio(null) .Returns(s => { throw new Exception("A moeda precisa ser preenchida."); }); mock.GetTaxasDeCambio(MOEDA_EMPTY) .Returns(s => { throw new Exception("A moeda precisa ser preenchida."); }); mock.GetTaxasDeCambio(MOEDA_INVALIDA) .Returns(s => { throw new ArgumentException("A moeda informada é inválida."); }); mock.GetTaxasDeCambio(MOEDA_VALIDA) .Returns(s => new CambioBuilder(MOEDA_VALIDA).TaxasDeCambio); }
public JsonResult GetTaxasDeCambio(string moeda) { try { var retorno = cambioBusiness.GetTaxasDeCambio(moeda); return(Json(new { success = true, response = retorno })); } catch (Exception ex) { return(Json(new { success = false, response = ex.Message })); } }
public void TestarParametroNull() { Exception ex = Assert.Throws <Exception>(() => mock.GetTaxasDeCambio(null)); Assert.Equal("A moeda precisa ser preenchida.", ex.Message); }