Ejemplo n.º 1
0
        public static void VerifySearchByDateField(ResourceId resource, ValidTestCases testCase, string fieldName, Directions direction, string currentDateTime, string timezone, int numRecords, HrbcRecordCreator hrbcRecordCreator)
        {
            SearchValue searchValue1    = null;
            SearchValue searchValue2    = null;
            DateTime    dateTimeGreater = DateTime.Parse(currentDateTime);
            DateTime    dateTimeLess    = DateTime.Parse(currentDateTime);

            if (testCase == ValidTestCases.EqualsTo)
            {
                searchValue1 = searchValue2 = SearchValue.CreateDate(currentDateTime);
            }
            else
            if (testCase == ValidTestCases.Greater)
            {
                searchValue1 = SearchValue.CreateDate(currentDateTime);
                searchValue2 = SearchValue.CreateDate(dateTimeGreater.AddMinutes(numRecords - 1).ToString(SearchConstants.SearchApiFullDateTemplate));
            }
            else
            {
                searchValue2 = SearchValue.CreateDate(currentDateTime);
                searchValue1 = SearchValue.CreateDate(dateTimeLess.AddMinutes(-numRecords).ToString(SearchConstants.SearchApiFullDateTemplate));
            }

            var request = SearchRequestComposer.GetBuilderWithRestrictions(resource).DateFilter($"{resource.ToString()}.{fieldName}", OperatorType.Between, timezone, searchValue1, searchValue2);

            request.Conditions.OrderBy = GetOrderByType(resource, fieldName, direction);
            var handler  = new DefaultManager();
            var response = handler.Send <SearchResponse>(request);

            PrAssert.That(response, PrIs.SuccessfulResponse());

            Assertions[direction](response.Result.Items, resource, hrbcRecordCreator, numRecords);
        }
        public void ItemStateReadValidFieldTests(ItemState state, Enums.ResourceType resourceType, string field)
        {
            var request = RequestParams(state, field, resourceType);

            ValidTestCases.GetTotalMinMaxOfRecords(state, resourceType, records.Data, recordsIn.Data, deletedRecords.Data, out int total, out ulong min, out ulong max);
            PerformTest(resourceType, request, state, min, max, total);
        }
Ejemplo n.º 3
0
        private void VerifyData(ResourceId resourceId, ValidTestCases inputType)
        {
            PrivateApiResponse <RecordsGetResponseItem> originalRecordData = null;

            switch (inputType)
            {
            case ValidTestCases.BaseId:
                //Read base id existed
                originalRecordData = GetResultRecordData(resourceId, new int[] { GetRecordId(resourceId, 1) });
                PrAssert.That(originalRecordData.Result.Total, Is.EqualTo(1), "Base id does not existed in database!");
                break;

            case ValidTestCases.MergeId:
                //Read merge id is not existed
                originalRecordData = GetResultRecordData(resourceId, new int[] { GetRecordId(resourceId, 4) });
                PrAssert.That(originalRecordData, PrIs.WithHttpCode(System.Net.HttpStatusCode.InternalServerError));
                break;

            case ValidTestCases.ArrayMergeId:
                //Read array merge id are not existed
                originalRecordData = GetResultRecordData(resourceId, new int[] { GetRecordId(resourceId, 6), GetRecordId(resourceId, 7) });
                PrAssert.That(originalRecordData, PrIs.WithHttpCode(System.Net.HttpStatusCode.InternalServerError));
                break;

            case ValidTestCases.Mapping:
                //Read elements are correct value

                string[] keys = ValuesMapper[resourceId].Keys.ToArray();

                originalRecordData = GetResultRecordData(resourceId, new int[] { GetRecordId(resourceId, 8) }, keys);

                string     keyValue    = string.Empty;
                string     recordValue = string.Empty;
                List <int> ids         = new List <int>();

                foreach (var record in originalRecordData.Result.Items)
                {
                    foreach (var key in keys)
                    {
                        keyValue = ValuesMapper[resourceId][key].ToString();

                        if (key == $"{resourceId.ToString()}.P_Phase")
                        {
                            recordValue = JsonConvert.DeserializeObject <List <int> >(record[key].ToString()).Single().ToString();
                            keyValue    = OptionsClientReader.Data.Single().Value.RecordId.ToString();
                        }
                        else if (key.Contains("P_UpdatedBy") || key.Contains("P_RegisteredBy") || key.Contains("P_Owner"))
                        {
                            recordValue = JsonConvert.DeserializeObject <List <int> >(record[key].ToString()).Single().ToString();
                        }
                        else
                        {
                            recordValue = record[key].ToString();
                        }
                        PrAssert.That(recordValue, Is.EqualTo(keyValue), "Field value is not correct!");
                    }
                }
                break;
            }
        }
