示例#1
0
        public void TestSearchMultipleSearchConditionUsingMultiFieldPhase(string fieldName1, string fieldName2, string condition1, string condition2)
        {
            Enums.ResourceType resourceType = Enums.ResourceType.Client;
            string             id           = records.Data[$"{resourceType.ToPrivateEnum()}{fields.First()}data2{1}"].Id.ToString();

            var phaseList = new Dictionary <int, string> {
                { 0, testData["data1"] }, { 1, testData["data2"] }, { 2, testData["data3"] },
                { 3, testData["data4"] }, { 4, testData["data5"] }, { 5, testData["data6"] }
            }.Select(item =>
            {
                var phase = FieldHelper.CreatePhaseInstance(resourceType, id);
                phase.DictionaryValues[fieldName1] = item.Value;
                phase.DictionaryValues[fieldName2] = item.Value;
                return(phase);
            }).ToList();

            List <string> ids = PublicApiAdapter.CreateAdapterForDefaultConnection().WriteSuccess(phaseList);

            Assume.That(ids, Is.Not.Null.And.Not.Empty, string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, resourceType));

            Dictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { DateTimeValidator.FieldAlias1, fieldName1 },
                { DateTimeValidator.FieldAlias2, fieldName2 },
                { DateTimeValidator.Condition1, condition1 },
                { DateTimeValidator.Condition2, condition2 },
                { DateTimeValidator.ConditionValue1, testData["data2"] },
                { DateTimeValidator.ConditionValue2, testData["data4"] },
            };

            //Read & verify the field's value
            SystemFieldTypeHelper.VerifySearchDatePhase(resourceType, parameters, false);
        }
        public void TestMultipleSearch1NumberField(string fieldName, string condition1, string condition2)
        {
            condition1 = condition1.ToLowerString();
            condition2 = condition2.ToLowerString();

            string conditionValue1 = string.Empty;
            string conditionValue2 = string.Empty;

            conditionValue1 = PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName, indexFirstPhaseList);  //Get phase value by public api because read phase private api could not retrieve RegistrationDate, Option alias
            conditionValue2 = PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName, indexSecondPhaseList); //Get phase value by public api because read phase private api could not retrieve RegistrationDate, Option alias

            //Read & verify the field's value
            if (fieldName == PhaseApiFields.RegistrationDate || fieldName == PhaseApiFields.UpdateDate || fieldName == PhaseApiFields.Date)
            {
                Dictionary <string, string> conditionParameters = new Dictionary <string, string>()
                {
                    { DateTimeValidator.FieldAlias1, fieldName },
                    { DateTimeValidator.FieldAlias2, fieldName },
                    { DateTimeValidator.Condition1, condition1 },
                    { DateTimeValidator.Condition2, condition2 },
                    { DateTimeValidator.ConditionValue1, conditionValue1 },
                    { DateTimeValidator.ConditionValue2, conditionValue2 },
                };
                SystemFieldTypeHelper.VerifySearchDatePhase(defaultResource, conditionParameters, false);
            }
            else
            {
                string formatCond = DateTimeValidator.GetFormatCondition(fieldName, fieldName, condition1, condition2, conditionValue1, conditionValue2);

                Dictionary <string, object> parameters = new Dictionary <string, object>()
                {
                    { PhaseApiFields.Partition, AuthenticationInfoProvider.Current.DefaultPartition },
                    { PhaseApiFields.Resource, (int)defaultResource },
                    { PhaseApiFields.Condition, formatCond },
                    { PhaseApiFields.Field, fieldName },
                };
                ReadResponseData <Phase> result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess <Phase>(parameters);
                Assert.That(result.Code, Is.EqualTo(Enums.PublicAPIResultCode.Success), string.Format(Enums.Message.READ_RESOURCE_FAILED, nameof(Phase)));

                foreach (var item in result.Items)
                {
                    Assert.That(int.Parse(item.DictionaryValues[fieldName].ToString()), DateTimeValidator.ConditionsMap[condition1](int.Parse(conditionValue1), int.Parse(conditionValue2)).And.Matches(DateTimeValidator.ConditionsMap[condition2](int.Parse(conditionValue2), int.Parse(conditionValue1))), DateTimeValidator.ErrorMessage);
                }
            }
        }
        public void TestMultipleSearchMultipleNumberField(string fieldName1, string fieldName2, string condition1, string condition2)
        {
            condition1 = condition1.ToLowerString();
            condition2 = condition2.ToLowerString();

            if (fieldName1.Contains("Date") && fieldName2.Contains("Date"))
            {
                Dictionary <string, string> conditionParameters = new Dictionary <string, string>()
                {
                    { DateTimeValidator.FieldAlias1, fieldName1 },
                    { DateTimeValidator.FieldAlias2, fieldName2 },
                    { DateTimeValidator.Condition1, condition1 },
                    { DateTimeValidator.Condition2, condition2 },
                    { DateTimeValidator.ConditionValue1, PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName1, indexFirstPhaseList) },  //Get phase value by public api because read phase private api could not retrieve RegistrationDate, Option alias
                    { DateTimeValidator.ConditionValue2, PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName2, indexSecondPhaseList) }, //Get phase value by public api because read phase private api could not retrieve RegistrationDate, Option alias
                };
                SystemFieldTypeHelper.VerifySearchDatePhase(defaultResource, conditionParameters, false);
            }
            else
            {
                List <string> conditionValues = new List <string>();
                conditionValues.Add((PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName1, indexFirstPhaseList)));
                conditionValues.Add((PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName1, indexFirstPhaseList)));
                conditionValues.Add((PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName2, indexSecondPhaseList)));
                conditionValues.Add((PhaseHelper.GeneratePhaseNumberType(defaultResource, fieldName2, indexSecondPhaseList)));
                string formatCond = PhaseHelper.GetFormatConditionDifferentFields(fieldName1, fieldName2, condition1, condition2, conditionValues[0], conditionValues[1], conditionValues[2], conditionValues[3]);

                Dictionary <string, object> parameters = new Dictionary <string, object>()
                {
                    { PhaseApiFields.Partition, AuthenticationInfoProvider.Current.DefaultPartition },
                    { PhaseApiFields.Resource, (int)defaultResource },
                    { PhaseApiFields.Condition, formatCond },
                    { PhaseApiFields.Field, $"{fieldName1},{fieldName2}" },
                };
                ReadResponseData <Phase> result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess <Phase>(parameters);
                Assert.That(result.Code, Is.EqualTo(Enums.PublicAPIResultCode.Success), string.Format(Enums.Message.READ_RESOURCE_FAILED, nameof(Phase)));

                foreach (var item in result.Items)
                {
                    DateTimeValidator.ConditionalAssertions[condition1](item.DictionaryValues[fieldName1], conditionValues[0], conditionValues[1]);
                    DateTimeValidator.ConditionalAssertions[condition2](item.DictionaryValues[fieldName2], conditionValues[2], conditionValues[3]);
                }
            }
        }