public void IniciarSesion()
        {
            if (autorizado != null)
            {
                CerrarConexionVivanto();
            }

            disposedValue = false;
            cliente       = new XmlServiceClient(parametros.UrlBase);

            using (var httpResponse = cliente.Get <HttpWebResponse>("{0}/{1},{2},{3}".Fmt(parametros.UrlLogin, parametros.IdAplicacion, login.Usuario, login.Clave)))
            {
                var responseStream = httpResponse.GetResponseStream();
                var r2             = responseStream.ToUtf8String();
                var dd             = ServiceStack.Text.XmlSerializer.DeserializeFromString <List <Autorizado> >(r2);
                if (dd.Count > 0)
                {
                    autorizado = dd[0];
                    long prueba;
                    if (!long.TryParse(autorizado.IdUsuario, out prueba))
                    {
                        var msg = autorizado.IdUsuario;
                        autorizado = null;
                        throw new ExcepcionServicioVivanto(DirInfoLog, msg);
                    }

                    Log.Autorizado(DirInfoLog, "{0} {1}".Fmt(autorizado.IdUsuario, autorizado.Token));
                    return;
                }
            }
            throw new ExcepcionServicioVivanto(DirInfoLog, "Metodo de autenticación no retornó Autorizados");
        }
 private void CerrarConexionVivanto()
 {
     if (cliente != null)
     {
         using (cliente)
         {
             if (autorizado != null)
             {
                 try {
                     using (var httpResponse = cliente.Get <HttpWebResponse>("{0}/{1},{2},{3}".Fmt(parametros.UrlLogout, parametros.IdAplicacion, autorizado.IdUsuario, autorizado.Token)))
                     {
                         var responseStream = httpResponse.GetResponseStream();
                         var r2             = responseStream.ToUtf8String();
                         Log.Sesion(DirInfoLog, r2);
                     }
                 }
                 catch (Exception ex)
                 {
                     Log.Sesion(DirInfoLog, ex.Message);
                 }
                 autorizado = null;
             }
         }
         cliente = null;
     }
 }
        public void GetAllOrders()
        {
            //ARRANGE ---
            var client = new XmlServiceClient("http://localhost:50712/");

            //ACT  ------
            var orders = client.Get <OrdersResponse>("/orders");

            //ASSERT ----
            Assert.IsTrue(orders != null);
            Assert.IsTrue(orders.Orders.Count > 0);
        }
        public void GetOrdersByOrderId()
        {
            //ARRANGE ---
            const int ORDER_ID = 1;
            var       client   = new XmlServiceClient("http://localhost:50712/");

            //ACT  ------
            var order = client.Get <OrderResponse>("/orders/" + ORDER_ID);

            //ASSERT ----
            Assert.IsTrue(order != null);
            Assert.IsTrue(order.Id == ORDER_ID);
        }
        public void GetOrderItemByOrderId()
        {
            //ARRANGE ---
            var    ITEM_ID   = "2";
            var    client    = new XmlServiceClient("http://localhost:50712/");
            string ITEM_LINK = "/orders/1/items/2";

            //ACT  ------
            var item = client.Get <OrderItemResponse>(ITEM_LINK);

            //ASSERT ----
            Assert.IsNotNull(item != null);
            Assert.IsTrue(item.Id.ToString() == ITEM_ID);
        }
		public void Get_Xml_XmlCodifiedLanguages()
		{
			var repository = Substitute.For<ILanguageRepository>();
			Replacing(repository);
			repository.FindAll().Returns(new[] {"es", "da"});

			using (var client = new XmlServiceClient())
			{
				var response = client.Get<LanguagesResponse>(UrlFor("/languages"));
				Assert.That(response.ResponseStatus, Is.Null);
				Assert.That(response.Languages[0].Code, Is.EqualTo("es"));
				Assert.That(response.Languages[1].Code, Is.EqualTo("da"));
			}
		}
        public void GetOrderItemsByOrderId()
        {
            //ARRANGE ---
            int    ORDER_ID   = 1;
            string ITEMS_LINK = "/orders/" + ORDER_ID + "/items";

            var client = new XmlServiceClient("http://localhost:50712/");

            //ACT  ------
            var items = client.Get <OrderItemsResponse>(ITEMS_LINK);

            //ASSERT ----
            Assert.IsNotNull(items != null);
            Assert.IsNotNull(items.Items);
            Assert.IsTrue(items.Items.Count == 2);
        }