Example #1
0
        public static Dictionary <string, object> GetMapping(ResourceId resourceId, ulong baseId, ulong clientId)
        {
            var mapping = new Dictionary <string, object>()
            {
                [$"{resourceId.ToAlias()}.P_Id"] = new Dictionary <string, object>()
                {
                    ["value"] = baseId,
                },
                [$"{resourceId.ToAlias()}.P_Name"] = new Dictionary <string, object>()
                {
                    ["value"] = MappingName,
                },
                [$"{resourceId.ToAlias()}.P_Owner"] = new Dictionary <string, object>()
                {
                    ["value"] = "1",
                },
            };

            if (resourceId == ResourceId.Recruiter)
            {
                mapping.Add($"{resourceId.ToAlias()}.P_Client", new Dictionary <string, object>()
                {
                    ["value"] = clientId.ToString()
                });
            }
            return(mapping);
        }
Example #2
0
        public static void VerifyAclSettings(ResourceId resourceId, bool isReadOnly, HrbcFieldCreator customFieldsLocal)
        {
            var fieldHandler = new FieldManager();
            var request      = new Dictionary <string, string>()
            {
                ["s[0]"]        = "acl",
                ["s[1]"]        = "resource",
                ["w[resource]"] = resourceId.ToAlias(),
                ["s[2]"]        = "alias",
                ["w[alias]"]    = customFieldsLocal.Data[$"{resourceId}"].Field.Name,
            };
            var response = fieldHandler.GetFieldGuid(request, HttpMethod.GET.ToNetHttpMethod());

            PrAssert.That(response, PrIs.SuccessfulResponse(), $"Read a field operation was not successful. HTTP response code is {response.HttpStatusCode}");
            PrAssert.That(response.Result.Result, PrIs.Not.Empty.Or.Null, "The search result is empty");
            foreach (var searchItem in response.Result.Result)
            {
                if (isReadOnly)
                {
                    PrAssert.That(searchItem.Acl.Data.Count, PrIs.EqualTo(1), "The search result acl is not as expected");
                }
                else
                {
                    PrAssert.That(searchItem.Acl.Data.Count, PrIs.EqualTo(2), "The search result acl is not as expected");
                }
            }
        }
        public void ReadInvalidGenericRecordTests(ResourceId resource, InvalidReadGenericRecord condition)
        {
            var recordHandler = new GenericRecordManager();
            var requestDic    = new Dictionary <string, object>()
            {
                ["resource"] = resource.GetHashCode(),
                ["idList"]   = new int[] { Common.ReadRecordsId(resource, FirstSystemRecord) },
                ["fields"]   = string.Format("{0}.P_PhaseDate,{1}.P_Name", resource.ToAlias(), resource.ToAlias())
            };

            if (condition == InvalidReadGenericRecord.NotLogin)
            {
                PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate();
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrivateApiConnection.GetConnectionForCurrentTest().Authenticate();
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.Unauthorized));
            }
            else if (condition == InvalidReadGenericRecord.TransactionError)
            {
                // This case unable to reproduce at this time.
            }
            else if (condition == InvalidReadGenericRecord.WrongFieldId)
            {
                requestDic["idList"] = WrongId;
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.InternalServerError));
            }
            else
            {
                requestDic["idList"] = null;
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
            }
        }
