Пример #1
0
        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);
            }
        }
Пример #2
0
    public void DeleteTarifa_True(int id)
    {
        var mockTarifaRepository = new Mock <ITarifaRepository>();

        mockTarifaRepository.Setup(sp => sp.Delete(id)).Returns(true);
        ITarifaService tarifaService = new TarifaService(mockTarifaRepository.Object);

        var resultado = tarifaService.Delete(id);

        Assert.True(resultado);
    }
Пример #3
0
    public void UpdateTarifa_True()
    {
        Tarifa tarifa = new Tarifa();
        var    mockTarifaRepository = new Mock <ITarifaRepository>();

        mockTarifaRepository.Setup(sp => sp.Update(tarifa)).Returns(true);
        ITarifaService tarifaService = new TarifaService(mockTarifaRepository.Object);

        var resultado = tarifaService.Update(tarifa);

        Assert.True(resultado);
    }
Пример #4
0
        public void InjectionTest()
        {
            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);
                Assert.IsNotNull(tarifaService);
            }
        }
Пример #5
0
    public void GetByIdTarifa_True(int id)
    {
        Tarifa tarifa = new Tarifa();

        tarifa.Id = id;
        var mockTarifaRepository = new Mock <ITarifaRepository>();

        mockTarifaRepository.Setup(sp => sp.Get(id)).Returns(tarifa);
        ITarifaService tarifaService = new TarifaService(mockTarifaRepository.Object);

        var resultado = tarifaService.Get(id);

        Assert.Equal(1, resultado.Id);
    }
Пример #6
0
        public async System.Threading.Tasks.Task GetTarifaTestNullAsync()
        {
            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 response = await tarifaService.GetTarifas(null);
            }
        }
Пример #7
0
    public void GetAllTarifa_True()
    {
        List <Tarifa> aux = new List <Tarifa>();
        Tarifa        tar = new Tarifa();

        aux.Add(tar);
        IEnumerable <Tarifa> tarifas = aux;
        var mockTarifaRepository     = new Mock <ITarifaRepository>();

        mockTarifaRepository.Setup(sp => sp.GetAll()).Returns(tarifas);
        ITarifaService tarifaService = new TarifaService(mockTarifaRepository.Object);

        var resultado = tarifaService.GetAll();

        Assert.NotEmpty(resultado);
    }
        public void SimularPreco__Should_Be_True()
        {
            //
            //Arrange
            int duracao = 10;
            var tarifa  = new TarifaBuilder().Build();
            var plano   = new PlanoBuilder().Build();

            var tarifaRepository = TarifaRepositoryBuilder.Instance().Exists(tarifa).Build();
            var planoRepository  = PlanoRepositoryBuilder.Instance().Exists(plano).Build();


            var service = new TarifaService(tarifaRepository, planoRepository);

            //
            // Act
            var response = service.SimularPreco(tarifa.Origem, tarifa.Destino, duracao);

            //
            // Assert
            Assert.Equal(tarifa.Valor * duracao, response);
        }
        public void SimularPrecoFaleMais__Should_Be_True()
        {
            //
            //Arrange
            int    duracao            = 31;
            double acrescimoExcedente = 1.1;
            var    tarifa             = new TarifaBuilder().Build();
            var    plano = new PlanoBuilder().Build();

            var tarifaRepository = TarifaRepositoryBuilder.Instance().Exists(tarifa).Build();
            var planoRepository  = PlanoRepositoryBuilder.Instance().Exists(plano).Build();


            var service = new TarifaService(tarifaRepository, planoRepository);

            //
            // Act
            var response = service.SimularPrecoFaleMais(tarifa.Origem, tarifa.Destino, duracao, plano.Id);

            //
            // Assert
            Assert.Equal((tarifa.Valor * acrescimoExcedente) * duracao, response);
        }
Пример #10
0
 public TarifaController(TarifaService tarifaService)
 {
     this.tarifaService = tarifaService;
 }