Ejemplo n.º 4
0
        public void MergeValid(ResourceId resourceId, ValidTestCases inputType)
        {
            var mergeRequest = GetParameters(resourceId, inputType);
            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(resourceId, mergeRequest, HttpMethod.Post);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));

            //Waiting for merge task successed before verifing data
            Assert.That(GetQueueMergeStatus(response.Result.Id.ToString()), "The merging is not finished yet!");

            //Verify data
            VerifyData(resourceId, inputType);
        }
Ejemplo n.º 5
0
        public void ReadValidItemState(Enums.ResourceType resourceType, ValidTestCases.ItemState itemState, ValidTestCases.ValidParameterValue parameter, string suffix, int expectedCode)
        {
            var    list         = records.Data.Select(rec => rec.Value.Id);
            string resourceName = resourceType.ToResourceName();

            ValidTestCases.GetTotalMinMaxOfRecords(itemState, resourceType, records.Data, recordsIn.Data, deletedRecords.Data, out int total, out ulong min, out ulong max);
            Dictionary <string, object> urlParameters = new Dictionary <string, object>()
            {
                { ResourceHelper.Partition, AuthenticationInfoProvider.Current.DefaultPartition },
                { "condition", $"{resourceName}.P_Id:ge={min},{resourceName}.P_Id:le={max}," },
            };

            ValidTestCases.ItemStateMapper[itemState](urlParameters);

            SendAndVerifyResult(urlParameters, resourceType, parameter, suffix, expectedCode, min, max, total);
        }
Ejemplo n.º 6
0
        public void InternalValidTest(ValidTestCases inputType)
        {
            var creds             = AuthenticationInfoProvider.GetAuthSpecForCurrentTest();
            var adminUserPassword = creds.Companies.First().Value.Users.First().Password;
            var adminUserLogin    = creds.Companies.First().Value.Users.First().Login;
            var adminUserId       = creds.Companies.First().Value.Users.First().Metadata["userId"];
            var companyId         = creds.Companies.First().Value.Id;
            var companyName       = creds.Companies.First().Value.Name;

            creds.Dispose();

            var headerValue = inputType == ValidTestCases.ChangeOrderXidentityHeader ? $"SERVICE={DefaultService};CID={companyId};UID={adminUserId}"
                                           : $"CID={companyId};UID={adminUserId};SERVICE={ValidMapperValues[inputType]}";
            var internalHandler = new InternalApiManager(InitPrivateApiConnection(companyName, adminUserLogin, adminUserPassword));
            var response        = internalHandler.SendRequestWithIdentityHeader(InternalAuthRequest, "X-IDENTITY", headerValue, HttpMethod.Post);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
        }
Ejemplo n.º 7
0
        public void ReadHrbcCoreSessionByLoginValidTest(ValidTestCases inputType)
        {
            ApiResponse <HrbcCoreSessionResponse> response = null;
            var creds              = AuthenticationInfoProvider.GetAuthSpecForCurrentTest();
            var adminUserId        = creds.Companies.First().Value.Users.First().Metadata["userId"].ToString();
            var adminLogin         = creds.Companies.First().Value.Users.First().Login;
            var adminPassword      = creds.Companies.First().Value.Users.First().Password;
            var readSessionHandler = new HrbcCoreManager();

            var requestDefault = new Dictionary <string, string>()
            {
                ["companyId"] = CompanyId,
                ["userId"]    = NormalUserId,
                ["sessionId"] = readSessionHandler.GetDefaultSessionId(_testConnection),
            };

            if (ValidTestCases.LoginNormalUserSendRequestNormalUserId == inputType)
            {
                var request = new Dictionary <string, string>(requestDefault);
                response = readSessionHandler.LoginAndSendRequestWithOtherAccount <HrbcCoreSessionResponse>(CompanyName, NormalUserLogin, NormalUserPassword, HrbcCoreManager.GetSessionEndpoint, request);
                readSessionHandler.ReAuthenticate(CompanyName, adminLogin, adminPassword);
            }
            else
            {
                Dictionary <string, string> request = new Dictionary <string, string>();
                if (ValidTestCases.LoginAdminUserSendRequestNormalUserId == inputType)
                {
                    request = requestDefault;
                }
                else
                {
                    request           = new Dictionary <string, string>(requestDefault);
                    request["userId"] = adminUserId;
                }
                response = readSessionHandler.SendHrbcCoreSession <HrbcCoreSessionResponse>(_testConnection, request, System.Net.Http.HttpMethod.Get);
            }
            creds.Dispose();

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(HttpStatusCode.OK));
            PrAssert.That(response.Result.Status, PrIs.EqualTo("OK"));
        }