Example #4
0
        private static void ReadAndVerifyData()
        {
            var fieldAliases = FieldNames.Aggregate((a, b) => $"{Resource.ToAlias()}.{a}" + "," + $"{Resource.ToAlias()}.{b}");

            var requestDic = new Dictionary <string, object>()
            {
                ["resource"] = Resource,
                ["idList"]   = SelectionRecordIds(Record, Filter, Resource, RecordCreator),
                ["fields"]   = fieldAliases
            };
            var recordHandler = new GenericRecordManager();
            var response      = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, HttpMethod.Post);

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

            foreach (var fieldName in FieldNames)
            {
                foreach (var item in response.Result.Items.Select(item => item[$"{Resource.ToAlias()}.{fieldName}"].ToString()))
                {
                    var fieldType = GetFieldTypes();
                    if (Filter == Filters.Append && (fieldType[fieldName].ToString().ContainsStrings(new string[] { InputType.SingleLineText.ToString(), InputType.MultiLinesText.ToString() })))
                    {
                        PrAssert.That(item, PrIs.EqualTo($"{Fields[fieldName]} {Fields[fieldName]}"));
                    }
                    else
                    {
                        if (fieldType[fieldName].ToString().ContainsStrings(new string[] { InputType.UserList.ToString(), InputType.OptionMultipleItems.ToString() }))
                        {
                            PrAssert.That(item.Contains(Fields[fieldName].ToString().Split(',')[0]) && item.Contains(Fields[fieldName].ToString().Split(',')[1]));
                        }
                        else
                        if (fieldType[fieldName].ToString().ContainsStrings(new string[] { "System", InputType.OptionPhase.ToString(), InputType.OptionOnlyItem.ToString() }))
                        {
                            PrAssert.That(item.Contains(Fields[fieldName].ToString()));
                        }
                        else
                        {
                            PrAssert.That(item, PrIs.EqualTo(Fields[fieldName]));
                        }
                    }
                }
            }
        }
Example #5
0
        public void ValidUpdateMenuTest(ResourceId resource, SublistMenuTestData.LabelValue labelValue, MainMenuTestData.Condition condition, MainMenuTestData.Alias alias, MainMenuTestData.Join join)
        {
            var handler     = new DefaultManager();
            var requestJson = GetUpdateMenuRequest(SublistMenuTestData.ValidMenuIdMapper[resource], (int)resource, GetLabelValue(SublistMenuTestData.ValidLabelMapper[labelValue]));

            requestJson["conditions"] = GetConditionValue($"{resource.ToAlias()}.{MainMenuTestData.ValidAliasMapper[alias]("")}", join.ToString().ToUpper(), new List());
            var updateResponse = handler.SendAsync <object>(SublistMenuTestData.MenuEndPoint, requestJson.ToJson(), HttpMethod.PUT).Result;

            PrAssert.That(updateResponse, PrIs.SuccessfulResponse(), "Not able to update a menu");
        }
Example #6
0
        public void ValidCreateMenuTest(ResourceId resource, SublistMenuTestData.LabelValue labelValue, MainMenuTestData.Condition condition, MainMenuTestData.Alias alias, MainMenuTestData.Join join)
        {
            var handler     = new DefaultManager();
            var requestJson = GetCreateMenuRequest((int)resource, GetLabelValue(SublistMenuTestData.ValidLabelMapper[labelValue]));

            requestJson["conditions"] = GetConditionValue($"{resource.ToAlias()}.{MainMenuTestData.ValidAliasMapper[alias]("")}", join.ToString().ToUpper(), new List());
            var createResponse = handler.SendAsync <CreateMenuResponse>(SublistMenuTestData.MenuEndPoint, requestJson.ToJson(), HttpMethod.POST).Result;

            PrAssert.That(createResponse, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Not able to create a menu");
            PrAssert.That(createResponse.Result.Id, PrIs.Not.Null.And.Not.Empty, "Not able to create a menu");
        }
Example #7
0
 public static string ToAlias(this ResourceType type, ResourceId resourceId)
 {
     if (type == ResourceType.Standard)
     {
         return(resourceId.ToAlias());
     }
     else
     {
         return(type.ToAlias());
     }
 }
        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");
        }
Example #9
0
        public static bool CheckExistedRecordId(ResourceId resource, int[] recordId)
        {
            var requestDic = new Dictionary <string, object>()
            {
                ["resource"] = resource.GetHashCode(),
                ["idList"]   = new int[] { recordId.GetEnumerator().GetHashCode() },
                ["fields"]   = string.Format("{0}.P_Id,{1}.P_Name", resource.ToAlias(), resource.ToAlias())
            };

            var recordHandler = new GenericRecordManager();
            var result        = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, HttpMethod.Post);

            return(result.IsSuccess ? false : true);
        }
