Microsoft.Protocols.TestSuites.MS_LISTSWS.S03_OperationOnListItem.MSLISTSWS_S03_TC84_UpdateListItemsWithKnowledge_Success C# (CSharp) Method

MSLISTSWS_S03_TC84_UpdateListItemsWithKnowledge_Success() private method

        public void MSLISTSWS_S03_TC84_UpdateListItemsWithKnowledge_Success()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(25151, this.Site), @"Test is executed only when R25151Enabled is set to true.");

            // Read configure value.
            string validFieldName = Common.GetConfigurationPropertyValue("ListFieldText", this.Site);
            string invalidFieldName = TestSuiteHelper.GetUniqueFieldName();
            string fieldValue = TestSuiteHelper.GenerateRandomString(5);

            // Create a list
            string listName = TestSuiteHelper.GetUniqueListName();
            string listId = TestSuiteHelper.CreateList(listName);

            // Construct two insert items, one is valid and the other one is invalid.
            List<Dictionary<string, string>> items = new List<Dictionary<string, string>>(2);
            List<MethodCmdEnum> cmds = new List<MethodCmdEnum>(2);
            Dictionary<string, string> item1 = new Dictionary<string, string>();
            item1.Add(validFieldName, fieldValue);
            items.Add(item1);
            cmds.Add(MethodCmdEnum.New);
            Dictionary<string, string> item2 = new Dictionary<string, string>();
            item2.Add(invalidFieldName, fieldValue);
            items.Add(item2);
            cmds.Add(MethodCmdEnum.New);

            // Construct the UpdateListItemsUpdates instances
            UpdateListItemsWithKnowledgeUpdates updates = TestSuiteHelper.CreateUpdateListWithKnowledgeItems(cmds, items, OnErrorEnum.Continue);

            Site.Assert.IsNotNull(updates, "Created UpdateListItemsWithKnowledgeUpdates successfully");

            // Call UpdateListItemsWithKnowledge with valid Guid.
            UpdateListItemsWithKnowledgeResponseUpdateListItemsWithKnowledgeResult updateListItemsWithKnowledgeResult = null;
            bool isSoapExceptionExist = false;
            try
            {
                updateListItemsWithKnowledgeResult = this.listswsAdapter.UpdateListItemsWithKnowledge(
                                                                    listId,
                                                                    updates,
                                                                    null,
                                                                    null);
            }
            catch (SoapException)
            {
                isSoapExceptionExist = true;
            }

            this.Site.Assert.IsNotNull(updateListItemsWithKnowledgeResult, "UpdateListItemWithKnowledge operation with valid GUID is successful.");

            // If there is no any SoapException exist, then capture R25151.
            this.Site.CaptureRequirementIfIsFalse(
                    isSoapExceptionExist,
                    25151,
                    @"Implementation does support this method[UpdateListItemsWithKnowledge]. (Microsoft SharePoint Foundation 2010 and above follow this behavior.)");

            #region Capture Requirement R1155

            // Verify if the FieldName is valid, the ErrorCode is equal to "0x00000000".
            bool isValisFieldName = updateListItemsWithKnowledgeResult.Results[0].ErrorCode.Equals("0x00000000");
            Site.Assert.IsTrue(isValisFieldName, "the ErrorCode is equal to 0x00000000.");

            // Verify if the FiledName is invalid, the ErrorCode is not equal to "0x00000000"".
            bool isInValidFieldName = !updateListItemsWithKnowledgeResult.Results[1].ErrorCode.Equals("0x00000000");
            Site.Assert.IsTrue(isInValidFieldName, "the ErrorCode is equal not to 0x00000000.");

            // Verify R1155.
            Site.CaptureRequirement(
                1155,
                @"[In UpdateListItemsWithKnowledge]Otherwise, the protocol server MUST process "
                + "the batched operations on the list and return success or failure conditions per "
                + "operation.");

            #endregion

            #region Capture Requirement R1151, R2358

            // Call GetListItemChangesWithKnowledgeResponseGetListItemChangesWithKnowledgeResult operation by using the List Guid 
            // to verify whether the item exists in the specified list.
            CamlViewFields fields = TestSuiteHelper.CreateViewFields(false, new List<string> { validFieldName });
            GetListItemChangesWithKnowledgeResponseGetListItemChangesWithKnowledgeResult getListItemWithKnowledgeResult = null;
            getListItemWithKnowledgeResult = this.listswsAdapter.GetListItemChangesWithKnowledge(
                                                                                                  listId,
                                                                                                  null,
                                                                                                  null,
                                                                                                  fields,
                                                                                                  null,
                                                                                                  null,
                                                                                                  null,
                                                                                                  null,
                                                                                                  null);

            string columnName = string.Format("{0}{1}", AdapterHelper.PrefixOws, validFieldName);
            DataTable data = AdapterHelper.ExtractData(getListItemWithKnowledgeResult.listitems.data.Any);
            bool isUseList = data.Rows.Count == 1 && Convert.ToString(data.Rows[0][columnName]) == fieldValue;

            Site.Log.Add(
                     LogEntryKind.Debug,
                     "The actual value: data.Rows.Count[{0}],columnName[{1}] for requirement #R1151",
                     data.Rows.Count,
                     0 == data.Rows.Count ? "NoRows" : data.Rows[0][columnName]);

            // If the specified list contains one item and the field value in the z:row element equals to value in
            // the UpdateListItemsWithKnowledge request, then R1151 should be covered.
            Site.CaptureRequirementIfIsTrue(
                isUseList,
                1151,
                @"[In UpdateListItemsWithKnowledge]If the specified listName is a valid GUID and corresponds to 
                the identification of a list on the site, use that list.");

            // If the protocol client does not specify the owshiddenversion field reference in 
            // the UpdateListItemsWithKnow request, then capture R2358.
            Site.CaptureRequirement(
               2358,
               @"[In UpdateListItemsWithKnowledge operation] [In "
               + "UpdateListItemsWithKnowledge element] [In updates element] [In Batch "
               + "element] [In Method element] [In Field element] If the protocol client does "
               + "not specify the owshiddenversion field reference in the "
               + "UpdateListItemsWithKnow request, then the protocol server MUST overwrite "
               + "any changes in the list item or return an error.");

            #endregion

            #region Capture Requirements R2326

            string fieldCounter = Common.GetConfigurationPropertyValue("ListFieldCounter", this.Site);

            // Set the value of Counter as "1".
            string fieldCounterValue = "1";
            cmds = new List<MethodCmdEnum>(1);
            items = new List<Dictionary<string, string>>(1);
            Dictionary<string, string> item3 = new Dictionary<string, string>();
            item3.Add(fieldCounter, fieldCounterValue);
            items.Add(item3);
            cmds.Add(MethodCmdEnum.New);

            // Call UpdateListItemsWithKnowledge with valid Guid. Add a counter.
            updates = TestSuiteHelper.CreateUpdateListWithKnowledgeItems(cmds, items, OnErrorEnum.Continue);

            updateListItemsWithKnowledgeResult
           = this.listswsAdapter.UpdateListItemsWithKnowledge(
                                                               listId,
                                                               updates,
                                                               null,
                                                               null);

            // Get the value of the "ID" from the server.
            columnName = string.Format("{0}{1}", AdapterHelper.PrefixOws, "ID");
            data = AdapterHelper.ExtractData(updateListItemsWithKnowledgeResult.Results[0].Any);
            string id = Convert.ToString(data.Rows[0][columnName]);

            // As description, if update the list item, must add the ID value for the specified list item.
            cmds = new List<MethodCmdEnum>(1);
            items = new List<Dictionary<string, string>>(1);
            Dictionary<string, string> item4 = new Dictionary<string, string>();
            item4.Add("ID", id);

            // Set an invalid value for the counter, Guid is not integer. 
            item4.Add(fieldCounter, Guid.NewGuid().ToString());
            items.Add(item4);
            cmds.Add(MethodCmdEnum.Update);
            updates = TestSuiteHelper.CreateUpdateListWithKnowledgeItems(cmds, items, OnErrorEnum.Continue);

            updateListItemsWithKnowledgeResult
           = this.listswsAdapter.UpdateListItemsWithKnowledge(
                                                               listId,
                                                               updates,
                                                               null,
                                                               null);

            // If the specified item is not be changed, then R2326 should be covered.
            columnName = string.Format("{0}{1}", AdapterHelper.PrefixOws, fieldCounter);
            data = AdapterHelper.ExtractData(updateListItemsWithKnowledgeResult.Results[0].Any);
            bool isReturnInZRowElement = Convert.ToString(data.Rows[0][columnName]) == fieldCounterValue;

            Site.Log.Add(
            LogEntryKind.Debug,
            "The actual value: columnName[{0}] for requirement #R2326",
            0 == data.Rows.Count ? "NoRows" : data.Rows[0][columnName]);

            Site.CaptureRequirementIfIsTrue(
                isReturnInZRowElement,
                2326,
                @"[In UpdateListItemsWithKnowledgeResult][In "
                + "UpdateListItemsWithKnowledgeResponse][In "
                + "UpdateListItemsWithKnowledgeResult element] On failure, the z:row element "
                + "MUST contain the list item data that exists on the server if the list item "
                + "specified in the request exists.");

            #endregion
        }
S03_OperationOnListItem