public void Validate(GastoTarjeta categoria, ModelStateDictionary modelState) { var crit = context.Datos; this.modelState = modelState; if (crit.Any(o => o.SadldoInicial < categoria.Monto)) { modelState.AddModelError("Monto", "No cuenta con salfo suficiente"); } }
public ActionResult Crear(GastoTarjeta gasto) { datosInter.Validate(gasto, ModelState); if (!datosInter.IsValid()) { ViewBag.Cuenta = datosInter.Datos(gasto.DatosId); return(View("Crear", gasto)); } gastoInterfaze.SaveGasto(gasto); return(RedirectToActionPermanent("Index", "Banco")); }
public void NoDebePoderGuardarUnGasto() { ModelStateDictionary modelState = new ModelStateDictionary(); var interfa1 = new Mock <GastoInterfaze>(); var interfa2 = new Mock <DatosInter>(); var gastotarjeta = new GastoTarjeta(); var criterio = new GastoTarjeta(); interfa1.Setup(o => o.SaveGasto(gastotarjeta)); interfa2.Setup(o => o.IsValid()).Returns(false); interfa2.Setup(o => o.Validate(gastotarjeta, modelState)); var controller = new GastoTarjController(interfa1.Object, interfa2.Object); var view = controller.Crear(gastotarjeta) as ViewResult; Assert.IsInstanceOf <GastoTarjeta>(view.Model); }
public void SaveGasto(GastoTarjeta gastoTarjeta) { context.GastoTarjeta.Add(gastoTarjeta); context.SaveChanges(); }