public void MSLISTSWS_S03_TC81_UpdateListItemsWithKnowledge_OnErrorContinue()
{
Site.Assume.IsTrue(Common.IsRequirementEnabled(25151, this.Site), @"Test is executed only when R25151Enabled is set to true.");
// Create a list.
string listId = TestSuiteHelper.CreateList();
// Get the configure value.
string validFieldName = Common.GetConfigurationPropertyValue("ListFieldText", this.Site);
// Get the random generate unique field name.
string invalidFieldName = TestSuiteHelper.GetUniqueFieldName();
// Construct three items: the second one is invalid, the first and the last one are valid.
List<Dictionary<string, string>> items = new List<Dictionary<string, string>>(3);
List<MethodCmdEnum> cmds = new List<MethodCmdEnum>(3);
// Add the first item.
Dictionary<string, string> item1 = new Dictionary<string, string>();
item1.Add(validFieldName, TestSuiteHelper.GenerateRandomString(5));
items.Add(item1);
cmds.Add(MethodCmdEnum.New);
// Add the second item.
Dictionary<string, string> item2 = new Dictionary<string, string>();
item2.Add(invalidFieldName, TestSuiteHelper.GenerateRandomString(5));
items.Add(item2);
cmds.Add(MethodCmdEnum.New);
// Add the third item.
Dictionary<string, string> item3 = new Dictionary<string, string>();
item3.Add(validFieldName, TestSuiteHelper.GenerateRandomString(5));
items.Add(item3);
cmds.Add(MethodCmdEnum.New);
UpdateListItemsWithKnowledgeUpdates updates = TestSuiteHelper.CreateUpdateListWithKnowledgeItems(cmds, items, OnErrorEnum.Continue);
UpdateListItemsWithKnowledgeResponseUpdateListItemsWithKnowledgeResult result = null;
result = this.listswsAdapter.UpdateListItemsWithKnowledge(
listId,
updates,
null,
null);
// Capture R2315 if there are three result elements,
// because we have there method in the request.
Site.CaptureRequirementIfAreEqual<int>(
3,
result.Results.Length,
2315,
"[In UpdateListItemsWithKnowledgeResult][In UpdateListItemsWithKnowledgeResponse]"
+ "[In UpdateListItemsWithKnowledgeResult element] If the OnError attribute of the Batch "
+ "element is set to Continue, then each Method corresponds to a Result.");
// Call GetListItems to get current items.
GetListItemsResponseGetListItemsResult listItems = null;
listItems = this.listswsAdapter.GetListItems(
listId,
null,
null,
null,
null,
null,
null);
DataTable data = AdapterHelper.ExtractData(listItems.listitems.data.Any);
// If there is only one item exist, the third insert will be aborted due to
// the failure of the second insert operation.
Site.CaptureRequirementIfAreEqual<int>(
2,
data.Rows.Count,
1507,
@"[OnErrorEnum]Continue: Continues running subsequent methods after an error is encountered.");
Site.CaptureRequirementIfAreEqual<int>(
2,
data.Rows.Count,
2316,
"[In UpdateListItemsWithKnowledgeResult][In UpdateListItemsWithKnowledgeResponse]"
+ "[In UpdateListItemsWithKnowledgeResult element] [If the OnError attribute of the Batch "
+ "element is set to Continue,] The outcome of a Method operation MUST not affect the other Method operations.");
if (Common.IsRequirementEnabled(4010, this.Site))
{
Site.CaptureRequirementIfAreEqual<int>(
2,
data.Rows.Count,
4010,
@"[In UpdateListItemsWithKnowledge][In Bench element][In OnError attribute] Implementation does execute the subsequent methods in the batch [if ""OnError=Continue""] when encountering an error."
+ @"(The 2007 Microsoft® Office system/Windows® SharePoint® Services 3.0 and above follow this behavior.)");
}
// Remove all the list items in this list.
string colunmIdName = AdapterHelper.PrefixOws + AdapterHelper.FieldIDName;
List<string> allItemsId = new List<string>();
foreach (DataRow row in data.Rows)
{
string id = Convert.ToString(row[colunmIdName]);
allItemsId.Add(id);
}
TestSuiteHelper.RemoveListItems(listId, allItemsId, OnErrorEnum.Continue);
// Construct UpdateListItemsUpdates instance not specified OnError, using the default value.
updates = TestSuiteHelper.CreateUpdateListWithKnowledgeItems(cmds, items);
// Call UpdateListItems using the default OnError value.
result = this.listswsAdapter.UpdateListItemsWithKnowledge(listId, updates, null, null);
// Call the GetListItems to get the current list items.
listItems = this.listswsAdapter.GetListItems(
listId,
null,
null,
null,
null,
null,
null);
data = AdapterHelper.ExtractData(listItems.listitems.data.Any);
// The UpdateListItmes does not send OnError, but if there are still 2 items,
// the third insert won’t be aborted due to the failure of the second insert operation.
// The behavior is the same on Continue.
Site.CaptureRequirementIfAreEqual<int>(
2,
data.Rows.Count,
2343,
@"[In UpdateListItemsWithKnowledge][In Bench element][In OnError attribute] "
+ "The default is to continue executing subsequent items.");
// Remove all the list items in this list.
allItemsId = new List<string>();
foreach (DataRow row in data.Rows)
{
string id = Convert.ToString(row[colunmIdName]);
allItemsId.Add(id);
}
TestSuiteHelper.RemoveListItems(listId, allItemsId, OnErrorEnum.Continue);
// Try to update an item.
Dictionary<string, string> itemOfUpdated = new Dictionary<string, string>();
itemOfUpdated.Add(validFieldName, TestSuiteHelper.GenerateRandomString(5));
// Set the list item ID equal to 1 and Current List does not contain any list item. The list item which "ID" is equal to 1 does not exist in Current List.
itemOfUpdated.Add("ID", "1");
items = new List<Dictionary<string, string>>();
items.Add(itemOfUpdated);
cmds = new List<MethodCmdEnum>();
cmds.Add(MethodCmdEnum.Update);
updates = TestSuiteHelper.CreateUpdateListWithKnowledgeItems(cmds, items, OnErrorEnum.Continue);
UpdateListItemsWithKnowledgeResponseUpdateListItemsWithKnowledgeResult resultOfUpdateListItemWithKnowledge = null;
resultOfUpdateListItemWithKnowledge = this.listswsAdapter.UpdateListItemsWithKnowledge(
listId,
updates,
null,
null);
// Here is one method in request, so there is one matched result element in response.
if (null == resultOfUpdateListItemWithKnowledge || null == resultOfUpdateListItemWithKnowledge.Results
|| 1 != resultOfUpdateListItemWithKnowledge.Results.Length)
{
this.Site.Assert.Fail("Could not get the expected result information from response of UpdateListItemsWithKnowledge operation");
}
// Here is one list item in request, so that there is one z:row that should be returned.
if (null == resultOfUpdateListItemWithKnowledge.Results[0].Any || 1 != resultOfUpdateListItemWithKnowledge.Results[0].Any.Length)
{
this.Site.Assert.Fail("Could not get the updated list item detail from response of UpdateListItemsWithKnowledge operation");
}
// If the SUT protocol presents the error code "0x81020016" in the response of resultOfUpdateListItemWithKnowledge operation,
// capture R2328.
Site.CaptureRequirementIfAreEqual<string>(
"0x81020016",
resultOfUpdateListItemWithKnowledge.Results[0].ErrorCode,
2328,
"[In UpdateListItemsWithKnowledgeResult][In UpdateListItemsWithKnowledgeResponse]"
+ "[In UpdateListItemsWithKnowledgeResult element] This [error code 0x81020016] "
+ "specifies that the list item referred to in the request does not exist.");
}