예제 #1
0
        public void TestListItemUserField(Enums.ResourceType resourceType, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType)
        {
            Assume.That(customFields.Data, Is.Not.Null.And.Not.Empty, "Cannot create a user field!");
            string fieldAlias = customFields.Data[$"{resourceType}-{Field1}"].Field.ToAlias();

            BulkWriteHelper.ExecuteTestListItem(resourceType, firstItemType, secondItemType, records, referenceRecords, fieldAlias, cleaner, Util.ToString(DateTime.Now));
        }
        private Phase CreateBulkWritePhaseInstance(Enums.ResourceType resourceType, BulkWriteInputType itemType, int index = 0)
        {
            Phase result = null;

            switch (itemType)
            {
            case BulkWriteInputType.ValidItem:
                result = PhaseHelper.CreatePhaseInstance(creatingRequestRecords, resourceType, index);
                break;

            case BulkWriteInputType.InvalidItem:
                result = PhaseHelper.CreatePhaseInstance(creatingRequestRecords, resourceType, index);
                result.DictionaryValues["Datexxx"] = "Abc";
                break;

            case BulkWriteInputType.UpdatedItem:
                result = new Phase()
                {
                    Id   = phaseReader.Data[$"{resourceType.ToPrivateEnum()}{index}"].FirstOrDefault().Id,
                    Date = Util.ToString(DateTime.Now, false),
                };
                break;

            case BulkWriteInputType.CreatedItem:
                result = PhaseHelper.CreatePhaseInstance(creatingRequestRecords, resourceType, index);
                break;
            }
            return(result);
        }
예제 #3
0
 /// <summary>
 /// Check WriteResultItem of Bulk Write test cases
 /// </summary>
 /// <param name="expectedType"></param>
 /// <param name="actualItem"></param>
 public static void VerifyBulkWriteResultItem(BulkWriteInputType expectedType, WriteResultItem actualItem)
 {
     if (expectedType == BulkWriteInputType.InvalidItem)
     {
         Assert.That(actualItem.Code, Is.Not.EqualTo(Enums.PublicAPIResultCode.Success), Enums.Message.WRONG_ERROR_CODE);
     }
     else
     {
         Assert.That(actualItem.Code, Is.EqualTo(Enums.PublicAPIResultCode.Success), Enums.Message.WRONG_ERROR_CODE);
         Assert.That(actualItem.Id, Is.Not.Null.And.Not.Empty, "The id is null or empty");
     }
 }
예제 #4
0
        /// <summary>
        /// Execute all steps of List Item Bulk Write test
        /// </summary>
        /// <param name="resourceType"></param>
        /// <param name="firstItemType"></param>
        /// <param name="secondItemType"></param>
        /// <param name="records"></param>
        /// <param name="fieldAlias"></param>
        /// <param name="fieldValue"></param>
        /// <param name="isPhase"></param>
        public static void ExecuteTestListItem(Enums.ResourceType resourceType, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType,
                                               HrbcRecordCreator records, HrbcRecordCreator referenceRecords, string fieldAlias, HrbcRecordDelete cleaner, object fieldValue = null, bool isPhase = false)
        {
            //Preparation
            var resourceList = new List <XmlResource>()
            {
                BulkWriteHelper.CreateBulkWriteTestResourceInstance(resourceType, firstItemType, records, referenceRecords, fieldAlias, fieldValue, isPhase, 0),
                BulkWriteHelper.CreateBulkWriteTestResourceInstance(resourceType, secondItemType, records, referenceRecords, fieldAlias, fieldValue, isPhase, 1),
            };

            WriteAndVerify(resourceType, resourceList, firstItemType, secondItemType, cleaner);
        }
        public void TestListItem(Enums.ResourceType resourceType, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType)
        {
            var resourceList = new List <Phase>()
            {
                CreateBulkWritePhaseInstance(resourceType, firstItemType, 0),
                CreateBulkWritePhaseInstance(resourceType, secondItemType, 1),
            };

            //Write data
            List <WriteResultItem> result = PhaseHelper.WritePhases(resourceList);

            //Verify result
            Assert.That(result, Is.Not.Null, "Create records operation failed. Response is null or cannot be parsed.");
            Assert.That(result.Count, Is.EqualTo(resourceList.Count), "Create records operation failed. Number of successfully inserted resources is not same as the number of records we intended to insert");
            BulkWriteHelper.VerifyBulkWriteResultItem(firstItemType, result[0]);
            BulkWriteHelper.VerifyBulkWriteResultItem(secondItemType, result[1]);
        }
예제 #6
0
        private static Dictionary <string, object> GetParamerters(BulkWriteInputType inputType)
        {
            var parameters = new Dictionary <string, object>
            {
                ["id"]        = -1,
                ["parent_id"] = 0,
                ["name"]      = "Test Option",
                ["type"]      = 0,
            };

            switch (inputType)
            {
            case BulkWriteInputType.ValidUpdateItem:
                parameters["id"] = Common.GetOptionsByCurrentContext("parentOptionCreateResponse").FirstOrDefault().Id;
                break;

            case BulkWriteInputType.InvalidItem:
                parameters["id"] = "zyz";
                break;
            }
            return(parameters);
        }
예제 #7
0
        public void WriteBulkOption(BulkWriteInputType firstInputType, BulkWriteInputType secondInputType)
        {
            var optionHandler = new OptionManager();
            var options       = new List <Dictionary <string, object> >();

            options.Add(GetParamerters(firstInputType));
            options.Add(GetParamerters(secondInputType));

            if (firstInputType == BulkWriteInputType.InvalidItem || secondInputType == BulkWriteInputType.InvalidItem)
            {
                Common.AssertWriteUnsuccessOption(optionHandler.WriteOptions(options), ResultCode.InvalidValue);
            }
            else
            {
                var response = optionHandler.WriteOptions(options);
                Common.AssertWriteSuccessOption(response);

                //Verify
                foreach (var item in response.Result)
                {
                    PrAssert.That(Common.SearchOptionByIdAndVerifyResult(item.Id).Id, PrIs.EqualTo(item.Id), string.Format(Common.errorMessage, "Id"));
                }
            }
        }
