public void PutMaterial() { 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 */ MaterialTestModel testModel = new MaterialTestModel() { Tema = "Test Api Edit", IdClienteAgencia = 2514, IdClienteAnunciante = 59, DuracionReal = 10, DespuesHorarioProtMenor = true, BebidasAlcoholicas = true, //La version tiene que ser mayor a cero es recomendable que se le sume 1 a la version del material que se esta modificando VigenciaDesde = new DateTime(2019, 03, 01), VigenciaHasta = new DateTime(2019, 03, 31), CodigoTipoMaterial = "COM", Observaciones = "Test Edit Observaciones", //Obligatorio RegistroAFSCA = "", //El codigo del tipo de publicidad se obtiene del servicio de consulta de tipo de publicidad => http://tlfepubapi61.tlfextranet.local:8062/odata/TiposPublicidad TiposPublicidad = new List <string>() { "TANDA", "PNT" }, Productos = new List <MaterialProductoTestModel>() { new MaterialProductoTestModel() { //El codigo del producto se obtiene del servicio de epublicidad de creacion de Producto => http://tlfepubapi61.tlfextranet.local/api/Productos/ Producto = new ProductoTestModel() { Codigo = "d65947fc-ef3c-4fe6-9cc7-460b0c5e769b" } } } }; string aux = Newtonsoft.Json.JsonConvert.SerializeObject(testModel); /**/ /* OPCION 2 USAR UN STRING PLANO */ //string aux1 = "{\"Numero\":\"4321 Edit\",\"Tema\":\"Test Api Edit\",\"IdClienteAgencia\":2514,\"IdClienteAnunciante\":59,\"DuracionReal\":10,\"DespuesHorarioProtMenor\":true,\"BebidasAlcoholicas\":true,\"VigenciaDesde\":\"2019-03-01T00:00:00\",\"VigenciaHasta\":\"2019-03-31T00:00:00\",\"IdPrograma\":0,\"CodigoTipoMaterial\":\"COM\",\"PathImage\":\"\",\"IdMaterialComercial\":0,\"Version\":1,\"Observaciones\":\"Test Edit Observaciones\",\"RegistroAFSCA\":\"\",\"Codigo\":null,\"Productos\":[{\"Producto\":{\"Nombre\":null,\"Descripcion\":null,\"IdFamilia\":0,\"Codigo\":\"d65947fc-ef3c-4fe6-9cc7-460b0c5e769b\",\"Version\":0,\"Anunciantes\":null}}],\"TiposPublicidad\":[\"TANDA\",\"PNT\"]}"; HttpContent content = new StringContent(aux, Encoding.UTF8, "application/json"); string code = "454661cd-768d-41f8-9a77-1a01ef523e00"; string queryUrl = string.Format("{0}/{1}", Route, code); HttpResponseMessage response = client.PutAsync(queryUrl, content).Result; Assert.IsTrue(response.IsSuccessStatusCode); } }
public void GetMaterial() { 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 = "77715d87-b2b0-47f7-bca7-c5fe51556c66"; string queryUrl = string.Format("{0}/{1}", Route, code); HttpResponseMessage response = client.GetAsync(queryUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); MaterialTestModel material = response.Content.ReadAsAsync <MaterialTestModel>().Result; Assert.IsTrue(material != null); if (material != null) { Assert.IsTrue(!string.IsNullOrEmpty(material.Codigo)); } } }
public void PostMaterial() { 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 */ MaterialTestModel testModel = new MaterialTestModel() { Tema = "Test Api 3", //Los id de IdClienteAgencia, IdClienteAnunciante y IdClienteFacturable se obtienen del servicio de consulta de clientes (segurizado solo se si tiene acceso a los que corresponda) //El id de los anunciantes y agencia sale del servicio de clientes => http://tlfepubapi61.tlfextranet.local:8062/odata/Clientes IdClienteAgencia = 2514, IdClienteAnunciante = 59, DuracionReal = 10, DespuesHorarioProtMenor = true, BebidasAlcoholicas = true, VigenciaDesde = new DateTime(2019, 03, 01), VigenciaHasta = new DateTime(2019, 03, 31), //Poner COM => COMERCIAL CodigoTipoMaterial = "COM", Observaciones = "Test 3 Observaciones", //obligatorio RegistroAFSCA = "", //El codigo del tipo de publicidad se obtiene del servicio de consulta de tipo de publicidad => http://tlfepubapi61.tlfextranet.local:8062/odata/TiposPublicidad TiposPublicidad = new List <string>() { "TANDA", "PNT" }, Productos = new List <MaterialProductoTestModel>() { new MaterialProductoTestModel() { //El codigo del producto se obtiene del servicio de epublicidad de creacion de Producto => http://tlfepubapi61.tlfextranet.local/api/Productos/ //Poner solo el codigo del producto Producto = new ProductoTestModel() { Codigo = "d65947fc-ef3c-4fe6-9cc7-460b0c5e769b" } }, new MaterialProductoTestModel() { //El codigo del producto se obtiene del servicio de epublicidad de creacion de Producto => http://tlfepubapi61.tlfextranet.local/api/Productos/ //Poner solo el codigo del producto Producto = new ProductoTestModel() { Codigo = "e68c99f1-290c-4b6f-bba6-3940d2830056" } } } }; string aux = Newtonsoft.Json.JsonConvert.SerializeObject(testModel); /**/ /* OPCION 2 USAR UN STRING PLANO */ //string aux1 = "{\"Numero\":\"4321\",\"Tema\":\"Test Api 3\",\"IdClienteAgencia\":2514,\"IdClienteAnunciante\":59,\"DuracionReal\":10,\"DespuesHorarioProtMenor\":true,\"BebidasAlcoholicas\":true,\"VigenciaDesde\":\"2019-03-01T00:00:00\",\"VigenciaHasta\":\"2019-03-31T00:00:00\",\"IdPrograma\":0,\"CodigoTipoMaterial\":\"COM\",\"PathImage\":\"\",\"IdMaterialComercial\":0,\"Version\":0,\"Observaciones\":\"Test 3 Observaciones\",\"RegistroAFSCA\":\"\",\"Codigo\":null,\"Productos\":[{\"Producto\":{\"Nombre\":null,\"Descripcion\":null,\"IdFamilia\":0,\"Codigo\":\"d65947fc-ef3c-4fe6-9cc7-460b0c5e769b\",\"Version\":0,\"Anunciantes\":null}},{\"Producto\":{\"Nombre\":null,\"Descripcion\":null,\"IdFamilia\":0,\"Codigo\":\"e68c99f1-290c-4b6f-bba6-3940d2830056\",\"Version\":0,\"Anunciantes\":null}}],\"TiposPublicidad\":[\"TANDA\",\"PNT\"]}"; HttpContent contentPost = new StringContent(aux, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(Route, contentPost).Result; MaterialTestModel materialResult = response.Content.ReadAsAsync <MaterialTestModel>().Result; Assert.IsTrue(materialResult != null); if (materialResult != null) { Assert.IsTrue(!string.IsNullOrEmpty(materialResult.Codigo)); } } }