Exemple #1
0
        //public static ApiWrapper ApiGetWrap(string urlApp, ApiWrapper wrap)
        //{
        //    string urlApi = urlApp + "/" + wrap.EntitySetName + "/Get";
        //    var result = CallApi(urlApi, "r", wrap);
        //    return Newtonsoft.Json.JsonConvert.DeserializeObject<bool>(result);
        //}

        public static bool ApiLogin(string urlApp, ApiWrapper wrap)
        {
            string urlApi = urlApp + "/SFSdotNetFrameworkSecurity/Account/ValidateLogin";
            var    result = CallApi(urlApi, wrap);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <bool>(result));
        }
Exemple #2
0
        public static T ApiGetByKey <T>(string urlApp, ApiWrapper wrap)
        {
            string urlApi = urlApp + "/" + wrap.EntitySetName + "/Get";
            var    result = CallApi(urlApi, "r", wrap);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(result));
        }
Exemple #3
0
        public static T ApiRequest <T>(string url, ApiWrapper wrap)
        {
            string urlApi = url;
            var    result = CallApi(urlApi, "r", wrap);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(result));
        }
Exemple #4
0
        private ApiWrapper <TModel> GetWrapper <TModel>() where TModel : class
        {
            ApiWrapper <TModel> apiWrapper = new ApiWrapper <TModel>();

            apiWrapper.Username  = ConfigurationManager.AppSettings["username"];
            apiWrapper.Password  = ConfigurationManager.AppSettings["password"];
            apiWrapper.CompanyId = ConfigurationManager.AppSettings["companyId"];
            return(apiWrapper);
        }
Exemple #5
0
        public void RegisterUserOnlyFullName()
        {
            string urlApp    = System.Configuration.ConfigurationManager.AppSettings["urlApp"];
            string IdCompany = System.Configuration.ConfigurationManager.AppSettings["companyId"];
            string appKey    = "SFSServiceDesk"; // ID de aplicación

            //string entitySetName = "bonCustomers";
            //UserDataRegister data = new SFS.ServiceDesk.Client.Models.UserDataRegister();
            #region Register user with App
            //data = new SFS.ServiceDesk.Client.Models.UserDataRegister();
            //data.Email = Utils.GetString(10) + "@mail.com";
            //data.Password = Utils.GetString(10);
            //data.FirstName = "Name" + Utils.GetString(6);
            //data.FirstName = "Last" + Utils.GetString(6);
            //data.AppKey = appKey; // tiene autoservicio, relacionado con una empresa + dominio
            //var registerResultWithApp = Services.CallApi(urlApp + "/Api/Register", "POST", data);

            //Result<UserDataResponse> resultRegisterWithApp = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<UserDataResponse>>(registerResultWithApp);
            //Assert.AreEqual(resultRegisterWithApp.status, "success");
            //Assert.IsNotNull(resultRegisterWithApp.data.IdCompany);

            #endregion

            #region Login
            UserDataLogin dataLogin = new SFS.ServiceDesk.Client.Models.UserDataLogin();
            dataLogin          = new SFS.ServiceDesk.Client.Models.UserDataLogin();
            dataLogin.Username = System.Configuration.ConfigurationManager.AppSettings["username"];
            dataLogin.Password = System.Configuration.ConfigurationManager.AppSettings["password"];
            var loginResult = Services.CallApi(urlApp + "/Api/Login", "POST", dataLogin);

            Result <UserDataWithToken> resultLogin = Newtonsoft.Json.JsonConvert.DeserializeObject <Result <UserDataWithToken> >(loginResult);
            Assert.AreEqual(resultLogin.status, "success");
            Assert.IsNotNull(resultLogin.data.Token);
            #endregion

            #region Get Items of ProfileEvents

            // Se espera que ocurra un error de token inválido porque la contraseña ha sido cambiada

            ApiWrapper dataRequest = new ApiWrapper();

            var dataRequestTyped = new ApiWrapper <SDArea>();
            //dataRequestTyped.Item = new Client.Models.PageType() { ProfileType = 0, Name = Utils.GetString(10) };

            dataRequestTyped.Token     = resultLogin.data.Token;
            dataRequestTyped.CompanyId = IdCompany;
            var    result = Services.CallApi(urlApp + "/" + appKey + "/SDCases/Get?v=2&Fields=SDCaseHistories", "POST", (object)dataRequestTyped);
            string test   = result;

            // var resultGetItems = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileEvent>>(getItems);

            // Assert.AreEqual(resultGetItems.status, "success");



            #endregion
        }
Exemple #6
0
        public static T ApiGet <T>(string urlApp, ApiWrapper wrap)
        {
            string extra = "";

            if (wrap.AllFields == true)
            {
                extra = "allFields=1";
            }
            string urlApi = urlApp + "/" + wrap.EntitySetName + "/Get?" + extra;
            var    result = CallApi(urlApi, "r", wrap);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(result));
        }
Exemple #7
0
        public static string CallApi(string urlApi, string action, ApiWrapper wrap)
        {
            string         url     = urlApi; //"";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = Newtonsoft.Json.JsonConvert.SerializeObject(wrap);

            request.Headers.Add("Token", wrap.Token);
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();

            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            // Get the response.
            WebResponse response = request.GetResponse();

            // Display the status.
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();

            // Display the content.
            // Console.WriteLine(responseFromServer);
            // Clean up the streams.
            reader.Close();
            dataStream.Close();
            response.Close();

            return(responseFromServer);
        }
Exemple #8
0
        public static string ApiCreate(string urlApp, ApiWrapper wrap)
        {
            string urlApi = urlApp + "/" + wrap.EntitySetName + "/Create?rok=1";

            return(CallApi(urlApi, "c", wrap));
        }
Exemple #9
0
 //public static UserInfo ApiLoginAndGetUser(string urlApp, ApiWrapper wrap)
 //{
 //    string urlApi = urlApp + "/SFSdotNetFrameworkSecurity/Account/ValidateLoginAndGetUser";
 //    var result = CallApi(urlApi, wrap);
 //    return Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(result);
 //}
 public static string CallApi(string urlApi, ApiWrapper wrap)
 {
     return(CallApi(urlApi, "r", wrap));
 }