예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 public MoedaService(IMoeda moeda)
 {
     _moeda = moeda;
 }
예제 #7
0
        public Decimal ObterValorDaConversaoDeMoeda(IMoeda CotacaoEmDolarMoedaConvertida)
        {
            var retorno = (this.Valor * CotacaoEmDolarMoedaConvertida.Valor);

            return(retorno);
        }