private static Dictionary <string, object> DefaultBulkCreateParameters(ResourceId resource, string fieldName, string fieldValue)
 {
     return(new Dictionary <string, object>
     {
         ["create"] = new Dictionary <string, object>
         {
             ["tag"] = resource.ToString().ToLower(),
             ["title"] = resource.ToString().ToLower(),
             ["entries"] = new List <Dictionary <string, object> >
             {
                 new Dictionary <string, object>
                 {
                     ["resource"] = resource.ToString().ToLower(),
                     ["merge"] = new Dictionary <string, object>
                     {
                         ["records"] = new Dictionary <string, object>
                         {
                             ["ids"] = new List <string> {
                                 "1"
                             },
                             ["phpSearch"] = string.Empty
                         },
                         ["field"] = "P_Owner"
                     },
                     ["fields"] = new Dictionary <string, object>
                     {
                         [fieldName] = fieldValue
                     }
                 }
             }
         }
     });
 }
        public void ValidCustomActionReplaceTest(ResourceId resourceId)
        {
            var requestUrl    = "http://hrbc1-web.localvm/{{" + resourceId.ToString() + ".P_Id}}";
            var expectedId    = resourceId == ResourceId.None ? 0 : RecordsCreator.Data[resourceId].Id;
            var expectUrl     = $"http://hrbc1-web.localvm/{expectedId}";
            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(), "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");
            if (resourceId != ResourceId.None && resourceId != ResourceId.Contract)
            {
                PrAssert.That(replaceResponse.Result.Url, PrIs.EqualTo(expectUrl), "Can not create custom action");
            }
        }
Пример #3
0
        private static BulkUpdateProperties GetBulkUpdateContent(ResourceId resource, List <ulong> ids, int index, string testDateTime, TestCoreFramework.Enums.FieldType type, HrbcFieldCreator fieldCreator)
        {
            Func <ResourceId, KeyValuePair <object, FieldPropertyCollection>, KeyValuePair <string, FieldContent> > userFieldDataGenerator = (resourceId, x)
                                                                                                                                             => new KeyValuePair <string, FieldContent>(x.Value.Name, new FieldContent {
                Content = testDateTime
            });
            var fields = fieldCreator.Data.Where(x => x.Value.Field.Resource == resource)
                         .Select(x => userFieldDataGenerator(resource, x))
                         .Concat(new List <KeyValuePair <string, FieldContent> > {
                new KeyValuePair <string, FieldContent>(SearchConstants.FieldTypeToApplicationFieldNameMap[type], new FieldContent {
                    Content = testDateTime
                })
            })
                         .Concat(SearchConstants.SystemFieldsValues[resource].Where(x => type == x.Key).Select(field => new KeyValuePair <string, FieldContent>(field.Value, new FieldContent {
                Content = testDateTime
            })))
                         .ToDictionary(pair => pair.Key, pair => pair.Value);
            var bulkUpdate = new BulkUpdateProperties();

            bulkUpdate.Create                       = new Create();
            bulkUpdate.Create.Resource              = resource.ToString();
            bulkUpdate.Create.Tag                   = resource.ToString();
            bulkUpdate.Create.Records               = new Records();
            bulkUpdate.Create.Records.Ids           = ids;
            bulkUpdate.Create.Records.PhpSearch     = string.Empty;
            bulkUpdate.Create.Fields                = fields;
            bulkUpdate.Create.CheckPhasePermissions = true;
            return(bulkUpdate);
        }
        public void DeletableUserFields(ResourceId resourceId)
        {
            var fieldHandler = new FieldManager();
            var response     = fieldHandler.DeleteField(FieldCreator.Data[resourceId.ToString()].Field.ToAlias());

            PrAssert.That(response, PrIs.SuccessfulResponse(), $"Delete an user field operation was not successful. HTTP response code is {response.HttpStatusCode}");
            VerifyFieldNotExist(FieldCreator.Data[resourceId.ToString()].Field.ToAlias());
        }
