public void TestReadGeneralFieldSettingValidation(Enums.ResourceType resourceType, ReadInvalidInputTestData.ItemState itemState, string fieldName, FieldProperty fieldProperty, object val)
        {
            var parameters = new Dictionary <string, object>()
            {
                { DeletedDataFields.Partition, AuthenticationInfoProvider.Current.DefaultPartition },
                { DeletedDataFields.ItemState, itemState.ToLowerString() },
                { DeletedDataFields.Condition, $"{resourceType.ToResourceName()}.{fieldName}:eq={fieldValues[fieldName]}" }
            };

            var result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess(resourceType.ToString(), parameters);

            Assert.That(result.Code, MustBe.EqualTo(Enums.PublicAPIResultCode.Success), Enums.Message.WRONG_ERROR_CODE);
        }
Esempio n. 2
0
        public void TestMultipleSearch1Field(Enums.ResourceType resourceType, ReadInvalidInputTestData.ItemState itemState, string fieldName, string firstCondition, string secondCondition)
        {
            ItemStateHelper.SearchParameters searchParameters = null;
            List <XmlResource> result     = null;
            string             fieldAlias = $"{resourceType.ToResourceName()}.{fieldName}";
            var extraUrlParameters        = new Dictionary <string, object>();

            if (itemState != ReadInvalidInputTestData.ItemState.None)
            {
                extraUrlParameters.Add(DeletedDataFields.ItemState, itemState.ToLowerString());
            }

            var itemStateType       = itemState == ReadInvalidInputTestData.ItemState.None ? ReadInvalidInputTestData.ItemState.All : itemState;
            var extraConditionParam = new Dictionary <string, object>(extraUrlParameters);

            extraConditionParam["condition"] = $"{resourceType.ToResourceName()}.P_Id:ge={ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Min"]},{resourceType.ToResourceName()}.P_Id:le={ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Max"]}";

            //Result code
            var resultCode = (fieldName == DeletedDataFields.P_UpdateDate) && (itemState == ReadInvalidInputTestData.ItemState.Deleted || itemState == ReadInvalidInputTestData.ItemState.All) && (firstCondition.ContainsStrings(new string[] { DateTimeValidator.Le, DateTimeValidator.Lt }) && secondCondition.ContainsStrings(new string[] { DateTimeValidator.Le, DateTimeValidator.Lt }))
                             ? Enums.PublicAPIResultCode.DateTimeOutOfRange : Enums.PublicAPIResultCode.Success;

            //Read & verify data
            switch (fieldName)
            {
            case DeletedDataFields.P_UpdateDate:
                result           = ItemStateHelper.GetAllResults(resourceType, fieldAlias, 0, MaxCount, extraConditionParam).Items;
                searchParameters = new ItemStateHelper.SearchParameters(fieldAlias, fieldAlias, firstCondition, secondCondition,
                                                                        result[Util.GetRandomNumber(20, 50)].DictionaryValues[fieldAlias].ToString(),
                                                                        result[Util.GetRandomNumber(120, 150)].DictionaryValues[fieldAlias].ToString());
                ItemStateHelper.VerifySearchDate(resourceType, searchParameters, resultCode, extraUrlParameters, false);
                break;

            case DeletedDataFields.P_Id:
                searchParameters = new ItemStateHelper.SearchParameters(fieldAlias, fieldAlias, firstCondition, secondCondition,
                                                                        ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Min"] + RecordNum,
                                                                        ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Max"] - RecordNum);
                ItemStateHelper.VerifyMultiSearchOneFieldById(resourceType, searchParameters, extraUrlParameters);
                break;

            case DeletedDataFields.P_UpdateBy:
                result           = ItemStateHelper.GetAllResults(resourceType, fieldAlias, 0, 0, extraConditionParam).Items;
                searchParameters = new ItemStateHelper.SearchParameters(fieldAlias, fieldAlias, firstCondition, secondCondition,
                                                                        ((result[1].DictionaryValues[$"{fieldAlias}"] as XmlResource).DictionaryValues["User"] as XmlResource).DictionaryValues["User.P_Id"].ToString(),
                                                                        ((result[7].DictionaryValues[$"{fieldAlias}"] as XmlResource).DictionaryValues["User"] as XmlResource).DictionaryValues["User.P_Id"].ToString()
                                                                        );
                ItemStateHelper.VerifyMultiSearchOneFieldById(resourceType, searchParameters, extraUrlParameters);
                break;
            }
        }
        public void TestSearchItemState(Enums.ResourceType resourceType, ReadInvalidInputTestData.ItemState itemState, string fieldName, string condition, int resultCode)
        {
            string fieldAlias         = $"{resourceType.ToResourceName()}.{fieldName}";
            var    extraUrlParameters = new Dictionary <string, object>();

            if (itemState != ReadInvalidInputTestData.ItemState.None)
            {
                extraUrlParameters.Add(DeletedDataFields.ItemState, itemState.ToLowerString());
            }

            var extraConditionParam = new Dictionary <string, object>(extraUrlParameters);
            var itemStateType       = itemState == ReadInvalidInputTestData.ItemState.None ? ReadInvalidInputTestData.ItemState.All : itemState;

            extraConditionParam["condition"] = $"{resourceType.ToResourceName()}.P_Id:ge={ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Min"]},{resourceType.ToResourceName()}.P_Id:le={ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Max"]}";
            var result      = ItemStateHelper.GetAllResults(resourceType, fieldAlias, 0, MaxCount, extraConditionParam).Items;
            var fieldValues = ParameterValues[fieldName](result, resourceType).ToString();

            ItemStateHelper.SearchParameters searchParameters = new ItemStateHelper.SearchParameters(fieldAlias, string.Empty, condition, string.Empty, fieldValues, fieldValues);
            extraUrlParameters.Add(DeletedDataFields.Count, MaxCount);

            //Verify data
            ItemStateHelper.VerifySingleSearchItemsState(resourceType, searchParameters, resultCode, extraUrlParameters);
        }
