Ejemplo n.º 1
0
        public bool APICopyCourseForExistingOrganization(object[] lStrvalue)
        {
            string header = string.Empty;

            string     statusCode   = string.Empty;
            string     result       = string.Empty;
            clsGeneric oGeneric     = new clsGeneric();
            string     URI          = string.Empty;
            Hashtable  htblTestData = new Hashtable();

            htblTestData = oGeneric.GetTestData(lStrvalue);
            bool _Flag = false;

            CopyCourseWithExistingOrganization oCopyCourseWithExistingOrganization = new CopyCourseWithExistingOrganization();
            SuperAdminCourseRecords            oSuperAdminCourseRecords            = new SuperAdminCourseRecords();

            List <SuperAdminCourseRecords> lstRecords = new List <SuperAdminCourseRecords>();

            string[] strCourses = htblTestData["CourseName"].ToString().Split(',');
            try
            {
                foreach (string strCourseID in strCourses)
                {
                    SuperAdminCourseRecords course = new SuperAdminCourseRecords();
                    course.NumberOfSeats      = htblTestData["Seats"].ToString();
                    course.SuperAdminCourseID = string.Empty;
                    course.SuperAdminCourseID = strCourseID;
                    lstRecords.Add(course);
                }

                oCopyCourseWithExistingOrganization.UserID = htblTestData["USERID"].ToString();
                oCopyCourseWithExistingOrganization.SuperAdminCourseRecords = lstRecords;
                oCopyCourseWithExistingOrganization.OrderID      = htblTestData["USERID"].ToString();
                oCopyCourseWithExistingOrganization.PurchaseDate = htblTestData["PurchaseDate"].ToString();
                #region
                if ((htblTestData["orgID"].ToString().Trim() == ""))
                {
                    lstRecords.Clear();

                    lstRecords = new List <SuperAdminCourseRecords>();

                    foreach (string strCourseID in strCourses)
                    {
                        SuperAdminCourseRecords course = new SuperAdminCourseRecords();
                        course.NumberOfSeats      = htblTestData["Seats"].ToString();
                        course.SuperAdminCourseID = string.Empty;
                        course.SuperAdminCourseID = strCourseID;
                        lstRecords.Add(course);
                    }

                    oCopyCourseWithExistingOrganization.SuperAdminCourseRecords = lstRecords;
                    oCopyCourseWithExistingOrganization.UserID = clsAPI.userid;

                    GetAPICredentials oGetAPICredentials = new GetAPICredentials();

                    oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", ApplicationSettings.APIURI() + clsAPI.orgCredential.Replace("$", clsAPI.orgID), oCopyCourseWithExistingOrganization, "H2", "", "");

                    var        orgCredential = JsonConvert.DeserializeObject <GetAPICredentials>(result);
                    Crypto3DES _des          = new Crypto3DES(ApplicationSettings.EComModuleEncKey());

                    _ecomTransactionKey = _des.Decrypt3DES(orgCredential.TransactionKey);
                    _ecomLoginKey       = _des.Decrypt3DES(orgCredential.LoginID);
                    oGeneric.GetApiResponseCodeData(out statusCode, out result, htblTestData["MethodType"].ToString(), ApplicationSettings.APIURI() + htblTestData["URI"].ToString(), oCopyCourseWithExistingOrganization, htblTestData["HeaderType"].ToString(), _ecomLoginKey, _ecomTransactionKey);
                }
                else
                {
                    #endregion
                    _ecomTransactionKey = ApplicationSettings.TransactionKey();
                    _ecomLoginKey       = ApplicationSettings.APILoginID();
                    clsAPI.orgID        = htblTestData["orgID"].ToString();
                    oGeneric.GetApiResponseCodeData(out statusCode, out result, htblTestData["MethodType"].ToString(), ApplicationSettings.APIURI() + htblTestData["URI"].ToString(), oCopyCourseWithExistingOrganization, htblTestData["HeaderType"].ToString(), _ecomLoginKey, _ecomTransactionKey);
                }

                if (htblTestData["TestCaseType"].ToString().ToUpper() == "POSITIVE")
                {
                    if (result.ToUpper().Contains("!DOCTYPE"))
                    {
                        clsGlobalVariable.strExceptionReport = "Resource not found";
                        return(true);
                    }

                    if (statusCode.Contains("201"))
                    {
                        header = htblTestData["HeaderType"].ToString();

                        RequestID oRequest = JsonConvert.DeserializeObject <RequestID>(result);
                        URI    = ApplicationSettings.APIURI() + clsAPI.apiStatus + oRequest.requestID.ToString();
                        result = string.Empty;
                        oGeneric.GetApiResponseCodeData(out statusCode, out result, "Get", URI, oCopyCourseWithExistingOrganization, "H2", "", "");
                        AccountRequests oRequestData  = JsonConvert.DeserializeObject <AccountRequests>(result);
                        int             courseCounter = 0;

                        foreach (string strCourseID in strCourses)
                        {
                            if (strCourseID == oRequestData.CourseResults[courseCounter].SuperAdminCourseID.ToString())
                            {
                                courseCounter++;
                                _Flag = true;
                            }
                            else
                            {
                                courseCounter++;
                                _Flag = false;
                            }
                        }

                        if (_Flag == true)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        var oError = JsonConvert.DeserializeObject <List <SuperAdminCoursePushDownError> >(result);
                        clsGlobalVariable.strExceptionReport = "Invalid URI: Error Code: " + oError[0].ErrorCode + "\n Error Description: " + oError[0].ErrorMessage;
                        return(false);
                    }
                }
                else if (htblTestData["TestCaseType"].ToString().ToUpper() == "NEGATIVE")
                {
                    if (result.ToUpper().Contains("!DOCTYPE"))
                    {
                        clsGlobalVariable.strExceptionReport = "Resource not found";
                        return(true);
                    }

                    if (statusCode.Contains("4") || statusCode.Contains("5"))
                    {
                        if (statusCode.Contains("404") || statusCode.Contains("500") || statusCode.Contains("405"))
                        {
                            clsGlobalVariable.strExceptionReport = "Resource not found";
                            return(true);
                        }
                        var oError = JsonConvert.DeserializeObject <List <SuperAdminCoursePushDownError> >(result);
                        SuperAdminCoursePushDownErrorCode oErrorCode = new SuperAdminCoursePushDownErrorCode();
                        foreach (string strErrorCode in oErrorCode.coursePushDownErrorCode)
                        {
                            if (strErrorCode == oError[0].ErrorCode)
                            {
                                _Flag = true;
                            }
                        }
                        if (_Flag == true)
                        {
                            return(true);
                        }
                        else
                        {
                            clsGlobalVariable.strExceptionReport = "Negative Case Failed!";
                            return(false);
                        }
                    }
                    else
                    {
                        clsGlobalVariable.strExceptionReport = "Resource or URI Wrong!";
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                clsException.ExceptionHandler(e, iWebdriver, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name);

                return(false);
            }
        }