Пример #5
0
 public void TestInvalidComputeFieldValueTwoParams(ResourceId resourceId, string fieldValuePair1, string fieldValuePair2, string targetField)
 {
     PerformTestInvalid(resourceId, targetField,
                        new Dictionary <string, object>
     {
         [$"{resourceId.ToString()}.{fieldValuePair1}_Dup1"] = FirstValue,
         [$"{resourceId.ToString()}.{fieldValuePair2}_Dup2"] = SecondValue
     });
 }
Пример #6
0
        public void TestValidComputeFieldValueCustomField(ResourceId resourceId, Operations op, string fieldValuePair1, string fieldValuePair2, string targetField)
        {
            var expression = GenerateExpression(resourceId, op, fieldValuePair1, fieldValuePair2);

            PerformTestValid(resourceId, op, targetField,
                             new Dictionary <string, object>
            {
                [$"{resourceId.ToString()}.{fieldValuePair1}"] = FirstValue,
                [$"{resourceId.ToString()}.{fieldValuePair2}"] = SecondValue
            }, expression);
        }
 public void TestInvalidComputationAffectedFieldTwoParams(ResourceId resourceId, string targetAffectedField, string targetNotAffectedField, string targetField)
 {
     PerformTestInvalid(resourceId, targetField,
                        new Dictionary <string, object> {
         [targetAffectedField] = TargetAffectedValue
     },
                        new Dictionary <string, object>
     {
         [$"{resourceId.ToString()}.{targetAffectedField}_Dup1"]    = FirstValue,
         [$"{resourceId.ToString()}.{targetNotAffectedField}_Dup2"] = SecondValue
     });
 }
        public void SearchSystemApplicationFieldCore(ResourceId resourceId, string field, SearchDateFieldCases.TestCases cases, bool isAsc)
        {
            var expectedOperator = cases == SearchDateFieldCases.TestCases.EqualsTo ? OperatorType.Eq : cases == SearchDateFieldCases.TestCases.Less ? OperatorType.Lt : OperatorType.Gt;
            var requestBuilder   = SearchRequestComposer.GetBuilderWithRestrictions(resourceId)
                                   .WithSort(isAsc, $"{resourceId.ToString()}.{field}");
            var request = requestBuilder.DateFilter($"{resourceId.ToString()}.{field}", expectedOperator,
                                                    "Asia/Tokyo", CreateDateTime.ToString(SearchConstants.SearchApiFullDateTemplate));
            var handler  = new DefaultManager();
            var response = handler.Send <SearchResponse>(request);

            SearchDateFieldCases.VerifySearchResult(response, resourceId, cases, $"{resourceId.ToString()}.{field}", isAsc, RecordsCreator, NumRecordsEachCase, DateTimeResponseFormat);
        }
        public void TestValidComputationAffectedCustomField(ResourceId resourceId, Operations op, string targetAffectedField, string targetNotAffectedField, string targetField)
        {
            var expression = GenerateExpression(resourceId, op, targetAffectedField, targetNotAffectedField);

            PerformTestValid(resourceId, op, targetField,
                             new Dictionary <string, object> {
                [targetAffectedField] = TargetAffectedValue
            },
                             new Dictionary <string, object>
            {
                [$"{resourceId.ToString()}.{targetAffectedField}"]    = FirstValue,
                [$"{resourceId.ToString()}.{targetNotAffectedField}"] = SecondValue
            }, expression);
        }
Пример #10
0
 public override void GetResourceReadOnly(EngineRequest request, ResourceId resource)
 {
     CheckInitialization();
     Logger.Storage.Debug("Getting a read-only version of the resource '" + resource.ToString() + "'...");
     EngineMethods.GetResourceReadOnly act = new EngineMethods.GetResourceReadOnly(request, resource);
     act.Execute();
 }
Пример #11
0
 public override void CheckoutResource(EngineRequest request, ResourceId resource)
 {
     CheckInitialization();
     Logger.Storage.Debug("Checking out the resource '" + resource.ToString() + "'");
     EngineMethods.CheckoutResource act = new EngineMethods.CheckoutResource(request, resource);
     act.Execute();
 }