예제 #8
0
        private static void WriteAndVerify(Enums.ResourceType resourceType, List <XmlResource> resourceList, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType, HrbcRecordDelete cleaner)
        {
            //Write data
            List <WriteResultItem> result = ResourceHelper.WriteResources(resourceType, resourceList, null);

            //In case a new resource is created, We add it to the cleaner
            if (result != null && result.Count > 0)
            {
                if (firstItemType != BulkWriteInputType.UpdatedItem)
                {
                    cleaner.Delete(resourceType, result[0].Id);
                }
                if (secondItemType != BulkWriteInputType.UpdatedItem)
                {
                    cleaner.Delete(resourceType, result[1].Id);
                }
            }

            //Verify result
            Assert.That(result, Is.Not.Null, "Create records operation failed. Response is null or cannot be parsed.");
            Assert.That(result.Count, Is.EqualTo(resourceList.Count), "Create records operation failed. Number of successfully inserted resources is not same as the number of records we intended to insert");
            VerifyBulkWriteResultItem(firstItemType, result[0]);
            VerifyBulkWriteResultItem(secondItemType, result[1]);
        }
예제 #9
0
        /// <summary>
        /// Create an instance of resource that is used for Bulk Write testing.
        /// </summary>
        /// <param name="resourceType">Resource Type</param>
        /// <param name="itemType">Bulk Write Item Type</param>
        /// <param name="fieldAlias">Field Alias</param>
        /// <param name="fieldValue">Field value is used in case of Valid/Updated Item</param>
        /// <param name="isPhase">Phase related fields will be created automatically</param>
        /// <param name="index">Index to get resources from records </param>
        /// <returns></returns>
        private static XmlResource CreateBulkWriteTestResourceInstance(Enums.ResourceType resourceType, BulkWriteInputType itemType, HrbcRecordCreator records,
                                                                       HrbcRecordCreator referenceRecords, string fieldAlias, object fieldValue, bool isPhase, int index)
        {
            XmlResource result = null;

            switch (itemType)
            {
            case BulkWriteInputType.ValidItem:
                result = ResourceHelper.CreateResourceInstance(referenceRecords, resourceType, index);
                break;

            case BulkWriteInputType.InvalidItem:
                result = ResourceHelper.CreateResourceInstance(referenceRecords, resourceType, index);
                result.DictionaryValues[fieldAlias + "xxx"] = "Abc";
                break;

            case BulkWriteInputType.UpdatedItem:
                result = ResourceHelper.CreateUpdatedResource(resourceType, records.Data[$"{resourceType.ToPrivateEnum()}{index}"].Id.ToString(),
                                                              fieldAlias, fieldValue, isPhase, referenceRecords, index);
                break;

            case BulkWriteInputType.CreatedItem:
                result = ResourceHelper.CreateSingleResourceItem(resourceType, fieldAlias, fieldValue, referenceRecords, isPhase, index, referenceRecords);
                break;
            }
            return(result);
        }
예제 #10
0
        public void TestListItemSystemField(Enums.ResourceType resourceType, string fieldName, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType)
        {
            string fieldAlias = resourceType.ToResourceName() + "." + fieldName;
            int    startIndex = resourceType == Enums.ResourceType.Process ? 2 : 0;

            BulkWriteHelper.ExecuteTestListItem(resourceType, firstItemType, secondItemType, records, referenceRecords, fieldAlias, cleaner, Util.ToString(DateTime.Now), true);
        }
예제 #11
0
        public void TestListItemApplicationField(Enums.ResourceType resourceType, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType)
        {
            string fieldAlias = resourceType.ToResourceName() + "." + AppField1;

            BulkWriteHelper.ExecuteTestListItem(resourceType, firstItemType, secondItemType, records, referenceRecords, fieldAlias, cleaner, Util.ToString(DateTime.Now));
        }
예제 #12
0
        public void TestListItemSystemField(Enums.ResourceType resourceType, string fieldName, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType)
        {
            string fieldAlias = resourceType.ToResourceName() + "." + fieldName;

            BulkWriteHelper.ExecuteTestListItem(resourceType, firstItemType, secondItemType, records, referenceRecords, fieldAlias, cleaner,
                                                ResourceHelper.DefaultUser, true);
        }
예제 #13
0
        public void TestListItemSystemField(Enums.ResourceType resourceType, string fieldName, BulkWriteInputType firstItemType, BulkWriteInputType secondItemType)
        {
            string fieldAlias = resourceType.ToResourceName() + "." + fieldName;

            if (resourceType == Enums.ResourceType.Process && firstItemType != BulkWriteInputType.InvalidItem && secondItemType != BulkWriteInputType.InvalidItem)
            {
                startIndex += 2;
                BulkWriteHelper.ExecuteTestListItem(resourceType, firstItemType, secondItemType, records, referenceRecords, fieldAlias, cleaner,
                                                    (index) => this.GetFieldValue(fieldName, index), true, startIndex - 2);
            }
            else
            {
                BulkWriteHelper.ExecuteTestListItem(resourceType, firstItemType, secondItemType, records, referenceRecords, fieldAlias, cleaner,
                                                    (index) => this.GetFieldValue(fieldName, index), true);
            }
        }