Example #10
0
        private static void VerifyExistedId(ResourceId resource, List <string> ids)
        {
            var requestDic = new Dictionary <string, object>()
            {
                ["resource"] = resource,
                ["idList"]   = ids,
                ["fields"]   = $"{resource.ToAlias()}.P_Id"
            };
            var recordHandler = new GenericRecordManager();
            var response      = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, System.Net.Http.HttpMethod.Post);

            PrAssume.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(response.Result.Total, PrIs.EqualTo(0), "The record is not deleted out database.");
        }
Example #11
0
        public void ValidMultiResourceCreatePhaseEntryWithResourceName(ResourceId firstResource, ResourceId secondResource)
        {
            var handler         = new DefaultManager();
            var result          = new List <Dictionary <string, object> >();
            var phaseFirstItem  = CreatePhaseItem(firstResource.ToAlias(), CreateDataItem(RootPhaseOption.Data[firstResource].Id), RecordsCreator.Data[$"{firstResource}{0}"].Id);
            var phaseSecondItem = CreatePhaseItem(secondResource.ToAlias(), CreateDataItem(RootPhaseOption.Data[secondResource].Id), RecordsCreator.Data[$"{secondResource}{0}"].Id);

            result.Add(phaseFirstItem);
            result.Add(phaseSecondItem);
            var request = new Dictionary <string, object>()
            {
                [ParamCreate] = result
            }.ToJson();

            SendRequestAndVerifyResources(handler, request);
        }
        public void ValidResourceUpdatePhaseEntryWithResourceName(ResourceId resource)
        {
            var handler = new DefaultManager();
            var result  = new List <Dictionary <string, object> >();
            Dictionary <string, object> dataItem        = UpdateDataItem(RootPhaseOption.Data[resource].Id);
            Dictionary <string, object> phaseFirstItem  = CreatePhaseItem((int)resource, dataItem, PreparedPhaseId.Data[resource].Data[0]);
            Dictionary <string, object> phaseSecondItem = CreatePhaseItem(resource.ToAlias(), dataItem, PreparedPhaseId.Data[resource].Data[1]);

            result.Add(phaseFirstItem);
            result.Add(phaseSecondItem);
            var request = new Dictionary <string, object>()
            {
                [ParamUpdate] = result
            }.ToJson();

            SendRequestAndVerifyResources(handler, request);
        }
 public static string GetOptionPhase(ResourceId resourceId)
 {
     return($"Option.P_{resourceId.ToAlias()}Phase");
 }
 public IContentBuilder AddField(HrbcField field, object data)
 {
     if (field.ResourceType != ResourceType.Standard || field.Resource != resourceId)
     {
         throw new ArgumentException(String.Format("Field must belong to standard resource {0}", resourceId.ToAlias()), "field");
     }
     checkValue(data);
     content.Add(field, data);
     return(this);
 }
Example #15
0
 public void ValidDeletePhaseEntryWithResourceName(ResourceId resource)
 {
     SendRequestAndVerify(resource.ToAlias(), PreparedPhaseId.Data[resource].Data[1]);
 }
Example #16
0
        public void ValidCreatePhaseEntryWithResourceName(PhaseEntryTestData.ValidNumberOfPhase numberOfPhase, ResourceId resource, PhaseEntryTestData.ValidPhaseOption id, PhaseEntryTestData.ValidPhaseDate date, PhaseEntryTestData.ValidPhaseMemo memo)
        {
            var handler = new DefaultManager();
            var request = new Dictionary <string, object>()
            {
                [ParamCreate] = CreatePhaseEntryRequest(resource, (int)numberOfPhase, resource.ToAlias(), SecondRecordsCreator, RootPhaseOption.Data, id, PhaseEntryTestData.validDateMapper[date], memo)
            }.ToJson();

            PrAssert.That(request, PrIs.Not.EqualTo(string.Empty));
            SendRequestAndVerify(numberOfPhase, resource, handler, request);
        }