Пример #12
0
        public void ValidCreateFieldOptionalProperties(ResourceId resourceId, Properties.Alias alias, Properties.Caption caption, Properties.Search search, Properties.Match match, Properties.Web web, Properties.Highlight highlight, Properties.Require require, Properties.Default defaultProperty, Properties.Min min, Properties.Max max, Properties.Scale scale)
        {
            var handler     = new DefaultManager();
            var properties  = NumberHelpers.GenerateProperties(NumberFieldTestData.NumberFieldType, Properties.Label.Max, caption, search, match, highlight, require, defaultProperty, min, max, scale);
            var createParam = new Dictionary <string, object>
            {
                [Properties.Parameters.Resource.GetEnumStringValue()]   = resourceId.ToString().ToLower(),
                [Properties.Parameters.Alias.GetEnumStringValue()]      = "",
                [Properties.Parameters.Properties.GetEnumStringValue()] = properties
            };

            CommonMapperValue.AliasMapperValue[alias](createParam);
            var request = new Dictionary <string, object>
            {
                [Properties.Parameters.Create.GetEnumStringValue()] = createParam
            }.ToJson();

            PrAssert.That(request, PrIs.Not.EqualTo(string.Empty));
            var response = handler.Send <FieldCreateResponse>(FieldManager.FieldHandlingRelativeUrl, request, HttpMethod.POST);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not Create Field");
            var fieldHandler = new FieldManager();
            var readResponse = fieldHandler.GetFieldDetails(response.Result.Id);

            CommonHelpers.DeleteField(new[] { response.Result.Id });
            PrAssert.That(readResponse, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not Read Field");
            PrAssert.That(readResponse.Result.Values.Count, PrIs.EqualTo(1), "Can not read Field");
            PrAssert.That(readResponse.Result.Values.First().Value.Properties[Properties.PropertyName.SType.GetEnumStringValue()], PrIs.EqualTo($"{NumberFieldTestData.NumberFieldType}"), "Not as expected s.type");
            PrAssert.That(readResponse.Result.Values.First().Value.Properties[Properties.PropertyName.Label.GetEnumStringValue()], PrIs.EqualTo(CommonMapperValue.LabelMapperValue[Properties.Label.Max]), "Not as expected d.label.ja");
            NumberHelpers.VerifyProperties(readResponse.Result.Values.First().Value.Properties, properties);
        }
Пример #13
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;
            }
        }
Пример #14
0
        public static string UpdateDuplicateRequest(ResourceId resourceId, Guid guid, Guid otherGuid, Dictionary <string, object> properties, Dictionary <string, object> otherProperties, Enum param, Enums.ValidDuplicated dupType)
        {
            var strParam = param.GetEnumStringValue();

            DuplicateParam(strParam, properties, otherProperties, dupType);
            var updateInfos = new Dictionary <string, object>
            {
                [Parameters.Resource.GetEnumStringValue()]   = resourceId.ToString().ToLower(),
                [Parameters.Properties.GetEnumStringValue()] = new Dictionary <string, object>(properties)
            };

            DuplicateParam(strParam, updateInfos, otherProperties, dupType);
            var guidInfos = new Dictionary <string, object>
            {
                [guid.ToString()]      = new Dictionary <string, object>(updateInfos),
                [otherGuid.ToString()] = new Dictionary <string, object>(updateInfos)
            };

            DuplicateParam(strParam, guidInfos, updateInfos, dupType);
            if (!param.Equals(Parameters.Guid))
            {
                guidInfos.Remove(otherGuid.ToString());
            }
            var request = new Dictionary <string, object>
            {
                [Parameters.Update.GetEnumStringValue()] = new Dictionary <string, object>(guidInfos)
            };
            var key = guidInfos.FirstOrDefault().Key;

            guidInfos[key == guid.ToString() ? otherGuid.ToString() : key] = new Dictionary <string, object>(updateInfos);
            guidInfos.Remove(key);
            DuplicateParam(strParam, request, guidInfos, dupType);

            return(ReplaceDuplicate(request.ToJson(), strParam));
        }
        public void NotDeletableApplicationFields(ResourceId resourceId)
        {
            var fieldHandler = new FieldManager();
            var response     = fieldHandler.DeleteField($"{resourceId.ToString()}.{ApplicationFields}");

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(HttpStatusCode.BadRequest).And.ErrorCode((int)ResultCode.NotPermitted));
        }
