public void DebePoderAgregarUnaVenta() { var data1 = new List <Sale>() { }.AsQueryable(); var data = new List <DetalleVenta>() { }.AsQueryable(); var dbset = new Mock <DbSet <DetalleVenta> >(); dbset.As <IQueryable <DetalleVenta> >().Setup(m => m.Provider).Returns(data.Provider); dbset.As <IQueryable <DetalleVenta> >().Setup(m => m.Expression).Returns(data.Expression); dbset.As <IQueryable <DetalleVenta> >().Setup(m => m.ElementType).Returns(data.ElementType); dbset.As <IQueryable <DetalleVenta> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var dbset2 = new Mock <DbSet <Sale> >(); dbset.As <IQueryable <Sale> >().Setup(m => m.Provider).Returns(data1.Provider); dbset.As <IQueryable <Sale> >().Setup(m => m.Expression).Returns(data1.Expression); dbset.As <IQueryable <Sale> >().Setup(m => m.ElementType).Returns(data1.ElementType); dbset.As <IQueryable <Sale> >().Setup(m => m.GetEnumerator()).Returns(data1.GetEnumerator()); var context = new Mock <OpticaContext>(); context.Setup(a => a.DetalleVentas).Returns(dbset.Object); context.Setup(a => a.Sales).Returns(dbset2.Object); var iVentaService = new Mock <IVentaService>(); var sale = new Sale() { IdSALE = "aa" }; var detalleVenta = new List <DetalleVenta>() { new DetalleVenta { Id = "ddd", VentaId = "q22", Cantidad = "2", ProductoId = "33", ProductoNombre = "A", ProductoCategoria = "D", ProductoPrecio = "20", Total = "40" }, new DetalleVenta { Id = "dd", VentaId = "q23", Cantidad = "3", ProductoId = "44", ProductoNombre = "B", ProductoCategoria = "E", ProductoPrecio = "30", Total = "90" }, new DetalleVenta { Id = "aaa", VentaId = "q24", Cantidad = "4", ProductoId = "44", ProductoNombre = "C", ProductoCategoria = "F", ProductoPrecio = "40", Total = "160" }, }; var ventaService = new VentaService(context.Object); var add = ventaService.AddVenta(sale, detalleVenta); Assert.IsTrue(add); Assert.AreEqual(true, add); Assert.AreNotEqual(false, add); }
protected void btnGuardar_Click(object sender, EventArgs e) { var venta = GetVenta(); venta.Fecha = DateTime.Parse(txtFecha.Text); if (venta != null) { if (ViewState["opc"].ToString() == "nuevo") { if (txtCliente.Text == "" && txtDni.Text == "") { ScriptManager. RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Llenar datos de Cliente..!!')", true); } else { venta.ComprobateId = Int32.Parse(cbTipoComprobante.SelectedValue); VentaService.AddVenta(venta); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('VENTA Registrada..!!')", true); Response.Redirect("frmListVentas.aspx"); } } else if (ViewState["opc"].ToString() == "editar") { if (txtCliente.Text == "" && txtDni.Text == "") { ScriptManager. RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Llenar datos de Cliente..!!')", true); } else { venta.ComprobateId = Int32.Parse(cbTipoComprobante.SelectedValue); VentaService.UpdateVenta(venta); ScriptManager. RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Venta Editada..!!')", true); Response.Redirect("frmListVentas.aspx"); } } } }