public void MSLISTSWS_S03_TC90_UpdateListItems_Methods()
{
// Create a list.
string listId = TestSuiteHelper.CreateList();
// Read value from configuration file.
string validFieldName = Common.GetConfigurationPropertyValue("ListFieldText", this.Site);
string fieldValue = TestSuiteHelper.GenerateRandomString(5);
// Construct one insert item with ID.
List<Dictionary<string, string>> items = new List<Dictionary<string, string>>();
List<MethodCmdEnum> cmds = new List<MethodCmdEnum>();
Dictionary<string, string> newItem = new Dictionary<string, string>();
newItem.Add(validFieldName, fieldValue);
newItem.Add("ID", Guid.NewGuid().ToString());
items.Add(newItem);
cmds.Add(MethodCmdEnum.New);
// Construct the UpdateListItemsUpdates instance.
UpdateListItemsUpdates updates = TestSuiteHelper.CreateUpdateListItems(cmds, items, OnErrorEnum.Return);
UpdateListItemsResponseUpdateListItemsResult resultWhenIncludeId = null;
resultWhenIncludeId = this.listswsAdapter.UpdateListItems(listId, updates);
// Get new item ID from UpdateListItems response.
DataTable data = AdapterHelper.ExtractData(resultWhenIncludeId.Results[0].Any);
string columnNameId = string.Format("{0}{1}", AdapterHelper.PrefixOws, AdapterHelper.FieldIDName);
List<string> updatedListItemIds = new List<string>();
foreach (DataRow row in data.Rows)
{
updatedListItemIds.Add(row[columnNameId].ToString());
}
// Get item IDs from GetListItems response.
GetListItemsResponseGetListItemsResult getListItemsResult = this.listswsAdapter.GetListItems(listId, null, null, null, null, null, null);
data = AdapterHelper.ExtractData(getListItemsResult.listitems.data.Any);
List<string> getListItemIds = new List<string>();
foreach (DataRow row in data.Rows)
{
getListItemIds.Add(row[columnNameId].ToString());
}
// If new item ID exists in the GetListItems response, it means the new item has been added. R2092 is captured.
bool isR2092Verified = true;
foreach (string id in updatedListItemIds)
{
if (!getListItemIds.Contains(id))
{
isR2092Verified = false;
}
}
Site.CaptureRequirementIfIsTrue(
isR2092Verified,
2092,
@"[In UpdateListItems operation] [In UpdateListItems element] [In updates element] [In Batch element] [In Method element] [New attribute] Adds a new list item to the specified list.");
// In the z:row, we can only make sure the attribute value which
// is specified by validFieldName is equal, and for all the other attribute there is no
// guarantee. So all the other attributes in the z:row will be ignored except the
// specified one.
foreach (UpdateListItemsResponseUpdateListItemsResultResult result in resultWhenIncludeId.Results)
{
foreach (XmlElement row in result.Any)
{
IgnoreAttributeExcept(
row,
validFieldName);
}
}
// Re-construct one insert item without ID.
items.Clear();
cmds.Clear();
newItem.Clear();
newItem.Add(validFieldName, fieldValue);
items.Add(newItem);
cmds.Add(MethodCmdEnum.New);
// Construct the UpdateListItemsUpdates instance.
updates = TestSuiteHelper.CreateUpdateListItems(cmds, items, OnErrorEnum.Return);
UpdateListItemsResponseUpdateListItemsResult resultWhenExcludeId = null;
resultWhenExcludeId = this.listswsAdapter.UpdateListItems(listId, updates);
data = AdapterHelper.ExtractData(resultWhenExcludeId.Results[0].Any);
foreach (DataRow row in data.Rows)
{
updatedListItemIds.Add(row[columnNameId].ToString());
}
// In the z:row, we can only make sure the attribute value which
// is specified by validFieldName is equal, and for all the other attribute there is no
// guarantee. So all the other attributes in the z:row will be ignored except the
// specified one.
foreach (UpdateListItemsResponseUpdateListItemsResultResult result in resultWhenExcludeId.Results)
{
foreach (XmlElement row in result.Any)
{
IgnoreAttributeExcept(
row,
validFieldName);
}
}
// If ignore some fields in z:row element and both results are the same, capture R2289.
bool isSame = TestSuiteHelper.DeepCompare(resultWhenIncludeId, resultWhenExcludeId);
Site.CaptureRequirementIfIsTrue(
isSame,
2289,
"[In UpdateListItems operation] [In UpdateListItems element] [In updates element] "
+ "[In Batch element] [In Method element] [New attribute] The server response will be "
+ "same in both <Field Name=\"ID\"> exists in request or not.");
// There are 2 list items. Update the first item and delete the last item.
items.Clear();
cmds.Clear();
Dictionary<string, string> updatedItem = new Dictionary<string, string>();
string newFieldValue = TestSuiteHelper.GenerateRandomString(10);
updatedItem.Add("ID", updatedListItemIds.First());
updatedItem.Add(validFieldName, newFieldValue);
items.Add(updatedItem);
cmds.Add(MethodCmdEnum.Update);
Dictionary<string, string> deletedItem = new Dictionary<string, string>();
deletedItem.Add("ID", updatedListItemIds.Last());
items.Add(deletedItem);
cmds.Add(MethodCmdEnum.Delete);
updates = TestSuiteHelper.CreateUpdateListItems(cmds, items, OnErrorEnum.Return);
// Call UpdateListItems operation to update the first item and delete the last item.
this.listswsAdapter.UpdateListItems(listId, updates);
// Call GetListItems operation.
CamlViewFields viewFields = TestSuiteHelper.CreateViewFields(true, new List<string> { validFieldName });
getListItemsResult = this.listswsAdapter.GetListItems(listId, null, null, viewFields, null, null, null);
data = AdapterHelper.ExtractData(getListItemsResult.listitems.data.Any);
getListItemIds.Clear();
string columnNameField = string.Format("{0}{1}", AdapterHelper.PrefixOws, validFieldName);
bool isR2093Verified = false;
foreach (DataRow row in data.Rows)
{
// Get item IDs from GetListItems response.
getListItemIds.Add(row[columnNameId].ToString());
// Check if the updated item has been updated successfully.
if (row[columnNameId].ToString().Equals(updatedListItemIds.First(), StringComparison.OrdinalIgnoreCase))
{
if (row[columnNameField].ToString().Equals(newFieldValue, StringComparison.Ordinal))
{
isR2093Verified = true;
}
}
}
// If the updated item in GetListItems response has been updated successfully, R2093 is captured.
Site.CaptureRequirementIfIsTrue(
isR2093Verified,
2093,
@"[In UpdateListItems operation] [In UpdateListItems element] [In updates element] [In Batch element] [In Method element] [Update attribute] Updates fields for a specific list item.");
// If GetListItems response does not contain the deleted item ID, it means the item has been deleted. Then R2094 is captured.
Site.CaptureRequirementIfIsFalse(
getListItemIds.Contains(updatedListItemIds.Last()),
2094,
@"[In UpdateListItems operation] [In UpdateListItems element] [In updates element] [In Batch element] [In Method element] [Delete attribute] Deletes a specific list item.");
// Verify 'Move' method.
if (Common.IsRequirementEnabled(20961, this.Site))
{
// Create 2 document libraries.
string sourceListName = TestSuiteHelper.GetUniqueListName();
string sourceList = TestSuiteHelper.CreateList(sourceListName, Convert.ToInt32(TemplateType.Document_Library));
string destinationListName = TestSuiteHelper.GetUniqueListName();
string destinationList = TestSuiteHelper.CreateList(destinationListName, Convert.ToInt32(TemplateType.Document_Library));
// Get the root folder of destination list.
GetListResponseGetListResult getListResult = this.listswsAdapter.GetList(destinationList);
string rootFolder = getListResult.List.RootFolder;
// Upload a document to source list.
IMS_LISTSWSSUTControlAdapter sutControlAdapter = this.Site.GetAdapter<IMS_LISTSWSSUTControlAdapter>();
string absoluteFileUrl = sutControlAdapter.UploadFile(sourceListName);
Site.Assert.IsTrue(
!string.IsNullOrEmpty(absoluteFileUrl),
"Upload file to the list {0} should be successful, the file path is [{1}]",
sourceListName,
absoluteFileUrl);
// Get the uploaded file name.
string uploadFileName = absoluteFileUrl.Substring(absoluteFileUrl.LastIndexOf('/'));
// Get uploaded item ID.
getListItemsResult = this.listswsAdapter.GetListItems(sourceList, null, null, null, null, null, null);
data = AdapterHelper.ExtractData(getListItemsResult.listitems.data.Any);
// Get the value of "ID" and "MoveNewUrl" fields.
string fileID = (string)data.Rows[0][columnNameId];
string moveNewUrl = rootFolder.TrimEnd('/') + "/" + uploadFileName.Trim('/');
// Construct one insert item with ID.
items.Clear();
cmds.Clear();
Dictionary<string, string> movedItem = new Dictionary<string, string>();
movedItem.Add("ID", fileID);
movedItem.Add("FileRef", absoluteFileUrl);
movedItem.Add("MoveNewUrl", moveNewUrl);
items.Add(movedItem);
cmds.Add(MethodCmdEnum.Move);
// Construct the UpdateListItemsUpdates instance.
UpdateListItemsUpdates moveUpdates = TestSuiteHelper.CreateUpdateListItems(cmds, items, OnErrorEnum.Return);
// Call UpdateListItems method to move file.
UpdateListItemsResponseUpdateListItemsResult moveResult = null;
moveResult = this.listswsAdapter.UpdateListItems(sourceList, moveUpdates);
// Error code "0x00000000" indicates the operation completes successfully. Then R20961 captured.
Site.CaptureRequirementIfAreEqual<string>(
"0x00000000",
moveResult.Results[0].ErrorCode,
20961,
@"Implementation does support this behavior[UpdateListItems.Move]. (Microsoft SharePoint Foundation 2010 and above follow this behavior.)");
}
}