Пример #16
0
        public void TestInvalidSpecialRecommend(ResourceId resource)
        {
            var handler  = new DefaultManager(CreateNewApiConnection());
            var request  = GenerateRecommendRequest(resource.ToString().ToLower());
            var response = handler.Send <object>(RecommendEndpoint, JsonConvert.SerializeObject(request), HttpMethod.POST);

            Assert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Пример #17
0
 public static Dictionary <string, object> GenerateUpdateParam(ResourceId resourceId, Dictionary <string, object> properties)
 {
     return(new Dictionary <string, object>
     {
         [Properties.Parameters.Resource.GetEnumStringValue()] = resourceId.ToString().ToLower(),
         [Properties.Parameters.Properties.GetEnumStringValue()] = properties
     });
 }
Пример #18
0
        public void TestRegisterByOtherHttpMethod(ResourceId resource, HttpMethod inputType)
        {
            var handler  = new DefaultManager(CreateNewApiConnection());
            var request  = GenerateRegisterRequest(ValidOperation.Put.ToString().ToLower());
            var response = handler.Send <object>($"{RegisterEndpoint}{resource.ToString().ToLower()}s", JsonConvert.SerializeObject(request), inputType, ContentType);

            Assert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.NotFound));
        }
Пример #19
0
        private Task <IVault> GetVaultAsync()
        {
            var session = AzureResourceService.AzureSessionService
                          .CreateSession(ResourceId.SubscriptionId);

            return(session.Vaults
                   .GetByIdAsync(ResourceId.ToString()));
        }
Пример #20
0
        public void TestValidRegisterReturnJsonContentType(ResourceId resource)
        {
            var connection = CreateNewApiConnection();
            var request    = GenerateRegisterRequest(ValidOperation.Put.ToString().ToLower());
            var response   = connection.SendAsync($"{RegisterEndpoint}{resource.ToString().ToLower()}s", JsonConvert.SerializeObject(request), System.Net.Http.HttpMethod.Post).Result;

            Assert.That(response.Content.Headers.ContentType.MediaType, PrIs.EqualTo("application/json"));
        }
Пример #21
0
        public void TestValidDuplicateRegister(ResourceId resource, Enums.ValidDuplicated dup, RegisterParameters param)
        {
            var handler  = new DefaultManager(CreateNewApiConnection());
            var request  = DuplicateValues[dup]()[param.GetEnumStringValue()];
            var response = handler.Send <object>($"{RegisterEndpoint}{resource.ToString().ToLower()}s", request, HttpMethod.POST, ContentType);

            Assert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent));
        }
Пример #22
0
        public void TestValidRegister(ResourceId resource, ValidOperation op)
        {
            var handler  = new DefaultManager(CreateNewApiConnection());
            var request  = GenerateRegisterRequest(op.ToString().ToLower());
            var response = handler.Send <object>($"{RegisterEndpoint}{resource.ToString().ToLower()}s", JsonConvert.SerializeObject(request), HttpMethod.POST, ContentType);

            Assert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent));
        }
Пример #23
0
 private static void AddDefaultRequestValue(ResourceId resourceId, List <KeyValuePair <string, string> > request)
 {
     if (resourceId != ResourceId.None)
     {
         request.Add(new KeyValuePair <string, string>(Selects.SelectParam, "resource"));
         request.Add(new KeyValuePair <string, string>(Selects.WhereParam, resourceId.ToString().ToLower()));
     }
 }
