Example #1
0
        public async Task <ResponseTarifa> GetTarifas(RequestTarifa requestTarifa)
        {
            try
            {
                Tarifa tarifa = await tarifaRepository.GetTarifas(requestTarifa.Origem, requestTarifa.Destino);

                if (tarifa == null)
                {
                    return new ResponseTarifa()
                           {
                               Destino = requestTarifa.Destino,
                               Origem  = requestTarifa.Origem,
                               Plano   = requestTarifa.Plano,
                               Tempo   = requestTarifa.Tempo
                           }
                }
                ;

                ResponseTarifa response = tarifa.ToDTO(requestTarifa);

                response.SemFaleMais = CalculadoraTarifa.CalculoSemPlano(response);
                response.ComFaleMais = CalculadoraTarifa.CalculoComPlano(response);

                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async System.Threading.Tasks.Task GetTarifaTestInvalidRequestAsync()
        {
            var options = new DbContextOptionsBuilder <Context>()
                          .UseSqlite("DataSource=:memory:")
                          .Options;

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new Context(options))
            {
                ITarifaRepository tarifaRepository = new TarifaRepository(context);
                TarifaService     tarifaService    = new TarifaService(tarifaRepository);

                var request = new RequestTarifa();
                request.Origem  = 11;
                request.Destino = 199;
                request.Plano   = null;
                request.Tempo   = 40;

                var response = await tarifaService.GetTarifas(request);

                Assert.IsNotNull(response);
                Assert.AreEqual(response.SemFaleMais, 0);
                Assert.AreEqual(response.ComFaleMais, 0);
            }
        }
Example #3
0
        public async Task <IActionResult> Get([FromQuery] RequestTarifa requestTarifa)
        {
            if (requestTarifa == null)
            {
                return(BadRequest());
            }

            return(Ok(await tarifaService.GetTarifas(requestTarifa)));
        }
Example #4
0
 public ResponseTarifa ToDTO(RequestTarifa requestTarifa)
 {
     return(new ResponseTarifa()
     {
         Origem = this.Origem,
         Destino = this.Destino,
         PrecoMinuto = this.PrecoMinuto,
         Tempo = requestTarifa.Tempo,
         Plano = requestTarifa.Plano
     });
 }
        public async System.Threading.Tasks.Task GetTarifaTestEmptyAsync()
        {
            var options = new DbContextOptionsBuilder <Context>()
                          .UseSqlite("DataSource=:memory:")
                          .Options;

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new Context(options))
            {
                ITarifaRepository tarifaRepository = new TarifaRepository(context);
                TarifaService     tarifaService    = new TarifaService(tarifaRepository);

                var request = new RequestTarifa();

                var response = await tarifaService.GetTarifas(request);

                Assert.IsNotNull(response);
            }
        }