Exemplo n.º 1
0
        public void TestPostRegistro()
        {
            string respEsperada     = "Registro exitoso";
            JavaScriptSerializer js = new JavaScriptSerializer();
            campos indece           = new campos()
            {
                productoGeneral = 1,
                tipoProducto    = 2,
                cantidad        = 2,
                mesa            = 3,
                producto        = 1,
                precioUnit      = Convert.ToDecimal("12.5"),
            };
            string postdata = js.Serialize(indece);

            byte[]         data    = Encoding.UTF8.GetBytes(postdata);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:50548/Ventas.svc/Venta");

            request.Method        = "POST";
            request.ContentLength = data.Length;
            request.ContentType   = "application/json";
            var requestStream = request.GetRequestStream();

            requestStream.Write(data, 0, data.Length);
            HttpWebResponse response  = (HttpWebResponse)request.GetResponse();
            StreamReader    reader    = new StreamReader(response.GetResponseStream());
            string          tramajson = reader.ReadToEnd();
            //List<productos> indicadorrespuesta = js.Deserialize<List<productos>>(tramajson);
            string repsuestaServicio = js.Deserialize <string>(tramajson);

            Assert.AreEqual(repsuestaServicio, respEsperada);
        }
Exemplo n.º 2
0
        public void TestPostProductos()
        {
            string respEsperada     = "Ron";
            JavaScriptSerializer js = new JavaScriptSerializer();
            campos indec            = new campos()
            {
                productoGeneral = 1,
                tipoProducto    = 2,
            };
            string postdata = js.Serialize(indec);

            byte[]         data    = Encoding.UTF8.GetBytes(postdata);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:50548/Producto.svc/Producto");

            request.Method        = "POST";
            request.ContentLength = data.Length;
            request.ContentType   = "application/json";
            var requestStream = request.GetRequestStream();

            requestStream.Write(data, 0, data.Length);

            HttpWebResponse response           = (HttpWebResponse)request.GetResponse();
            StreamReader    reader             = new StreamReader(response.GetResponseStream());
            string          tramajson          = reader.ReadToEnd();
            List <campos>   indicadorrespuesta = js.Deserialize <List <campos> >(tramajson);
            string          desctipoProducto   = "";

            foreach (campos ca in indicadorrespuesta)
            {
                desctipoProducto = ca.descProducto;
            }
            Assert.AreEqual(desctipoProducto, respEsperada);
        }