/// <summary> /// The GetAttachmentCollection operation is used to retrieve information about all the lists on the current site. /// </summary> /// <param name="listName">A parameter represents the list name or GUID for returning the result.</param> /// <param name="listItemId">A parameter represents the identifier of the content type which will be collected.</param> /// <returns>Return attachment collection result.</returns> public GetAttachmentCollectionResponseGetAttachmentCollectionResult GetAttachmentCollection(string listName, string listItemId) { if (null == this.listsProxy) { throw new InvalidOperationException("The Proxy instance is NULL, need to initialize the adapter"); } GetAttachmentCollectionResponseGetAttachmentCollectionResult result = null; result = this.listsProxy.GetAttachmentCollection(listName, listItemId); this.VerifyTransportRequirement(); return(result); }
/// <summary> /// A method used to verify the response of GetAttachmentCollection whether contain expected Number Attachment items. If it does not pass the verification, this method will throw a Assert exception. /// </summary> /// <param name="getAttachementCollectionResult">A parameter represents the response of GetAttachmentCollection operation.</param> /// <param name="expectedAttachmentsNumber">A parameter represents the expected attachment items' number which is used to check the response of GetAttachmentCollection operation.</param> /// <returns>Return true indicating the response of GetAttachmentCollection contains expected number of attachment items</returns> private bool VerifyWhetherContainExpectedNumberAttachment(GetAttachmentCollectionResponseGetAttachmentCollectionResult getAttachementCollectionResult, int expectedAttachmentsNumber) { this.Site.Assert.IsNotNull(getAttachementCollectionResult, "The GetAttachmentCollection operation should return valid response."); this.Site.Assert.IsNotNull(getAttachementCollectionResult.Attachments, "The response of GetAttachmentCollection operation should contain valid attachments data."); // Verify the number of attachment collection's items whether equal to expected value. this.Site.Assert.AreEqual <int>( expectedAttachmentsNumber, getAttachementCollectionResult.Attachments.Length, "The response of GetAttachmentCollection operation should contain [{0}] expected attachments data, actual:[{1}]", expectedAttachmentsNumber, getAttachementCollectionResult.Attachments.Length); return(true); }
public void MSOUTSPS_S01_TC04_OperateAttachment_TasksTemplateType() { #region Add a list item // Add one list into SUT. string listId = this.AddListToSUT(TemplateType.Tasks); // Add one list item List <string> addedListitems = this.AddItemsToList(listId, 1); string addedListitemId = addedListitems[0]; byte[] attachmentContent = this.GenerateUniqueAttachmentContents(5); string attachmentName = this.GetUniqueAttachmentName(); #endregion #region AddAttachment operation // Call AddAttachment operation. OutspsAdapter.AddAttachment( listId, addedListitemId, attachmentName, attachmentContent); #endregion #region HTTPGET operation // Get full URL of an attachment string fullUrlOfAttachment = this.GetAttachmentFullUrl(listId, addedListitemId, attachmentName); // Call HTTPGET operation. Uri fullUrlOfAttachmentPath; if (!Uri.TryCreate(fullUrlOfAttachment, UriKind.RelativeOrAbsolute, out fullUrlOfAttachmentPath)) { this.Site.Assert.Fail("The full url of attachment should be valid Uri format string."); } byte[] getContentsOfAttachment = OutspsAdapter.HTTPGET(fullUrlOfAttachmentPath, "f"); this.Site.Assert.AreEqual <int>( attachmentContent.Length, getContentsOfAttachment.Length, "The attachment content's length should equal to added by AddAttachment operation."); #endregion #region GetAttachmentCollection operation byte[] attachmentContentSecond = this.GenerateUniqueAttachmentContents(5); string attachmentNameSecond = this.GetUniqueAttachmentName(); // Call the AddAttachment operation. OutspsAdapter.AddAttachment( listId, addedListitemId, attachmentNameSecond, attachmentContentSecond); // Call GetAttachmentCollection operation. GetAttachmentCollectionResponseGetAttachmentCollectionResult getAttachementCollectionResult = OutspsAdapter.GetAttachmentCollection(listId, addedListitemId); // If add new attachment successfully, total attachment number is 2 this.VerifyWhetherContainExpectedNumberAttachment(getAttachementCollectionResult, 2); #endregion if (Common.IsRequirementEnabled(106802, this.Site)) { #region GetListItemChangesSinceToken operation // Set CamlQueryOptions and view fields make the "attachment" field present in response. CamlQueryOptions camloptions = new CamlQueryOptions(); camloptions.QueryOptions = new CamlQueryOptionsQueryOptions(); camloptions.QueryOptions.IncludeAttachmentUrls = bool.TrueString; camloptions.QueryOptions.IncludeAttachmentVersion = bool.TrueString; CamlViewFields viewfieds = this.GenerateViewFields(false, new List <string> { "Attachments" }); // Call GetListItemChangesSinceToken operation. GetListItemChangesSinceTokenResponseGetListItemChangesSinceTokenResult getlistItemChangesRes = null; getlistItemChangesRes = OutspsAdapter.GetListItemChangesSinceToken( listId, null, null, viewfieds, null, camloptions, null, null); this.Site.Assert.IsNotNull(getlistItemChangesRes, "SUT should return a response contain data."); string headerValue = this.GetIfMatchHeaderValueFromResponse(getlistItemChangesRes, fullUrlOfAttachment, int.Parse(addedListitemId)); #endregion #region HTTPPUT operation // Call HTTPPUT operation. fullUrlOfAttachmentPath = null; if (!Uri.TryCreate(fullUrlOfAttachment, UriKind.RelativeOrAbsolute, out fullUrlOfAttachmentPath)) { this.Site.Assert.Fail("The full url of attachment should be valid Uri format string."); } byte[] newattachmentContents = this.GenerateUniqueAttachmentContents(6); OutspsAdapter.HTTPPUT(fullUrlOfAttachmentPath, headerValue, newattachmentContents); // Verify updated attachment. this.VerifyAttachmentContentsLength(fullUrlOfAttachment, newattachmentContents.Length); #endregion } OutspsAdapter.DeleteAttachment(listId, addedListitemId, fullUrlOfAttachment); // Verify whether delete attachment succeed. this.VerifyDeleteAttachmentSucceed(fullUrlOfAttachment); }
public void MSOUTSPS_S01_TC01_OperateAttachment_AppointmentTemplateType() { #region Add a list item // Add one list into SUT. string listId = this.AddListToSUT(TemplateType.Events); // Add one list item List <string> addedListitems = this.AddItemsToList(listId, 1); string addedListitemId = addedListitems[0]; byte[] attachmentContent = this.GenerateUniqueAttachmentContents(5); string attachmentName = this.GetUniqueAttachmentName(); #endregion #region AddAttachment operation // Call AddAttachment operation. string fileUrl = OutspsAdapter.AddAttachment( listId, addedListitemId, attachmentName, attachmentContent); #endregion #region HTTPGET operation // Get full URL of an attachment string fullUrlOfAttachment = this.GetAttachmentFullUrl(listId, addedListitemId, attachmentName); Uri fullUrlOfAttachmentPath; if (!Uri.TryCreate(fullUrlOfAttachment, UriKind.RelativeOrAbsolute, out fullUrlOfAttachmentPath)) { this.Site.Assert.Fail("The full url of attachment should be valid Uri format string."); } // Call HTTPGET operation. byte[] getContentsOfAttachment = OutspsAdapter.HTTPGET(fullUrlOfAttachmentPath, "f"); #endregion #region Capture R1062, R1070, R1073, R1075 // If the length of attachment content in protocol SUT equal to added by AddAttachment operation, then capture R1062, R1070, R1073 Site.CaptureRequirementIfAreEqual( attachmentContent.Length, getContentsOfAttachment.Length, 1062, "[In Message Processing Events and Sequencing Rules][The operation]AddAttachment Adds an attachment to an item."); // Verify MS-OUTSPS requirement: MS-OUTSPS_R1070 Site.CaptureRequirementIfAreEqual( attachmentContent.Length, getContentsOfAttachment.Length, 1070, "[In AddAttachment]AddAttachment is used by protocol clients to create a new attachment on an item on the protocol server."); // Verify MS-OUTSPS requirement: MS-OUTSPS_R10730 Site.CaptureRequirementIfAreEqual( attachmentContent.Length, getContentsOfAttachment.Length, 10730, "[In Messages]AddAttachmentResponse specified the response to a request to create a new attachment on an item on the protocol server."); // If the AddAttachment operation return valid attachment url, then Capture R1075 Site.CaptureRequirementIfIsNotNull( fileUrl, 1075, "[In AddAttachmentResponse]If an AddAttachmentResponse is received, then the upload was successful."); #endregion #region GetAttachmentCollection operation byte[] attachmentContentSecond = this.GenerateUniqueAttachmentContents(5); string attachmentNameSecond = this.GetUniqueAttachmentName(); // Call the AddAttachment operation. OutspsAdapter.AddAttachment( listId, addedListitemId, attachmentNameSecond, attachmentContentSecond); // Call GetAttachmentCollection operation. GetAttachmentCollectionResponseGetAttachmentCollectionResult getAttachementCollectionResult = OutspsAdapter.GetAttachmentCollection(listId, addedListitemId); #endregion #region Capture R1065, R11000 // If add new attachment successfully, total attachment number is 2, Capture R1065, R11000 bool isContainExpectedAttachment = this.VerifyWhetherContainExpectedNumberAttachment(getAttachementCollectionResult, 2); this.Site.CaptureRequirementIfIsTrue( isContainExpectedAttachment, 1065, "[In Message Processing Events and Sequencing Rules][The operation]GetAttachmentCollection Gets a list of the attachments on an item."); this.Site.CaptureRequirementIfIsTrue( isContainExpectedAttachment, 11000, "[In Messages]GetAttachmentCollectionResponse specified the response to a request to get the list of all attachments on a single item in one list."); #endregion if (Common.IsRequirementEnabled(106802, this.Site)) { #region GetListItemChangesSinceToken operation // Set CamlQueryOptions and view fields make the "attachment" field present in response. CamlQueryOptions camloptions = new CamlQueryOptions(); camloptions.QueryOptions = new CamlQueryOptionsQueryOptions(); camloptions.QueryOptions.IncludeAttachmentUrls = bool.TrueString; camloptions.QueryOptions.IncludeAttachmentVersion = bool.TrueString; CamlViewFields viewfieds = this.GenerateViewFields(false, new List <string> { "Attachments" }); // Call GetListItemChangesSinceToken operation. GetListItemChangesSinceTokenResponseGetListItemChangesSinceTokenResult getListItemChangesRes = null; getListItemChangesRes = OutspsAdapter.GetListItemChangesSinceToken( listId, null, null, viewfieds, null, camloptions, null, null); this.Site.Assert.IsNotNull(getListItemChangesRes, "SUT should return a response contain data."); string headerValue = this.GetIfMatchHeaderValueFromResponse(getListItemChangesRes, fullUrlOfAttachment, int.Parse(addedListitemId)); #endregion #region Capture R1241 // If the header is returned, then R1241 should be covered. this.Site.CaptureRequirementIfIsNotNull( headerValue, 1241, "[In HTTP PUT]The Attachments property MUST contain a file version if protocol clients have included the IncludeAttachmentUrls and IncludeAttachmentVersion elements specified in [MS-LISTSWS]."); #endregion #region HTTPPUT operation // Call HTTPPUT operation to update the attachment contents for the first attachment. fullUrlOfAttachmentPath = null; if (!Uri.TryCreate(fullUrlOfAttachment, UriKind.RelativeOrAbsolute, out fullUrlOfAttachmentPath)) { this.Site.Assert.Fail("The full url of attachment should be valid Uri format string."); } byte[] newattachmentContents = this.GenerateUniqueAttachmentContents(6); OutspsAdapter.HTTPPUT(fullUrlOfAttachmentPath, headerValue, newattachmentContents); // Verify the updated attachment contents' length this.VerifyAttachmentContentsLength(fullUrlOfAttachment, newattachmentContents.Length); #endregion } OutspsAdapter.DeleteAttachment(listId, addedListitemId, fullUrlOfAttachment); #region Capture R10930 // If the operation does not return SoapException, capture R10930 directly. Because the schema of the DeleteAttachmentResponse define in [MS-LISTSWS]: <s:element name="DeleteAttachmentResponse"><s:complexType/></s:element>, does not contain any complex type definition, so the proxy class marked this operation as void type return. this.Site.CaptureRequirement( 10930, "[In Messages]DeleteAttachmentResponse specified the response to a request to delete attachments from an item on the protocol server."); #endregion // Verify whether the attachment was deleted. bool isDeleteSucceed = this.VerifyDeleteAttachmentSucceed(fullUrlOfAttachment); #region Capture R1064, R1091 // Because the specified attachment was deleted, the HTTPGET operation could not find it, so there will have a soap exception. this.Site.CaptureRequirementIfIsTrue( isDeleteSucceed, 1064, @"[In Message Processing Events and Sequencing Rules][The operation]DeleteAttachment Deletes an attachment from an item on a list."); this.Site.CaptureRequirementIfIsTrue( isDeleteSucceed, 1091, @"[In DeleteAttachment]Protocol clients use DeleteAttachment to delete attachments from an item on the protocol server."); #endregion }
/// <summary> /// Verify the message syntax of GetAttachmentCollection operation when the response is /// received successfully. /// </summary> /// <param name="getAttachmentCollectionResult">The result of the operation.</param> private void VerifyGetAttachmentCollectionOperation( GetAttachmentCollectionResponseGetAttachmentCollectionResult getAttachmentCollectionResult) { this.Site.Assert.IsNotNull(getAttachmentCollectionResult, "Should get a correct response from GetAttachmentCollection operation."); // Verify R548 this.Site.Log.Add( LogEntryKind.Debug, "The actual value: getAttachmentCollectionResult.Attachments.Length[{0}] for requirement #R548", getAttachmentCollectionResult.Attachments.Length); this.Site.CaptureRequirementIfIsNotNull( getAttachmentCollectionResult.Attachments, 548, @"[In GetAttachmentCollection operation] If the operation succeeds, the protocol server MUST return the collection of attachment URLs for the specified list item."); // Verify R1746 // The response have been received successfully, then the following requirement can be captured. // If the response is not received and parsed successfully, the test case will fail before this requirement is captured Site.CaptureRequirement( 1746, @"[The schema of GetAttachmentCollection is defined as:]" + @"<wsdl:operation name=""GetAttachmentCollection"">" + @" <wsdl:input message=""GetAttachmentCollectionSoapIn"" />" + @" <wsdl:output message=""GetAttachmentCollectionSoapOut"" />" + @"</wsdl:operation>"); // Verify R533 // The response have been received successfully, then the following requirement can be captured. // If the response is not received and parsed successfully, the test case will fail before this requirement is captured Site.CaptureRequirement( 533, @"[In GetAttachmentCollection operation] [If the protocol client sends a " + "GetAttachmentCollectionSoapIn request message] the protocol server " + "responds with a GetAttachmentCollectionSoapOut response message."); // Verify R1753 // The response have been received successfully, then the following requirement can be captured. // If the response is not received and parsed successfully, the test case will fail before this requirement is captured Site.CaptureRequirement( 1753, @"[GetAttachmentCollectionSoapOut]The SOAP Body contains a " + "GetAttachmentCollectionResponse element."); // Verify R1758 // The response have been received successfully, then the following requirement can be captured. // If the response is not received and parsed successfully, the test case will fail before this requirement is captured Site.CaptureRequirement( 1758, @"[The schema of GetAttachmentCollectionResponse is defined as:]" + @"<s:element name=""GetAttachmentCollectionResponse"">" + @" <s:complexType>" + @" <s:sequence>" + @" <s:element name=""GetAttachmentCollectionResult"" minOccurs=""0"">" + @" <s:complexType mixed=""true"">" + @" <s:sequence>" + @" <s:element name=""Attachments"">" + @" <s:complexType>" + @" <s:sequence>" + @" <s:element name=""Attachment"" type=""s:string"" minOccurs=""0"" " + @" maxOccurs=""unbounded"">" + @" </s:element>" + @" </s:sequence>" + @" </s:complexType>" + @" </s:element>" + @" </s:sequence>" + @" </s:complexType>" + @" </s:element>" + @" </s:sequence>" + @" </s:complexType>" + @"</s:element>"); }
/// <summary> /// A method used to get attachment Url from response of GetAttachmentCollection operation /// </summary> /// <param name="responseOfGetAttachmentColection">A parameter represents the response of GetAttachmentCollection operation which should contain expected attachment url.</param> /// <param name="attachmentName">A parameter represents the name of attachment which is used to find out the url from the response of GetAttachmentCollection operation.</param> /// <returns>A return value represents the url of specified attachment.</returns> protected string GetAttachmentUrlFromResponse(GetAttachmentCollectionResponseGetAttachmentCollectionResult responseOfGetAttachmentColection, string attachmentName) { if (null == responseOfGetAttachmentColection || null == responseOfGetAttachmentColection.Attachments || responseOfGetAttachmentColection.Attachments.Length == 0) { throw new ArgumentException("The response of GetAttachmentColection operation should contain valid attachment data.", "responseOfGetAttachmentColection"); } // Get the attachment URL from GetAttachmentCollection response. // The URL value is contained in string array, which is defined in [MS-LISTSWS]. // There is at least one text item which contain the "attachmentFileName" in the Text array. string attachmentUrl = string.Empty; var urlItems = from urlItem in responseOfGetAttachmentColection.Attachments where urlItem.IndexOf(attachmentName, StringComparison.OrdinalIgnoreCase) >= 0 select urlItem; if (urlItems.Count() > 0) { attachmentUrl = urlItems.ElementAt(0); } else { this.Site.Assert.Fail( "The response of GetAttachmentColection operation does not contain the url information for the attachment[{0}]", attachmentName); } return attachmentUrl; }