public void SaveVehiculo_True() { Vehiculo vehiculo = new Vehiculo(); var mockVehiculoRepository = new Mock <IVehiculoRepository>(); mockVehiculoRepository.Setup(sp => sp.Save(vehiculo)).Returns(true); IVehiculoService vehiculoService = new VehiculoService(mockVehiculoRepository.Object); var resultado = vehiculoService.Save(vehiculo); Assert.True(resultado); }
private void btnVehiculoGuardar_Click(object sender, EventArgs e) { if (txtVehiculoDescripcion.Text == "" || txtVehiculoMotor.Text == "" || txtVehiculoPlaca.Text == "" || txtVehiculoChasis.Text == "") { MessageBox.Show("Llene los campos faltantes.", "Datos necesarios vacios", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { // Estado de disponibilidad int estado; if (ckbVehiculoEstado.Checked) { estado = 1; } else { estado = 2; } try { var vehiculo = new Data.Entidades.Vehiculo { // Id = lblVehiculoId.Text == "Vehiculo ID" ? 0 : Convert.ToInt32(lblVehiculoId.Text), Descripcion = txtVehiculoDescripcion.Text, TipoVehiculoId = Convert.ToInt32(cbVehiculoTipo.SelectedValue), MarcaId = Convert.ToInt32(cbVehiculoMarca.SelectedValue), ModeloId = Convert.ToInt32(cbVehiculoModelo.SelectedValue), CombustibleId = Convert.ToInt32(cbVehiculoCombustible.SelectedValue), NumeroChasis = txtVehiculoChasis.Text, NumeroMotor = txtVehiculoMotor.Text, NumeroPlaca = txtVehiculoPlaca.Text, EstadoId = estado }; _vehiculoService.Save(vehiculo); MessageBox.Show("El vehiculo se ha guardado exitosamente", "Vehiculo guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Error", ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (lblVehiculoId.Text == "Vehiculo ID") { txtVehiculoDescripcion.Text = ""; txtVehiculoChasis.Text = ""; txtVehiculoMotor.Text = ""; txtVehiculoPlaca.Text = ""; cbVehiculoTipo.SelectedIndex = 0; cbVehiculoMarca.SelectedIndex = 0; cbVehiculoModelo.SelectedIndex = 0; cbVehiculoCombustible.SelectedIndex = 0; ckbVehiculoEstado.Checked = true; } else { Dispose(); var vehiculoLista = new VehiculoLista(); vehiculoLista.Show(); } }