public void TestQueRetornaACotacaoDaMoedaDesejadaComBaseNoDolarComInformacoesEmCache() { IMoeda MoedaDolar = new Moeda("USD", 1); Mock <IDistributedCache> mckcache = new Mock <IDistributedCache>(); Mock <IConfigurationHelper> mckConfigurationHelper = new Mock <IConfigurationHelper>(); RedisConnectorHelperFactory redisHelperFactory = new RedisConnectorHelperFactory(mckcache.Object); IRedisConnectorHelper redisHelper = redisHelperFactory.Create(); mckcache.Setup(x => x.Get("GetCotacaoComBaseNoDolarUSD")).Returns(Serialize(MoedaDolar)); DistributedCacheEntryOptions distributedCacheEntryOptions = new DistributedCacheEntryOptions(); distributedCacheEntryOptions.SetAbsoluteExpiration(TimeSpan.FromMinutes(1)); mckcache.Setup(x => x.Set("GetCotacaoComBaseNoDolarUSD", Serialize(MoedaDolar), distributedCacheEntryOptions)); IConversorACL conversorACL = new ConversorACL(new MoedaFactory(), new RedisConnectorHelperFactory(mckcache.Object), mckConfigurationHelper.Object); IMoeda DolarResult = conversorACL.GetCotacaoComBaseNoDolar(MoedaDolar.SiglaMoeda); Assert.True(DolarResult.Valor.Equals(1)); IMoeda MoedaBRL = new Moeda("BRL", 3.86M); mckcache.Setup(x => x.Get("GetCotacaoComBaseNoDolarBRL")).Returns(Serialize(MoedaBRL)); mckcache.Setup(x => x.Set("GetCotacaoComBaseNoDolarBRL", Serialize(MoedaBRL), distributedCacheEntryOptions)); IMoeda RealResult = conversorACL.GetCotacaoComBaseNoDolar(MoedaBRL.SiglaMoeda); Assert.False(RealResult.Valor.Equals(DolarResult.Valor)); }
public void TestQueRetornaACotacaoDaMoedaDesejadaComBaseNoDolarSemInformacoesEmCache() { IMoeda MoedaDolarMck = new Moeda("USD", 1); byte[] resultmockNull = null; Mock <IDistributedCache> mckcache = new Mock <IDistributedCache>(); Mock <IConfigurationHelper> mckconfigurationHelper = new Mock <IConfigurationHelper>(); mckconfigurationHelper.Setup(x => x.GetSection("ACCESS_KEY")).Returns("?access_key=1503440cbd4d453ce74962abd00a82c2"); mckconfigurationHelper.Setup(x => x.GetSection("BASE_URL")).Returns("http://apilayer.net/api/"); mckcache.Setup(x => x.Get("GetCotacaoComBaseNoDolarUSD")).Returns(resultmockNull); DistributedCacheEntryOptions distributedCacheEntryOptions = new DistributedCacheEntryOptions(); distributedCacheEntryOptions.SetAbsoluteExpiration(TimeSpan.FromMinutes(1)); mckcache.Setup(x => x.Set("GetCotacaoComBaseNoDolarUSD", Serialize(MoedaDolarMck), distributedCacheEntryOptions)); IConversorACL conversorACL = new ConversorACL(new MoedaFactory(), new RedisConnectorHelperFactory(mckcache.Object), mckconfigurationHelper.Object); IMoeda DolarResult = conversorACL.GetCotacaoComBaseNoDolar(MoedaDolarMck.SiglaMoeda); Assert.True(DolarResult.Valor.Equals(1)); String OutraMoedaQueNaoTemValorDoDolar = "BRL"; mckcache.Setup(x => x.Get("GetCotacaoComBaseNoDolarBRL")).Returns(resultmockNull); mckcache.Setup(x => x.Set("GetCotacaoComBaseNoDolarBRL", Serialize(MoedaDolarMck), distributedCacheEntryOptions)); IMoeda RealResult = conversorACL.GetCotacaoComBaseNoDolar(OutraMoedaQueNaoTemValorDoDolar); Assert.False(RealResult.Valor.Equals(DolarResult.Valor)); }
public void TestStandoValoresNulosOuEmBrancoComTempoDeAmarzenamento() { IMoeda MoedaNull = null; IMoeda Moeda = new Moeda("USD", 1); Mock <IDistributedCache> mckcache = new Mock <IDistributedCache>(); IRedisConnectorHelper redisHelper = new RedisConnectorHelper(mckcache.Object); Assert.Throws <Exception>(() => redisHelper.Set("Teste", MoedaNull, 1)); Assert.Throws <Exception>(() => redisHelper.Set("", Moeda, 1)); Assert.Throws <Exception>(() => redisHelper.Set("", MoedaNull, 1)); }
public IMoeda ConverterParaDolar(IMoeda CotacaoDaMoedaEscolhidaEmDolar) { IMoeda result = null; if (CotacaoDaMoedaEscolhidaEmDolar.Valor <= 0) { throw new Exception("Nao e possivel realizar o calculo sem a cotacao da moeda em dolar."); } result = new Moeda("USD", this.Valor / CotacaoDaMoedaEscolhidaEmDolar.Valor); return(result); }
public ConverterMoedaResult ConverterMoeda(ConverterMoedaRequest converterMoedaRequest) { IConversorACL conversorACL = conversorACLFactory.Create(); IMoeda MoedaOrigem = moedaFactory.Create(converterMoedaRequest.SiglaMoedaOrigem, converterMoedaRequest.ValorParaConversao); IMoeda CotacaoEmDolarMoedaOrigem = conversorACL.GetCotacaoComBaseNoDolar(MoedaOrigem.SiglaMoeda); IMoeda dinhieroOrigemEmDolar = MoedaOrigem.ConverterParaDolar(CotacaoEmDolarMoedaOrigem); IMoeda CotacaoEmDolarMoedaConvertida = conversorACL.GetCotacaoComBaseNoDolar(converterMoedaRequest.MoedaParaConversao); Decimal valorDaConversao = dinhieroOrigemEmDolar.ObterValorDaConversaoDeMoeda(CotacaoEmDolarMoedaConvertida); IMoeda MoedaConvertida = moedaFactory.Create(converterMoedaRequest.MoedaParaConversao, valorDaConversao); ConverterMoedaResult result = new ConverterMoedaResult() { siglaMoeda = MoedaConvertida.SiglaMoeda, valor = MoedaConvertida.Valor }; return(result); }
public MoedaService(IMoeda moeda) { _moeda = moeda; }
public Decimal ObterValorDaConversaoDeMoeda(IMoeda CotacaoEmDolarMoedaConvertida) { var retorno = (this.Valor * CotacaoEmDolarMoedaConvertida.Valor); return(retorno); }