public void GetProducto() { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SAML", GetSamlToken()); client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Obligatorio string code = "e68c99f1-290c-4b6f-bba6-3940d2830056"; string queryUrl = string.Format("{0}/{1}", Route, code); HttpResponseMessage response = client.GetAsync(queryUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); ProductoTestModel producto = response.Content.ReadAsAsync <ProductoTestModel>().Result; Assert.IsTrue(producto != null); if (producto != null) { Assert.IsTrue(!string.IsNullOrEmpty(producto.Nombre)); Assert.IsTrue(!string.IsNullOrEmpty(producto.Codigo)); Assert.IsTrue(!string.IsNullOrEmpty(producto.Descripcion)); } } }
public void PostProducto() { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SAML", GetSamlToken()); client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = new TimeSpan(12, 0, 0); //El id de los anunciantes sale del servicio de clientes => http://tlfepubapi61.tlfextranet.local:8062/odata/Clientes //El id de la familia sale del servicio de familias => http://tlfepubapi61.tlfextranet.local:8062/odata/Familias //No poner codigo cuando se hace el post y resultado en el caso de ser valido va a tener el codigo del producto /* OPCION 1 PASAR UN MODEL Y SERIALIZARLO CON NEWTONSOFT JSON*/ ProductoTestModel testModel = new ProductoTestModel() { Nombre = "Test HAVAS Nombre Producto", Descripcion = "Test HAVAS Description Producto", IdFamilia = 10409, //No pasar un codigo en el alta del producto Codigo = "", Anunciantes = new List <long>() { 2514 } }; string aux = Newtonsoft.Json.JsonConvert.SerializeObject(testModel); /* */ /* OPCION 2 PASAR UN STRING PLANO */ //string aux1 = "{\"Nombre\":\"Test HAVAS Nombre Producto\",\"Descripcion\":\"Test HAVAS Description Producto\",\"IdFamilia\":10409,\"Codigo\":\"\",\"Anunciantes\":[2514]}"; HttpContent contentPost = new StringContent(aux, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(Route, contentPost).Result; Assert.IsTrue(response.IsSuccessStatusCode); ProductoTestModel productoResult = response.Content.ReadAsAsync <ProductoTestModel>().Result; Assert.IsTrue(productoResult != null); if (productoResult != null) { Assert.IsTrue(!string.IsNullOrEmpty(productoResult.Nombre)); Assert.IsTrue(!string.IsNullOrEmpty(productoResult.Codigo)); Assert.IsTrue(!string.IsNullOrEmpty(productoResult.Descripcion)); } } }
public void PutProducto() { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SAML", GetSamlToken()); client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = new TimeSpan(12, 0, 0); /* OPCION 1 USAR UN MODEL Y SERIALIZARLO CON NEWTONSOFT JSON*/ ProductoTestModel testModel = new ProductoTestModel() { Nombre = "Test HAVAS Nombre Producto", Descripcion = "Test HAVAS Description Producto", IdFamilia = 10409, Codigo = "", Anunciantes = new List <long>() { 2514 } }; string aux = Newtonsoft.Json.JsonConvert.SerializeObject(testModel); /**/ /* OPCION 2 USAR UN STRING PLANO */ string aux1 = "{\"Nombre\":\"Test HAVAS Nombre Producto\",\"Descripcion\":\"Test HAVAS Description Producto\",\"IdFamilia\":10409,\"Codigo\":\"\",\"Anunciantes\":[2514]}"; HttpContent contentPost = new StringContent(aux, Encoding.UTF8, "application/json"); string code = "d65947fc-ef3c-4fe6-9cc7-460b0c5e769b"; string queryUrl = string.Format("{0}/{1}", Route, code); HttpResponseMessage response = client.PutAsync(queryUrl, contentPost).Result; Assert.IsTrue(response.IsSuccessStatusCode); } }