コード例 #1
0
        public void CreateWithInvalidVeiculoShouldThrowError()
        {
            // Arrange
            var veiculo      = new Veiculo("IKG6861", "Verde", 100.00, true, true, "Hyundai", "HB20", TipoVeiculo.Carro, "Venda");
            var dataEntrega  = DateTime.Now;
            var dataRetirada = DateTime.Now;

            var aluguelDto = new AluguelDto
            {
                IdVeiculo    = 0,
                ValorMensal  = 100.00,
                Nome         = "Comprador",
                DataEntrega  = dataEntrega,
                DataRetirada = dataRetirada
            };

            var aluguel = new Aluguel(0, 100.00, "Comprador", dataEntrega, dataRetirada);

            veiculoRepository.GetById(aluguel.IdVeiculo).Returns(veiculo);

            // Act
            Action act = () => service.Create(aluguelDto);

            // Assert
            act.Should().Throw <InvalidOperationException>();
            veiculoRepository.Received().GetById(aluguel.IdVeiculo);
        }
コード例 #2
0
        public void CreateWithValidVeiculoShouldReturnAluguel()
        {
            // Arrange
            var id         = 0;
            var veiculo    = new Veiculo("IKG6861", "Verde", 100.00, true, true, "Hyundai", "HB20", TipoVeiculo.Carro, "Aluguel");
            var aluguelDto = new AluguelDto
            {
                IdVeiculo    = id,
                ValorMensal  = 100,
                Nome         = "Comprador",
                DataEntrega  = DateTime.Now,
                DataRetirada = DateTime.Now
            };

            var aluguel = new Aluguel(id, 100, "Comprador", DateTime.Now, DateTime.Now);

            veiculoRepository.GetById(id).Returns(veiculo);
            aluguelRepository.CreateAluguel(aluguelDto).Returns(aluguel);

            // Act
            var result = service.Create(aluguelDto);

            // Assert
            result.Should().NotBeNull();
            result.Should().Equals(aluguel);
            aluguelRepository.Received().CreateAluguel(aluguelDto);
        }
コード例 #3
0
        public Aluguel CreateAluguel(AluguelDto aluguelDto)
        {
            var novoAluguel = new Aluguel(aluguelDto.IdVeiculo,
                                          aluguelDto.ValorMensal,
                                          aluguelDto.Nome,
                                          aluguelDto.DataEntrega,
                                          aluguelDto.DataRetirada);

            var result = Insert(novoAluguel);

            return(result);
        }
コード例 #4
0
        public async Task <AluguelDto> GetAluguelById(int id)
        {
            var aluguel = await _context.Alugueis.Include(f => f.Filme).Include(c => c.Cliente).FirstOrDefaultAsync(x => x.AluguelId == id);

            if (aluguel == null)
            {
                return(null);
            }
            var novoAluguel = new AluguelDto(aluguel);

            return(novoAluguel);
        }
コード例 #5
0
        public Aluguel Create(AluguelDto aluguelDto)
        {
            var veiculo = veiculoRepository.GetById(aluguelDto.IdVeiculo);

            if (veiculo.TipoOperacao.Equals("Aluguel") && veiculo.Disponivel)
            {
                var result = repository.CreateAluguel(aluguelDto);
                veiculo.ChangeDisponibilidade();
                veiculoRepository.UpdateVeiculo(veiculo);
                return(result);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
コード例 #6
0
        public void CreateShouldReturnAluguel()
        {
            //Arrange
            var aluguelDto = new AluguelDto
            {
                IdVeiculo    = 10,
                ValorMensal  = 100,
                Nome         = "Comprador",
                DataEntrega  = DateTime.Now,
                DataRetirada = DateTime.Now
            };

            var aluguel = new Aluguel(10, 100, "Comprador", DateTime.Now, DateTime.Now);

            //Act
            var result = repository.CreateAluguel(aluguelDto);

            //Assert
            result.Should().NotBeNull();
            result.Should().Equals(aluguel);
        }
コード例 #7
0
        public IActionResult Create([FromBody] AluguelDto aluguelDto)
        {
            var result = service.Create(aluguelDto);

            return(Ok(result));
        }