Ejemplo n.º 8
0
        public void ReadHrbcCoreTmpCompanyInfoValidTest(UserType userType, ValidTestCases inputType)
        {
            ApiResponse <HrbcCoreTmpCompanyInfoResponse> response = null;
            var creds              = AuthenticationInfoProvider.GetAuthSpecForCurrentTest();
            var companyName        = creds.Companies.First().Value.Metadata["companyName"].ToString();
            var companyLoginId     = creds.Companies.First().Value.Name;
            var adminLogin         = creds.Companies.First().Value.Users.First().Login;
            var adminPassword      = creds.Companies.First().Value.Users.First().Password;
            var dbInfoHost         = creds.Companies.First().Value.Metadata["dbInfoHost"].ToString();
            var dbInfoPort         = creds.Companies.First().Value.Metadata["dbInfoPort"].ToString();
            var dbInfoUserName     = creds.Companies.First().Value.Metadata["dbInfoUserName"].ToString();
            var dbInfoPassword     = creds.Companies.First().Value.Metadata["dbInfoPassword"].ToString();
            var companyInfoHandler = new HrbcCoreManager();

            var requestDefault = new Dictionary <string, string>()
            {
                ["companyId"] = CompanyId
            };

            if (inputType != ValidTestCases.Default)
            {
                requestDefault["fullMode"] = ValidMapperValues[inputType].ToString().ToLower();
            }

            if (UserType.User == userType)
            {
                var request = new Dictionary <string, string>(requestDefault);
                response = companyInfoHandler.LoginAndSendRequestWithOtherAccount <HrbcCoreTmpCompanyInfoResponse>(CompanyName, NormalUserLogin, NormalUserPassword, HrbcCoreManager.GetTmpCompanyInfoEndpoint, request);
                companyInfoHandler.ReAuthenticate(CompanyName, adminLogin, adminPassword);
            }
            else
            {
                response = companyInfoHandler.SendHrbcCoreTmpCompanyInfo <HrbcCoreTmpCompanyInfoResponse>(_testConnection, requestDefault, System.Net.Http.HttpMethod.Get);
            }
            creds.Dispose();

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(HttpStatusCode.OK));
            //Verify data
            VerifyData(response, inputType, new CompanyInfo(CompanyId, companyName, companyLoginId, $"PRC{CompanyId}", dbInfoHost, dbInfoPort, dbInfoUserName, dbInfoPassword));
        }
Ejemplo n.º 9
0
        public void ValidApplicationInfoTests(ValidTestCases testcase, UserType usertype)
        {
            ApiResponse <HrbcApplicationInfoResponse.SuccessResponse> response = null;
            var connection = AuthApiConnection.GetConnectionForCurrentTest();
            var appHandler = new ApplicationManager();
            var request    = new Dictionary <string, string>()
            {
                ["myapp"] = testcase.GetHashCode().ToString()
            };

            if (UserType.User == usertype)
            {
                connection.DeAuthenticate();
                connection.Authenticate(CompanyName, NormalUserLogin, NormalUserPassword);
            }

            response = appHandler.ReadHrbcApplicationInfo <HrbcApplicationInfoResponse.SuccessResponse>(request);
            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(HttpStatusCode.OK));
            foreach (var app in response.Result.AppInfo.TakeWhile(item => item.ApplicationID == long.Parse(AppInfo.Metadata[ApplicationID].ToString())))
            {
                VerifyAppData(app, AppInfo);
            }
        }
