예제 #1
0
        public async Task <ActionResult <Vehiculo> > Create([FromBody] CreateVehiculoViewModel model)
        {
            if (!ModelState.IsValid)//validando
            {
                return(BadRequest(ModelState));
            }

            Vehiculo ca = new Vehiculo
            {
                Placa            = model.Placa,
                Color            = model.Color,
                FechaFabricacion = model.FechaFabricacion,
                ModeloId         = model.ModeloId,
                CategoriaId      = model.CategoriaId,
                ConductorId      = model.ConductorId,
            };


            _context.Vehiculos.Add(ca);//como si escribieras el insert sin ejecutar
            try
            {
                await _context.SaveChangesAsync();//con el savechanges lo aterrizas o actualizar los cambios en la bd
            }
            catch (Exception)
            {
                return(BadRequest());
            }

            return(Ok());
        }
예제 #2
0
        public async Task RegisteranVehicle()
        {
            //Arrange


            var BDName  = Guid.NewGuid().ToString();
            var context = BuildContext(BDName);


            //Act

            var newvehicle = new CreateVehiculoViewModel()
            {
                Placa            = "ABC123",
                Color            = "Azul",
                FechaFabricacion = "14/2020",
                ConductorId      = 1,
                CategoriaId      = 1,
                ModeloId         = 1,
            };

            var controller = new VehiculoesController(context);

            var response = await controller.Create(newvehicle);

            var registration = response.Result as StatusCodeResult;

            //Assert

            Assert.IsInstanceOf <OkResult>(registration);
        }