Пример #24
0
        public PrivateApiResponse <T> GetEntryRecords <T>(ResourceId resourceType, HttpMethod httpMethod, string contentType = "application/json")
        {
            string urlPath = string.Format(EntryEndpoint, resourceType.ToString().ToLower());

            using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Get Entry by {urlPath}"))
            {
                return(ProcessResponseWithContent <T>(Connection.SendAsync(urlPath, httpMethod, contentType).Result));
            }
        }
Пример #25
0
        public PrivateApiResponse <T> MergeRecords <T>(ResourceId resourceType, IEnumerable <KeyValuePair <string, string> > parameters, HttpMethod httpMethod, string contentType = "application/json")
        {
            string urlPath = string.Format(MergeEndpoint, resourceType.ToString().ToLower());

            using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Merge records with {urlPath}"))
            {
                return(ProcessResponseWithContent <T>(Connection.SendAsync(urlPath, parameters, httpMethod, contentType).Result));
            }
        }
Пример #26
0
 public static Dictionary <string, string> GetOriginalSearchConditionsParameters(ResourceId resource, string wrongType = null)
 {
     return(new Dictionary <string, string>()
     {
         ["type"] = wrongType == null?resource.ToString().ToLower() : wrongType,
                        ["menu_id"] = MenuId[resource].ToString(),
                        ["limit"] = "10"
     });
 }
Пример #27
0
        public PrivateApiResponse <T> GetEntryRecords <T>(ResourceId resourceType, IEnumerable <KeyValuePair <string, string> > parameters, IEnumerable <MultipartFormContentItem> content, HttpMethod httpMethod)
        {
            string urlPath = string.Format(EntryEndpoint, resourceType.ToString().ToLower());

            using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Get Entry by {urlPath}"))
            {
                return(ProcessResponseWithContent <T>(Connection.SendAsync(urlPath, parameters, content, httpMethod).Result));
            }
        }
Пример #28
0
        public PrivateApiResponse <T> MergeRecords <T>(ResourceId resourceType, IEnumerable <MultipartFormContentItem> content, HttpMethod httpMethod)
        {
            string urlPath = string.Format(MergeEndpoint, resourceType.ToString().ToLower());

            using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Merge records with {urlPath}"))
            {
                return(ProcessResponseWithContent <T>(Connection.SendAsync(urlPath, content, httpMethod).Result));
            }
        }
Пример #29
0
 public static Dictionary <string, object> GenerateComputeFieldValueRequest(ResourceId resourceId, string targetField, Dictionary <string, object> fieldValuePairs)
 {
     return(new Dictionary <string, object>
     {
         [ComputeAffectedField.ResourceId.GetEnumStringValue()] = (int)resourceId,
         [ComputeAffectedField.TargetField.GetEnumStringValue()] = $"{resourceId.ToString()}.{targetField}",
         [ComputeAffectedField.FieldValuePairs.GetEnumStringValue()] = fieldValuePairs
     });
 }
        public void ResourceRouteParamterValidationTest(ResourceId resource, VerificationCaseType testCase, PrivateApiResponseCode expectedCode, Action <SearchRequest, Func <string, string> > requestUpdater, string caseDescription)
        {
            var request = SearchRequestComposer.GetBuilder(resource, $"{(int)resource}")
                          .Filter(searchType: SearchRequestComposer.SearchTypeMap[SearchFilterType.NumOperator],
                                  field: $"{resource.ToString()}.P_Id",
                                  op: SearchRequestComposer.OperatorTypeMap[OperatorType.Eq],
                                  value: SearchValue.CreateConst("1234"));

            PerformValidationTest(request, resource, testCase, expectedCode, requestUpdater);
        }
Пример #31
0
 /// <summary>
 /// Initialise the resource.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="map"></param>
 /// <param name="id"></param>
 public Resource(FolderAsset parent, ResourceMap map, ResourceId id)
     : base(parent, id.ToString())
 {
     Map = map;
     Id = id;
 }