Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            var restTemplate = new RestTemplate("http://localhost:12340");

            restTemplate.MessageConverters.Add(new JsonHttpMessageConverter());
            var data = restTemplate.GetForMessage <Something>("/aaa");

            Console.WriteLine("is data received null? {0}", null == data);
            Console.WriteLine(data.Body.StringData);
            Console.WriteLine(data.Body.IntData);

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Ejemplo n.º 2
0
        public static IEnumerable <Employe> GetAllEmployes()
        {
            string autenticacion = string.Empty;
            HttpResponseMessage <string> respuesta;
            HttpHeaders  encabezado     = new HttpHeaders();
            RestTemplate marco          = new RestTemplate();
            HttpEntity   entidadEntrada = new HttpEntity();

            IEnumerable <Employe> employes;

            marco = PrepararMarcoServicio();

            respuesta = marco.GetForMessage <string>(DataResources.EmployesData);
            employes  = JsonConvert.DeserializeObject <IEnumerable <Employe> >(respuesta.Body);
            return(employes);
        }
Ejemplo n.º 3
0
        public void GetForMessage()
        {
            Uri        requestUri    = new Uri("http://example.com");
            HttpMethod requestMethod = HttpMethod.GET;

            Expect.Call <bool>(converter.CanRead(typeof(string), null)).Return(true);
            MediaType         textPlain  = new MediaType("text", "plain");
            IList <MediaType> mediaTypes = new List <MediaType>(1);

            mediaTypes.Add(textPlain);
            Expect.Call <IList <MediaType> >(converter.SupportedMediaTypes).Return(mediaTypes);
            Expect.Call <IClientHttpRequest>(requestFactory.CreateRequest(requestUri, requestMethod)).Return(request);
            HttpHeaders requestHeaders = new HttpHeaders();

            Expect.Call <HttpHeaders>(request.Headers).Return(requestHeaders).Repeat.Any();
            ExpectGetResponse();
            Expect.Call <bool>(errorHandler.HasError(requestUri, requestMethod, response)).Return(false);
            HttpHeaders responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = textPlain;
            Expect.Call <HttpHeaders>(response.Headers).Return(responseHeaders).Repeat.Any();
            ExpectHasMessageBody(responseHeaders);
            Expect.Call <bool>(converter.CanRead(typeof(string), textPlain)).Return(true);
            String expected = "Hello World";

            Expect.Call <string>(converter.Read <string>(response)).Return(expected);
            Expect.Call <HttpStatusCode>(response.StatusCode).Return(HttpStatusCode.OK);
            Expect.Call <string>(response.StatusDescription).Return("OK");

            mocks.ReplayAll();

            HttpResponseMessage <String> result = template.GetForMessage <string>("http://example.com");

            Assert.AreEqual(expected, result.Body, "Invalid GET result");
            Assert.AreEqual(textPlain, result.Headers.ContentType, "Invalid Content-Type");
            Assert.AreEqual(textPlain.ToString(), requestHeaders.GetSingleValue("Accept"), "Invalid Accept header");
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode, "Invalid status code");
            Assert.AreEqual("OK", result.StatusDescription, "Invalid status description");

            mocks.ReplayAll();
        }
Ejemplo n.º 4
0
        public ActionResult ObtainPacientInfo(string IdPacient)
        {
            var InfoPacient = _proxy.GetForMessage <string>($"{ConstantesApi.getPacientInfoUri}?IdPacient={Server.UrlEncode(IdPacient)}");

            return(Content(InfoPacient.Body, "application/json"));
        }