Ejemplo n.º 10
0
        public static void BulkUpdateDateForRecordsCreator(HrbcRecordCreator RecordsCreator, string date, ValidTestCases testCase, int numRecords = 0)
        {
            var      bulkManager = new BulkUpdateManager();
            DateTime dateTime    = DateTime.Parse(date);

            int plusMinutes = 0;

            foreach (ResourceId resource in Utils.Resources())
            {
                for (var i = 0; i < numRecords; i++)
                {
                    if (testCase == ValidTestCases.Less)
                    {
                        plusMinutes = -(numRecords - i);
                    }
                    else if (testCase == ValidTestCases.Greater)
                    {
                        plusMinutes = i;
                    }

                    var recordId = RecordsCreator.Data[$"{resource}{i}"].Id;
                    var response = bulkManager.BulkUpdate <BulkUpdateResponse>(GetBulkUpdateContent(resource, new List <ulong> {
                        recordId
                    }, dateTime.AddMinutes(plusMinutes).ToString(SearchConstants.SearchApiFullDateTemplate)), System.Net.Http.HttpMethod.Post);
                    PrAssume.That(response, PrIs.SuccessfulResponse());

                    if (GetBulkUpdateQueueStatus(response.Result.Id.ToString()))
                    {
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private Dictionary <string, object> GetParameters(ResourceId resourceId, ValidTestCases inputType)
        {
            var mapping = new Dictionary <string, object>
            {
                [$"{resourceId.ToString()}.P_Name"] = new Dictionary <string, object>
                {
                    ["Value"] = "TEST FROM NAM"
                },

                [$"{resourceId.ToString()}.P_Owner"] = new Dictionary <string, object>
                {
                    ["Value"] = 1
                },
            };

            var parameters = new Dictionary <string, object>
            {
                ["baseId"]   = GetRecordId(resourceId, 1),
                ["mergedId"] = new List <string> {
                    GetRecordId(resourceId, 2).ToString()
                },
                ["mapping"] = mapping
            };

            int indexClient = 1;

            switch (inputType)
            {
            case ValidTestCases.BaseId:
            {
                mapping[$"{resourceId.ToString()}.P_Id"] = new Dictionary <string, object>()
                {
                    ["Value"] = GetRecordId(resourceId, 1)
                };
                return(parameters);
            }

            case ValidTestCases.MergeId:
            {
                parameters["baseId"]   = GetRecordId(resourceId, 3);
                parameters["mergedId"] = new List <string>()
                {
                    GetRecordId(resourceId, 4).ToString()
                };
                mapping[$"{resourceId.ToString()}.P_Id"] = new Dictionary <string, object>()
                {
                    ["Value"] = GetRecordId(resourceId, 3)
                };
                indexClient = 3;
                break;
            }

            case ValidTestCases.ArrayMergeId:
                parameters["baseId"]   = GetRecordId(resourceId, 5);
                parameters["mergedId"] = new List <string>()
                {
                    GetRecordId(resourceId, 6).ToString(), GetRecordId(resourceId, 7).ToString()
                };
                mapping[$"{resourceId.ToString()}.P_Id"] = new Dictionary <string, object>()
                {
                    ["Value"] = GetRecordId(resourceId, 5)
                };
                indexClient = 5;
                break;

            case ValidTestCases.Mapping:
                parameters["baseId"]   = GetRecordId(resourceId, 8);
                parameters["mergedId"] = new List <string>()
                {
                    GetRecordId(resourceId, 9).ToString()
                };
                indexClient = 8;

                var mappingResources = new Dictionary <ResourceId, Dictionary <string, object> >
                {
                    [ResourceId.Client]    = ClientValues,
                    [ResourceId.Recruiter] = RecruiterValues,
                };

                foreach (var mappingResource in mappingResources[resourceId])
                {
                    mapping[mappingResource.Key] = new Dictionary <string, object>()
                    {
                        ["Value"] = mappingResource.Value
                    };
                }
                mapping[$"{resourceId.ToString()}.P_Id"] = new Dictionary <string, object>()
                {
                    ["Value"] = GetRecordId(resourceId, 8)
                };

                break;
            }

            if (ResourceId.Recruiter == resourceId)
            {
                mapping.Add($"{resourceId.ToString()}.P_Client", new Dictionary <string, object>()
                {
                    ["Value"] = GetRecordId(ResourceId.Client, indexClient)
                });
            }

            return(parameters);
        }
Ejemplo n.º 12
0
        private void VerifyData(ApiResponse <HrbcCoreTmpCompanyInfoResponse> response, ValidTestCases inputType, CompanyInfo companyInfo)
        {
            var creds     = AuthenticationInfoProvider.GetAuthSpecForCurrentTest();
            var adminName = creds.Companies.First().Value.Users.First().Metadata["name"].ToString();

            creds.Dispose();

            if (inputType == ValidTestCases.Default || inputType == ValidTestCases.False)
            {
                PrAssert.That(response.Result.Name, PrIs.Null);
            }
            else
            {
                PrAssert.That(response.Result.Name, PrIs.EqualTo(companyInfo.Name));
            }

            PrAssert.That(response.Result.CompanyLoginId, PrIs.EqualTo(companyInfo.CompanyLoginId));
            PrAssert.That(response.Result.CatalogName, PrIs.EqualTo(companyInfo.CatalogName));
            PrAssert.That(response.Result.DbInfoHost, PrIs.EqualTo(companyInfo.DbInfoHost));
            PrAssert.That(response.Result.DbInfoPort, PrIs.EqualTo(companyInfo.DbInfoPort));
            PrAssert.That(response.Result.DbInfoUserName, PrIs.EqualTo(companyInfo.DbInfoUserName));
            PrAssert.That(response.Result.DbInfoPassword, PrIs.EqualTo(companyInfo.DbInfoPassword));
            PrAssert.That(response.Result.Id, PrIs.EqualTo(companyInfo.Id));
        }