/// <summary> /// Update the specified items' List.FieldText configured column in the specified list to the "NewTextField" value. /// </summary> /// <param name="list">A parameter represents the list title or list id.</param> /// <param name="updateIds">A parameter represents the update items ids.</param> /// <param name="errorEnum">A parameter represents when error occurs, the following sequence will continue or return.</param> public static void UpdateListItems(string list, List<string> updateIds, OnErrorEnum errorEnum) { List<Dictionary<string, string>> updatedItems = new List<Dictionary<string, string>>(); List<MethodCmdEnum> cmds = new List<MethodCmdEnum>(); foreach (string id in updateIds) { Dictionary<string, string> itemId = new Dictionary<string, string>(); itemId.Add("ID", id); // We make the Text field value always update to "NewTextField" append a counter number. itemId.Add( Common.GetConfigurationPropertyValue("ListFieldText", testSite), string.Format("{0}{1}", "NewTextField", id)); updatedItems.Add(itemId); cmds.Add(MethodCmdEnum.Update); } UpdateListItemsUpdates updates = TestSuiteHelper.CreateUpdateListItems( cmds, updatedItems, errorEnum); UpdateListItemsResponseUpdateListItemsResult result = null; try { result = listswsAdapter.UpdateListItems( list, updates); } catch (SoapException exp) { testSite.Debug.Fail(ErrorMessageTemplate, "updating list items in the list " + list, exp.Detail.InnerText); } if (updateIds.Count != result.Results.Length) { testSite.Assert.Fail("Expect update {0} item, but actually add {1} items", updateIds.Count, result.Results.Length); } foreach (UpdateListItemsResponseUpdateListItemsResultResult res in result.Results) { if (res.ErrorCode != "0x00000000") { testSite.Debug.Fail(ErrorMessageTemplate, "updating list items in the list " + list, res.Any); } } }
/// <summary> /// Delete the specified items in the specified list. /// </summary> /// <param name="list">A parameter represents the list title or list id.</param> /// <param name="deleteIDList">Specify the delete items id.</param> /// <param name="errorEnum">Specify how to affect the following sequence when one delete item method fails.</param> public static void RemoveListItems(string list, List<string> deleteIDList, OnErrorEnum errorEnum) { List<Dictionary<string, string>> deletedItems = new List<Dictionary<string, string>>(); List<MethodCmdEnum> cmds = new List<MethodCmdEnum>(); foreach (string id in deleteIDList) { Dictionary<string, string> itemId = new Dictionary<string, string>(); itemId.Add("ID", id); deletedItems.Add(itemId); cmds.Add(MethodCmdEnum.Delete); } UpdateListItemsUpdates updates = TestSuiteHelper.CreateUpdateListItems( cmds, deletedItems, errorEnum); UpdateListItemsResponseUpdateListItemsResult result = listswsAdapter.UpdateListItems( list, updates); if (deleteIDList.Count != result.Results.Length) { testSite.Assert.Fail("Expect delete {0} item, but actually add {1} items", deleteIDList.Count, result.Results.Length); } foreach (UpdateListItemsResponseUpdateListItemsResultResult res in result.Results) { if (res.ErrorCode != "0x00000000") { testSite.Debug.Fail(ErrorMessageTemplate, "deleting item from the list " + list, AdapterHelper.GetElementValue(res.Any, "ErrorText")); } } }
/// <summary> /// A method used to construct UpdateListItemsWithKnowledgeUpdates instance using the specified parameters. /// </summary> /// <param name="methods">A list of MethodCmdEnum to specify the operations.</param> /// <param name="fieldNameValuePairs">A list of items values.</param> /// <param name="errorhandleType">Specify the OnError of the Batch element's value.</param> /// <returns>Returns the UpdateListItemsUpdates instance.</returns> public static UpdateListItemsWithKnowledgeUpdates CreateUpdateListWithKnowledgeItems( List<MethodCmdEnum> methods, List<Dictionary<string, string>> fieldNameValuePairs, OnErrorEnum errorhandleType) { testSite.Assert.IsNotNull( methods, "The parameter methods in CreateUpdateListWithKnowledgeItems cannot be null"); testSite.Assert.IsNotNull( fieldNameValuePairs, "The parameter methods in CreateUpdateListWithKnowledgeItems cannot be null"); testSite.Assert.AreEqual<int>( methods.Count, fieldNameValuePairs.Count, "The element number in the methods and fieldNameValuePairs parameter List are same"); UpdateListItemsWithKnowledgeUpdates updates = new UpdateListItemsWithKnowledgeUpdates(); updates.Batch = new UpdateListItemsWithKnowledgeUpdatesBatch(); updates.Batch.Method = new UpdateListItemsWithKnowledgeUpdatesBatchMethod[methods.Count]; for (int i = 0; i < methods.Count; i++) { updates.Batch.OnError = errorhandleType; updates.Batch.OnErrorSpecified = true; updates.Batch.Method[i] = new UpdateListItemsWithKnowledgeUpdatesBatchMethod(); updates.Batch.Method[i].Cmd = methods[i]; int fieldCount = fieldNameValuePairs[i].Keys.Count; updates.Batch.Method[i].Field = new UpdateListItemsWithKnowledgeUpdatesBatchMethodField[fieldCount]; int j = 0; foreach (KeyValuePair<string, string> keyPair in fieldNameValuePairs[i]) { updates.Batch.Method[i].Field[j] = new UpdateListItemsWithKnowledgeUpdatesBatchMethodField(); updates.Batch.Method[i].Field[j].Name = keyPair.Key; updates.Batch.Method[i].Field[j].Value = keyPair.Value; j++; } } return updates; }