public static void VerifySearchResult(PrivateApiResponse <SearchResponse> response, ResourceId resourceId, SearchDateFieldCases.TestCases cases, string fieldName, bool isAsc, HrbcRecordCreator RecordsCreator, int NumRecordsEachCase, string DateTimeResponseFormat) { PrAssert.That(response, PrIs.SuccessfulResponse(), "Search unsuccesfull"); PrAssert.That(response.Result.Items, PrIs.Not.Null.And.Not.Empty, "Null or Empty search response"); PrAssert.That(response.Result.Items.Count, PrIs.GreaterThanOrEqualTo(NumRecordsEachCase), "Unexpected numbers of search results"); List <int> ids = response.Result.Items; for (int i = (int)cases * NumRecordsEachCase; i < (int)cases * NumRecordsEachCase + NumRecordsEachCase; i++) { PrAssert.That(ids.Contains((int)RecordsCreator.Data[$"{resourceId}{i}"].Id), "The expected id is not in search result"); } var recordHandler = new RecordManager(); var res = recordHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource((Porters.TestCoreFramework.Enums.ResourceType)(int) resourceId) .WithIds(ids.ToArray()) .Fields(fieldName, $"{ resourceId}.P_Id") .Result); List <long> expectedIdsList; if (isAsc) { expectedIdsList = res.Result.Items.OrderBy(item => DateTime.ParseExact(item[fieldName].ToString(), DateTimeResponseFormat, System.Globalization.CultureInfo.InvariantCulture)).Select(s => (long)s[$"{resourceId}.P_Id"]).ToList(); } else { expectedIdsList = res.Result.Items.OrderByDescending(item => DateTime.ParseExact(item[fieldName].ToString(), DateTimeResponseFormat, System.Globalization.CultureInfo.InvariantCulture)).Select(s => (long)s[$"{resourceId}.P_Id"]).ToList(); } for (int i = 0; i < ids.Count; i++) { PrAssert.That(expectedIdsList[i], PrIs.EqualTo(ids[i]), "The search result is not order as expected"); } }
public static List <long> SortedProcessDataList(List <int> listResult, string orderField, string orderType, FieldType fieldType) { var recordHandler = new RecordManager(); var res = recordHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Process) .WithIds(listResult.ToArray()) .Fields(ProcessClose, ProcessId, ProcessPhase, ProcessPhaseDate, ProcessUpdateDate, ProcessRegistrationDate, ProcessExpectedClosingDate, ProcessExpectedSalesAmount, orderField) .Result); PrAssume.That(res, PrIs.SuccessfulResponse(), "Can not read Process records"); var result = GetDataList(res.Result.Items, orderField, fieldType).OrderBy(item => item.Close).ThenByDescending(item => item.Phase).ThenByDescending(item => item.PhaseDate); var sortedList = new List <ProcessData>(); if (orderField != ProcessId && orderField != string.Empty) { sortedList = ((orderType == "asc") ? result.ThenBy(item => item.OrderField) : result.ThenByDescending(item => item.OrderField)) .ThenByDescending(item => item.Id).ToList(); } else { sortedList = ((orderType == "asc") ? result.ThenBy(item => item.Id) : result.ThenByDescending(item => item.Id)).ToList(); } return(sortedList.Select(i => i.Id).ToList()); }
private PrivateApiResponse <RecordsGetResponseItem> GetResultRecordData(ResourceId resourceId, int[] recordIds, string[] keys = null) { var resourceType = (TestCoreFramework.Enums.ResourceType)(int) resourceId; return((new RecordManager()).ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(resourceType) .WithIds(recordIds) .Fields(keys == null ? new string[] { $"{resourceId.ToString()}.P_Id" } : keys) .Result)); }
private PrivateApiResponse <RecordsGetResponseItem> ReadRecords(TestCoreFramework.Enums.ResourceType readResource, int[] ids, string[] fields) { RecordManager recordHandler = new RecordManager(); return(recordHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(readResource) .WithIds(ids) .Fields(fields) .Result)); }
public void ValidSpecialCustomActionReplaceTest(ResourceId resourceId, string fieldName) { string fieldAlias = $"{resourceId.ToAlias()}.{fieldName}"; var recordHandler = new RecordManager(); var res = recordHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource((TestCoreFramework.Enums.ResourceType)(int) resourceId) .WithIds((int)RecordsCreator.Data[resourceId].Id) .Fields($"{resourceId.ToAlias()}.P_Id", fieldAlias) .Result); var recordValue = res.Result.Items[0]; if (fieldName.EndsWith("Date") || fieldName == "P_Owner") { recordValue[fieldAlias] = recordValue[fieldAlias].ToString().Replace("/", "-").Replace("[\r\n", "").Replace("\r\n]", "").Split('.')[0].Trim(); } var requestUrl = $"hrbc1-web.localvm/{{{{{fieldAlias}}}}}"; var expectUrl = $"hrbc1-web.localvm/{recordValue[fieldAlias].ToString()}"; var createRequest = CreateCustomActionTests.GetCreateRequest(requestUrl, CustomActionTestData.ValidLabelMapper[CustomActionTestData.ValidLabel.BothEnJa](CustomActionTestData.ValidLabelValueMapper[CustomActionTestData.ValidLabelValue.StringNoSpaceBoth]), CustomActionTestData.ValidPlaceValueMapper[CustomActionTestData.ValidPlaceValue.Client]); var hanlder = new CustomActionManager(); var response = hanlder.CustomAction <CreateCustomActionResponse>(createRequest, HttpMethod.POST.ToNetHttpMethod()); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not create custom action"); var resourceName = resourceId == ResourceId.Person ? "candidate" : resourceId.ToString().ToLower(); var replaceRequest = GetReplaceRequest(response.Result.Id, new Dictionary <string, object> { [resourceName] = resourceId == ResourceId.None ? 0 : RecordsCreator.Data[resourceId].Id, }); hanlder = new CustomActionManager(); var replaceResponse = hanlder.Replace <ReplaceCustomActionResponse>(replaceRequest, HttpMethod.POST.ToNetHttpMethod()); PrAssert.That(replaceResponse, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not create custom action"); var convertedUrl = WebUtility.UrlDecode(replaceResponse.Result.Url).Trim(); PrAssert.That(convertedUrl, PrIs.EqualTo(expectUrl), "Can not create custom action"); }
public void DetaultCrudTest() { var fieldHandler = new FieldManager(); var fields = fieldHandler.GetFieldGuid(new[] { "P_Name", "P_Owner", "A_TestSingleLineText" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client }) .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id)); //create var recordHandler = new RecordManager(); var request = RecordRequestComposer.ComposeCreateRequest() // creating a request object, using custom handlers .Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithField(fields["Client.P_Name"], "TestName -- CLIENT1") .WithField(fields["Client.P_Owner"], 1) .WithField(fields["Client.A_TestSingleLineText"], "TEST VALUE 1") .WithFieldSet(new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT 5", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 5" })) .Append(Porters.TestCoreFramework.Enums.ResourceType.Client, new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT2", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 2" }) .AppendMany(Porters.TestCoreFramework.Enums.ResourceType.Client, new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT3", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 3" }, new Dictionary <int, object> { [fields["Client.P_Name"]] = "TestName -- CLIENT4", [fields["Client.P_Owner"]] = 1, [fields["Client.A_TestSingleLineText"]] = "TEST VALUE 4" }) .Result; var response = recordHandler.WriteRecords(request); PrAssert.That(response, PrIs.SuccessfulResponse()); //read var res = recordHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithIds(response.Result.Ids.SelectMany(x => x).ToArray()) .Fields("Client.P_Name", "Client.P_Id", "Client.A_TestSingleLineText") .Result); PrAssert.That(res.Result.Total, Is.EqualTo(5)); PrAssert.That(res.Result.Items, Is.All.Matches <Dictionary <string, object> >(x => !string.IsNullOrEmpty(x["Client.A_TestSingleLineText"].ToString()))); //update recordHandler.UpdateRecords( RecordRequestComposer.ComposeUpdateRequest().Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .Append(x => x.WithId(response.Result.Ids[0][0]).AppendField(fields["Client.A_TestSingleLineText"], "NewTestValue 1")) .Append(x => x.WithId(response.Result.Ids[1][0]).AppendFields(new Dictionary <int, object> { [fields["Client.A_TestSingleLineText"]] = "NewTestValue 2" }))).Result); LogHelper.LoggerForCurrentTest.Info("Records are updated without exceptions."); // example of how to access log //delete recordHandler.DeleteRecords( RecordRequestComposer.ComposeDeleteRequest(Porters.TestCoreFramework.Enums.ResourceType.Client, response.Result.Ids.SelectMany(x => x))); }
public void UpdateFieldsTest() { const string FieldPropertyToModify = "d.label.ja"; var resource = ResourceId.Client; var aliases = new[] { "P_Country", "P_City", "P_Prefecture" }; var resetProgrammingCacheField = "P_Memo"; var connection = PrivateApiConnection.GetConnectionForCurrentTest(); var fieldHandler = new FieldManager(); var optionHandler = new OptionManager(); var aclHandler = new AclManager(); var recordsHandler = new RecordManager(); //PHASE1: preparing test data: reading and updating fields/options/acls/records var rawFields = fieldHandler.GetFieldGuid(new[] { "P_Country", "P_Phase", "P_PhaseDate" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client }) .Result.Result; var fields = rawFields.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id)); var guidFields = rawFields.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => x.Id); //fields fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> { ["d.label.ja"] = "MEMO" }); var originalFieldValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value); foreach (var alias in aliases) { fieldHandler.UpdateField(alias, ResourceId.Client, new Dictionary <string, object> { [FieldPropertyToModify] = $"UPDATE_{alias.ToUpper()}_1" }); } //options var data = optionHandler.SearchOption("Option.P_LanguageAbility"); var originalOptionValues = data.Result.Single().Children; foreach (var child in data.Result.Single().Children) { optionHandler.UpdateOption(child.Id, new Dictionary <string, object> { ["name"] = child.Alias }); } //acl var aclInfo = aclHandler.ReadAclInfo(guidFields["Client.P_Country"]); var originalAclInfo = aclInfo.Result[guidFields["Client.P_Country"]].Last().Value.Phases.ToDictionary(x => x.Key, x => new AclHandlingComponent.DataContract.AclResponseItem.PermissionItem { Permission = x.Value.Permission }); aclInfo.Result[guidFields["Client.P_Country"]].Last().Value.Phases.Select(x => x.Value.Permission = 20).ToArray(); aclHandler.SetFieldAcl(aclInfo.Result); //records var originalRecordData = recordsHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithIds(new[] { 10001 }) .Fields("Client.P_Country", "Client.P_Phase", "Client.P_PhaseDate") .Result); recordsHandler.UpdateRecords( RecordRequestComposer.ComposeUpdateRequest().Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .Append(x => x.WithId(10001).AppendField(fields["Client.P_Country"], "TestValue") .AppendField(fields["Client.P_Phase"], originalRecordData.Result.Items.Single()["Client.P_Phase"]) .AppendField(fields["Client.P_PhaseDate"], originalRecordData.Result.Items.Single()["Client.P_PhaseDate"]))).Result); connection.DeAuthenticate(); connection.DeleteAllCookies(); //MANUAL PART: switch DB, restart memcache System.Threading.Thread.Sleep(new TimeSpan(0, 5, 5)); connection.Authenticate(); //PART3: reading from new DB, making sure that all of values are default fieldHandler.UpdateField(resetProgrammingCacheField, ResourceId.Client, new Dictionary <string, object> { ["d.label.ja"] = "MEMO" }); // fields check var updatedValues = aliases.ToDictionary(x => x, x => fieldHandler.GetFieldDetails($"{resource}.{x}").Result.Values.Single().Value); foreach (var alias in aliases) { PrAssert.That(originalFieldValues[alias].Properties[FieldPropertyToModify], PrIs.EqualTo(updatedValues[alias].Properties[FieldPropertyToModify])); } //options check data = optionHandler.SearchOption("Option.P_LanguageAbility"); foreach (var child in data.Result.Single().Children) { PrAssert.That(child.Name, Is.EqualTo(originalOptionValues.Single(x => x.Id == child.Id).Name)); } //acl check aclInfo = aclHandler.ReadAclInfo(guidFields["Client.P_Country"]); foreach (var aclItem in originalAclInfo) { PrAssert.That(aclInfo.Result[guidFields["Client.P_Country"]].Last().Value.Phases[aclItem.Key].Permission, Is.EqualTo(aclItem.Value.Permission)); } //records check var recordsData = recordsHandler.ReadRecords( RecordRequestComposer.ComposeReadRequest() .ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithIds(new[] { 10001 }) .Fields("Client.P_Country", "Client.P_Phase", "Client.P_PhaseDate") .Result); PrAssert.That(recordsData.Result.Items.Single()["Client.P_Country"], Is.EqualTo(originalRecordData.Result.Items.Single()["Client.P_Country"])); }