Esempio n. 4
0
        public void TestMultipleSearchMultipleFields(Enums.ResourceType resourceType, ReadInvalidInputTestData.ItemState itemState, string firstFieldName, string secondFieldName, string firstCondition, string secondCondition)
        {
            ItemStateHelper.SearchParameters searchParameters = null;
            string firstFieldAlias  = $"{resourceType.ToResourceName()}.{firstFieldName}";
            string secondFieldAlias = $"{resourceType.ToResourceName()}.{secondFieldName}";

            var extraUrlParameters = new Dictionary <string, object>();

            if (itemState != ReadInvalidInputTestData.ItemState.None)
            {
                extraUrlParameters.Add(DeletedDataFields.ItemState, itemState.ToLowerString());
            }

            var itemStateType = itemState == ReadInvalidInputTestData.ItemState.None ? ReadInvalidInputTestData.ItemState.All : itemState;

            searchParameters = new ItemStateHelper.SearchParameters(firstFieldAlias, secondFieldAlias, firstCondition, secondCondition, null, null, null, null);

            //Result code
            var resultCode = (((firstFieldName == DeletedDataFields.P_UpdateDate) && firstCondition.ContainsStrings(new string[] { DateTimeValidator.Le, DateTimeValidator.Lt }) ||
                               (secondFieldName == DeletedDataFields.P_UpdateDate) && secondCondition.ContainsStrings(new string[] { DateTimeValidator.Le, DateTimeValidator.Lt })) &&
                              (itemState == ReadInvalidInputTestData.ItemState.Deleted || itemState == ReadInvalidInputTestData.ItemState.All))
                             ? Enums.PublicAPIResultCode.DateTimeOutOfRange : Enums.PublicAPIResultCode.Success;

            //Get result for condition inputs
            var extraConditionParam = new Dictionary <string, object>(extraUrlParameters);

            extraConditionParam["condition"] = $"{resourceType.ToResourceName()}.P_Id:ge={ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Min"]},{resourceType.ToResourceName()}.P_Id:le={ItemStateHelper.RecordIds[itemStateType](resourceType, RecordNum, recordsIn90Days, recordsOver90Days, deletedRecordsMapping)["Max"]}";
            var result = ItemStateHelper.GetAllResults(resourceType, $"{firstFieldAlias},{secondFieldAlias}", 0, MaxCount, extraConditionParam).Items;

            FirstFieldNameValues[firstFieldName](result, searchParameters, resourceType, itemStateType, firstFieldAlias, RecordNum);
            SecondFieldNameValues[secondFieldName](result, searchParameters, resourceType, itemStateType, secondFieldAlias, RecordNum);

            //Read & verify data
            string formatCond = PhaseHelper.GetFormatConditionDifferentFields(firstFieldAlias, secondFieldAlias, firstCondition, secondCondition,
                                                                              searchParameters.FirstCondValue.ToString(),
                                                                              searchParameters.SecondCondValue.ToString(),
                                                                              searchParameters.ThirdCondValue.ToString(),
                                                                              searchParameters.FourCondValue.ToString()
                                                                              );

            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "partition", AuthenticationInfoProvider.Current.DefaultPartition },
                { "condition", formatCond },
                { "field", $"{firstFieldAlias},{secondFieldAlias}" },
                { "count", MaxCount },
            };

            if (extraUrlParameters != null)
            {
                parameters = parameters.Concat(extraUrlParameters).GroupBy(d => d.Key).ToDictionary(d => d.Key, d => d.First().Value);
            }

            if (resultCode == Enums.PublicAPIResultCode.DateTimeOutOfRange)
            {
                var response = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail(resourceType.ToString(), parameters);
                Assert.That(response, MustBe.MatchingErrorCode(resultCode), Enums.Message.WRONG_ERROR_CODE);
            }
            else
            {
                var response = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess(resourceType.ToString(), parameters);
                Assert.That(response, MustBe.ReadSuccess(0), string.Format(Enums.Message.READ_RESOURCE_FAILED, resourceType));

                object firstRealValue  = null;
                object secondRealValue = null;

                foreach (var item in response.Items)
                {
                    firstRealValue  = RealValues[firstFieldName](item, firstFieldAlias);
                    secondRealValue = RealValues[secondFieldName](item, secondFieldAlias);

                    DateTimeValidator.ConditionalAssertions[firstCondition](firstRealValue, firstFieldName == DeletedDataFields.P_UpdateDate ? Util.ParseDateTime(searchParameters.FirstCondValue.ToString()) : searchParameters.FirstCondValue,
                                                                            firstFieldName == DeletedDataFields.P_UpdateDate ? Util.ParseDateTime(searchParameters.SecondCondValue.ToString()) : searchParameters.SecondCondValue);
                    DateTimeValidator.ConditionalAssertions[secondCondition](secondRealValue, secondFieldName == DeletedDataFields.P_UpdateDate ? Util.ParseDateTime(searchParameters.ThirdCondValue.ToString()) : searchParameters.ThirdCondValue
                                                                             , secondFieldName == DeletedDataFields.P_UpdateDate ? Util.ParseDateTime(searchParameters.FourCondValue.ToString()) : searchParameters.FourCondValue);
                }
            }
        }