/// <summary>
        /// Builds a ItemOperations request to fetch the whole content of the notes
        /// </summary>
        /// <param name="collectionId">Specifies the notes folder</param>
        /// <param name="serverIds">Specifies a unique identifier that is assigned by the server for the notes</param>
        /// <param name="longIds">Specifies a unique identifier that is assigned by the server to each result returned by a previous Search response.</param>
        /// <param name="bodyPreference">Sets preference information related to the type and size of the body.</param>
        /// <param name="schema">Specifies the schema of the item to be fetched.</param>
        /// <returns>Returns the ItemOperationsRequest instance</returns>
        internal static ItemOperationsRequest CreateItemOperationsFetchRequest(
            string collectionId,
            List <string> serverIds,
            List <string> longIds,
            Request.BodyPreference bodyPreference,
            Request.Schema schema)
        {
            Request.ItemOperationsFetchOptions fetchOptions = new Request.ItemOperationsFetchOptions();
            List <object> fetchOptionItems = new List <object>();
            List <Request.ItemsChoiceType5> fetchOptionItemsName = new List <Request.ItemsChoiceType5>();

            if (null != bodyPreference)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.BodyPreference);
                fetchOptionItems.Add(bodyPreference);
            }

            if (null != schema)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.Schema);
                fetchOptionItems.Add(schema);
            }

            fetchOptions.Items            = fetchOptionItems.ToArray();
            fetchOptions.ItemsElementName = fetchOptionItemsName.ToArray();

            List <Request.ItemOperationsFetch> fetchElements = new List <Request.ItemOperationsFetch>();

            if (serverIds != null)
            {
                foreach (string serverId in serverIds)
                {
                    Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch()
                    {
                        CollectionId = collectionId,
                        ServerId     = serverId,
                        Store        = SearchName.Mailbox.ToString(),
                        Options      = fetchOptions
                    };
                    fetchElements.Add(fetchElement);
                }
            }

            if (longIds != null)
            {
                foreach (string longId in longIds)
                {
                    Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch()
                    {
                        LongId  = longId,
                        Store   = SearchName.Mailbox.ToString(),
                        Options = fetchOptions
                    };
                    fetchElements.Add(fetchElement);
                }
            }

            return(Common.CreateItemOperationsRequest(fetchElements.ToArray()));
        }
        /// <summary>
        /// Builds a ItemOperations request to fetch the whole content of a single mail item
        /// by using the specified collectionId, emailServerId,bodyPreference and bodyPartPreference
        /// In general, returns the XML formatted ItemOperations request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <ItemOperations xmlns="ItemOperations" xmlns:airsync="AirSync" xmlns:airsyncbase="AirSyncBase">
        ///    <Fetch>
        ///       <Store>Mailbox</Store>
        ///       <airsync:CollectionId>5</airsync:CollectionId>
        ///       <airsync:ServerId>5:1</airsync:ServerId>
        ///       <Options>
        ///          <airsync:MIMESupport>2</airsync:MIMESupport>
        ///          <airsyncbase:BodyPreference>
        ///             <airsyncbase:Type>4</airsyncbase:Type>
        ///          </airsyncbase:BodyPreference>
        ///          <airsyncbase:BodyPreference>
        ///             <airsyncbase:Type>2</airsyncbase:Type>
        ///          </airsyncbase:BodyPreference>
        ///       </Options>
        ///    </Fetch>
        /// </ItemOperations>
        /// -->
        /// </summary>
        /// <param name="collectionId">Specify the folder of mailItem, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.2)</param>
        /// <param name="serverIds">Specify a unique identifier that was assigned by the server for a mailItem, which can be returned by ActiveSync Sync command(Refer to [MS-ASCMD]2.2.3.151.5)</param>
        /// <param name="schema">Sets the schema information</param>
        /// <returns>Returns the ItemOperationsRequest instance</returns>
        internal static ItemOperationsRequest CreateItemOperationsFetchRequest(string collectionId, List <string> serverIds, Request.Schema schema)
        {
            Request.ItemOperations itemOperations = new Request.ItemOperations();
            List <object>          items          = new List <object>();

            Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch();

            if (serverIds != null)
            {
                foreach (string item in serverIds)
                {
                    fetchElement.CollectionId = collectionId;
                    fetchElement.ServerId     = item;
                    items.Add(fetchElement);
                }
            }

            itemOperations.Items = items.ToArray();

            foreach (object item in itemOperations.Items)
            {
                Request.ItemOperationsFetch fetch = item as Request.ItemOperationsFetch;
                if (fetch != null)
                {
                    fetch.Store = SearchName.Mailbox.ToString();
                    Request.ItemOperationsFetchOptions fetchOptions = new Request.ItemOperationsFetchOptions();

                    List <object> fetchOptionItems = new List <object>();
                    List <Request.ItemsChoiceType5> fetchOptionItemsName = new List <Request.ItemsChoiceType5>
                    {
                        Request.ItemsChoiceType5.BodyPreference,
                        Request.ItemsChoiceType5.Schema
                    };

                    fetchOptionItems.Add(
                        new Request.BodyPreference()
                    {
                        AllOrNone               = false,
                        AllOrNoneSpecified      = false,
                        TruncationSize          = 0,
                        TruncationSizeSpecified = false,
                        Preview          = 0,
                        PreviewSpecified = false,
                        Type             = 2,
                    });
                    fetchOptionItems.Add(schema);

                    fetchOptions.Items            = fetchOptionItems.ToArray();
                    fetchOptions.ItemsElementName = fetchOptionItemsName.ToArray();
                    fetch.Options = fetchOptions;
                }
            }

            return(Common.CreateItemOperationsRequest(itemOperations.Items));
        }
        /// <summary>
        /// Create an ItemOperations command request.
        /// </summary>
        /// <param name="collectionId">The collection id.</param>
        /// <param name="serverId">The serverId of the item.</param>
        /// <param name="bodyPreference">The bodyPreference in the options element.</param>
        /// <param name="schema">Sets the schema information.</param>
        /// <returns>An ItemOperations command request.</returns>
        internal static ItemOperationsRequest CreateItemOperationsRequest(string collectionId, string serverId, Request.BodyPreference bodyPreference, Request.Schema schema)
        {
            ItemOperationsRequest request = new ItemOperationsRequest {
                RequestData = new Request.ItemOperations()
            };

            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                Store        = SearchName.Mailbox.ToString(),
                CollectionId = collectionId,
                ServerId     = serverId
            };

            List <object> items = new List <object>();
            List <Request.ItemsChoiceType5> itemsElementName = new List <Request.ItemsChoiceType5>();

            if (null != schema)
            {
                itemsElementName.Add(Request.ItemsChoiceType5.Schema);
                items.Add(schema);
            }

            if (null != bodyPreference)
            {
                itemsElementName.Add(Request.ItemsChoiceType5.BodyPreference);
                items.Add(bodyPreference);

                if (bodyPreference.Type == 0x4)
                {
                    itemsElementName.Add(Request.ItemsChoiceType5.MIMESupport);

                    // '2' indicates server sends MIME data for all messages but not S/MIME messages only
                    items.Add((byte)0x2);
                }
            }

            if (items.Count > 0)
            {
                fetch.Options = new Request.ItemOperationsFetchOptions()
                {
                    ItemsElementName = itemsElementName.ToArray(),
                    Items            = items.ToArray()
                };
            }

            request.RequestData.Items = new object[] { fetch };

            return(request);
        }
        /// <summary>
        /// Check if the request of ItemOperations command contains the schema element
        /// </summary>
        /// <param name="itemOperationsRequest">ItemOperations command request.</param>
        /// <returns>The boolean value represents whether the request of ItemOperations command contains the schema element</returns>
        public static bool ContainsSchemaElement(ActiveSyncRequestBase <Request.ItemOperations> itemOperationsRequest)
        {
            Request.ItemOperationsFetch fetch = (Request.ItemOperationsFetch)itemOperationsRequest.RequestData.Items[0];

            bool hasSchemaElement = false;

            // Check if the request contains schema
            foreach (object item in fetch.Options.Items)
            {
                if (item.GetType().Equals(typeof(Request.Schema)))
                {
                    hasSchemaElement = true;
                }
            }

            return(hasSchemaElement);
        }
        /// <summary>
        /// Get the request of ItemOperations command.
        /// </summary>
        /// <param name="collectionId">The collection id of the folder to fetch.</param>
        /// <param name="serverId">The server id of the mail.</param>
        /// <param name="bodyPartPreference">The BodyPartPreference in the Options element.</param>
        /// <param name="bodyPreference">The BodyPreference in the Options element.</param>
        /// <returns>An ItemOperations command request.</returns>
        internal static ItemOperationsRequest GetItemOperationsRequest(string collectionId, string serverId, Request.BodyPartPreference bodyPartPreference, Request.BodyPreference bodyPreference)
        {
            ItemOperationsRequest request = new ItemOperationsRequest {
                RequestData = new Request.ItemOperations()
            };

            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                Store        = SearchName.Mailbox.ToString(),
                CollectionId = collectionId,
                ServerId     = serverId
            };

            List <object> items = new List <object>();
            List <Request.ItemsChoiceType5> itemsElementName = new List <Request.ItemsChoiceType5>();

            if (bodyPreference != null)
            {
                items.Add(bodyPreference);
                itemsElementName.Add(Request.ItemsChoiceType5.BodyPreference);
            }

            if (bodyPartPreference != null)
            {
                items.Add(bodyPartPreference);
                itemsElementName.Add(Request.ItemsChoiceType5.BodyPartPreference);
            }

            if (items.Count > 0)
            {
                fetch.Options = new Request.ItemOperationsFetchOptions()
                {
                    ItemsElementName = itemsElementName.ToArray(),
                    Items            = items.ToArray()
                };
            }

            request.RequestData.Items = new object[] { fetch };

            return(request);
        }
        /// <summary>
        /// Get the request of ItemOperations command.
        /// </summary>
        /// <param name="collectionId">The collection id of the folder to fetch.</param>
        /// <param name="serverId">The server id of the mail.</param>
        /// <param name="bodyPartPreference">The BodyPartPreference in the Options element.</param>
        /// <param name="bodyPreference">The BodyPreference in the Options element.</param>
        /// <returns>An ItemOperations command request.</returns>
        internal static ItemOperationsRequest GetItemOperationsRequest(string collectionId, string serverId, Request.BodyPartPreference bodyPartPreference, Request.BodyPreference bodyPreference)
        {
            ItemOperationsRequest request = new ItemOperationsRequest { RequestData = new Request.ItemOperations() };
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                Store = SearchName.Mailbox.ToString(),
                CollectionId = collectionId,
                ServerId = serverId
            };

            List<object> items = new List<object>();
            List<Request.ItemsChoiceType5> itemsElementName = new List<Request.ItemsChoiceType5>();

            if (bodyPreference != null)
            {
                items.Add(bodyPreference);
                itemsElementName.Add(Request.ItemsChoiceType5.BodyPreference);
            }

            if (bodyPartPreference != null)
            {
                items.Add(bodyPartPreference);
                itemsElementName.Add(Request.ItemsChoiceType5.BodyPartPreference);
            }

            if (items.Count > 0)
            {
                fetch.Options = new Request.ItemOperationsFetchOptions()
                {
                    ItemsElementName = itemsElementName.ToArray(),
                    Items = items.ToArray()
                };
            }

            request.RequestData.Items = new object[] { fetch };

            return request;
        }
        public void MSASCMD_S08_TC11_ItemOperations_Fetch_DocumentLibrary()
        {
            #region Call method ItemOperations to get data of a shared document with inline method.
            // Initialize a Fetch element.
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                LinkId = Common.GetConfigurationPropertyValue("SharedDocument1", this.Site),
                Store = SearchName.DocumentLibrary.ToString(),
                Options = new Request.ItemOperationsFetchOptions
                {
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.UserName, Request.ItemsChoiceType5.Password },
                    Items = new string[] { this.User1Information.UserName, this.User1Information.UserPassword }
                }
            };

            // Create an ItemOperations command request.
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });

            // Send request and get response.
            ItemOperationsResponse itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.Inline);
            string data = this.GetDataElement(itemOperationsResponse);
            Site.Assert.IsNotNull(data, "The Data element of the ItemOperations response should not be null.");
            byte[] contents = new byte[0];

            try
            {
                contents = Convert.FromBase64String(data);
            }
            catch (FormatException formatException)
            {
                Site.Assert.Fail("The binary content should be base64 encoded. Detail exception message: {0}", formatException.Message);
            }

            // If data string can be successful decoded with base64, that means the data string is encoded with base64 encoding, then MS-ASCMD_R234, MS-ASCMD_R2301 are verified.
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R234");

            // Verify MS-ASCMD requirement: MS-ASCMD_R234
            Site.CaptureRequirement(
                234,
                @"[In Delivery of Content Requested by Fetch] The inline method of delivering binary content is including data encoded with base64 encoding inside the WBXML.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2301");

            // Verify MS-ASCMD requirement: MS-ASCMD_R2301
            Site.CaptureRequirement(
                2301,
                @"[In Fetch(ItemOperations)] Because the ItemOperations response potentially contains large amounts of binary data, this protocol [MS-ASCMD] enables the client to choose a delivery method that is most efficient for its implementation by providing the following two methods to deliver content that is requested by the Fetch element: Inline-The binary content is encoded with base64 encoding and is included inside the WBXML.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5919");

            bool existVersionElement = false;

            for (int i = 0; i < itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.ItemsElementName.Length; i++)
            {
                if (itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.ItemsElementName[i] == Response.ItemsChoiceType3.Version)
                {
                    existVersionElement = true;
                    break;
                }
            }

            // Verify MS-ASCMD requirement: MS-ASCMD_R5919
            Site.CaptureRequirementIfIsTrue(
                existVersionElement,
                5919,
                @"[In Version] The Version element is present only when the ItemOperations command is used to access a [Windows SharePoint Services or] UNC resource.");

            #endregion

            #region Call method ItemOperations to get data of a shared document with MultiPart method.
            // Send request and get response.
            itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.MultiPart);
            data = this.GetDataElement(itemOperationsResponse);
            Site.Assert.IsNull(data, "The Data element of the ItemOperations response should be null.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5434");

            bool existPartElement = false;

            for (int i = 0; i < itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.ItemsElementName.Length; i++)
            {
                if (itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.ItemsElementName[i] == Response.ItemsChoiceType3.Part)
                {
                    existPartElement = true;
                    break;
                }
            }

            // Verify MS-ASCMD requirement: MS-ASCMD_R5434
            Site.CaptureRequirementIfIsTrue(
                existPartElement,
                5434,
                @"[In Part] It [Part element] is a child of the Properties element if the item being fetched is located in a document library.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2302");

            Site.Assert.IsTrue(itemOperationsResponse.MultipartMetadata.PartsCount >= 2, "There should be at least 2 parts, since the first part is WBXML, the subsequent parts contains non-empty data in txt file. Actual parts count: {0}", itemOperationsResponse.MultipartMetadata.PartsCount);
            int contentLength = 0;
            for (int i = 1; i < itemOperationsResponse.MultipartMetadata.PartsMetaData.Length; i++)
            {
                contentLength += itemOperationsResponse.MultipartMetadata.PartsMetaData[i].Count;
            }

            Site.Assert.IsTrue(contentLength > 0, "The subsequent parts should contains non-empty data in txt file, the length of the data in txt file: {0}.", contentLength);

            // Verify MS-ASCMD requirement: MS-ASCMD_R2302
            // The multipart structure have been implemented in the test suite's adapter, and the WBXML data in first part is converted to XML string, and de-serialized as proxy class in Response element,
            // There should be at least 2 parts, since the first part is WBXML, and is de-serialized into Response element, the subsequent parts contains non-empty data in txt file.
            Site.CaptureRequirement(
                2302,
                @"[In Fetch(ItemOperations)] [Because the ItemOperations response potentially contains large amounts of binary data, this protocol [MS-ASCMD] enables the client to choose a delivery method that is most efficient for its implementation by providing the following two methods to deliver content that is requested by the Fetch element:] Multipart-This method involves a multipart structure in which the WBXML is the first part, and the requested data populates the subsequent parts.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R236");

            // Verify MS-ASCMD requirement: MS-ASCMD_R236
            // This requirement can be captured after above steps.
            Site.CaptureRequirement(
                236,
                @"[In Delivery of Content Requested by Fetch] The multipart method of delivering content is a multipart structure with the WBXML being the first part, and the requested data populating the subsequent parts.");

            #endregion

            #region Call method ItemOperations to get data of a shared document with inline method and Range element specified as "0-0" to fetch the first byte.

            // Initialize a Fetch element.
            fetch = new Request.ItemOperationsFetch
            {
                LinkId = Common.GetConfigurationPropertyValue("SharedDocument1", this.Site),
                Store = SearchName.DocumentLibrary.ToString(),
                Options = new Request.ItemOperationsFetchOptions
                {
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.UserName, Request.ItemsChoiceType5.Password, Request.ItemsChoiceType5.Range },
                    Items = new string[] { this.User1Information.UserName, this.User1Information.UserPassword, "0-0" }
                }
            };

            // Create an ItemOperations command request.
            itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });

            // Send request and get response.
            itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.Inline);
            data = this.GetDataElement(itemOperationsResponse);
            Site.Assert.IsNotNull(data, "The Data element of the ItemOperations response should not be null.");
            byte[] firstByte = new byte[0];
            try
            {
                firstByte = Convert.FromBase64String(data);
            }
            catch (FormatException formatException)
            {
                Site.Assert.Fail("The binary content should be base64 encoded. Detail exception message: {0}", formatException.Message);
            }

            Site.Assert.AreEqual<int>(1, firstByte.Length, "There should be only 1 byte returned as specified in Range element.");
            int total = 0;

            for (int i = 0; i < itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.ItemsElementName.Length; i++)
            {
                if (itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.ItemsElementName[i] == Response.ItemsChoiceType3.Total)
                {
                    total = int.Parse(itemOperationsResponse.ResponseData.Response.Fetch[0].Properties.Items[i].ToString());
                    break;
                }
            }

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R3716");

            // Verify MS-ASCMD requirement: MS-ASCMD_R3716
            Site.CaptureRequirementIfAreEqual<int>(
                total,
                contents.Length,
                3716,
                @"[In Range(ItemOperations)] If the Range element is omitted in the Fetch request, the whole item is fetched.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5422");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5422
            // If server responds with a successful status code, which including the Range element as "0-0", this requirement can be captured.
            Site.CaptureRequirementIfAreEqual<string>(
                "1",
                itemOperationsResponse.ResponseData.Response.Fetch[0].Status,
                5422,
                @"[In Range] The byte range is zero-indexed.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5423");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5423
            // If the returned byte equals to the first byte of the document's content, this requirement can be captured.
            Site.CaptureRequirementIfAreEqual<byte>(
                contents[0],
                firstByte[0],
                5423,
                @"[In Range] The first byte is indicated by a 0 (zero).");
            #endregion
        }
        /// <summary>
        /// Call ItemOperations command.
        /// </summary>
        /// <param name="collectionId">The CollectionId of the folder.</param>
        /// <param name="itemServerId">The ServerId of the email to be fetched.</param>
        /// <param name="acceptMultiPart">Whether need the server to return the requested item in multipart format. It is used in Base64 query value type.</param>
        /// <returns>The response of ItemOperations command.</returns>
        protected SendStringResponse CallItemOperationsCommand(string collectionId, string itemServerId, bool acceptMultiPart)
        {
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                Store = "Mailbox",
                CollectionId = collectionId,
                ServerId = itemServerId
            };

            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });
            Dictionary<CmdParameterName, object> commandParameter = null;
            if (acceptMultiPart)
            {
                commandParameter = new Dictionary<CmdParameterName, object> { { CmdParameterName.Options, 2 } };
            }

            // Call ItemOperations command by HTTP POST.
            SendStringResponse itemOperationsResponse = this.HTTPAdapter.HTTPPOST(CommandName.ItemOperations, commandParameter, itemOperationsRequest.GetRequestDataSerializedXML());

            // Check the command is executed successfully.
            this.CheckResponseStatus(itemOperationsResponse.ResponseDataXML);

            return itemOperationsResponse;
        }
        /// <summary>
        /// Build an ItemOperations command request.
        /// </summary>
        /// <param name="collectionId">The collection id.</param>
        /// <param name="serverId">The server id of the mail.</param>
        /// <param name="fileReference">The file reference of the attachment.</param>
        /// <param name="bodyPreferences">The bodyPreference in the options element.</param>
        /// <param name="bodyPartPreferences">The bodyPartPreference in the options element.</param>
        /// <returns>An ItemOperations command request.</returns>
        internal static ItemOperationsRequest CreateItemOperationsRequest(string collectionId, string serverId, string fileReference, Request.BodyPreference[] bodyPreferences, Request.BodyPartPreference[] bodyPartPreferences)
        {
            ItemOperationsRequest request = new ItemOperationsRequest { RequestData = new Request.ItemOperations() };
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch { Store = SearchName.Mailbox.ToString() };

            if (fileReference != null)
            {
                fetch.FileReference = fileReference;
            }
            else
            {
                fetch.CollectionId = collectionId;
                fetch.ServerId = serverId;
            }

            List<object> items = new List<object>();
            List<Request.ItemsChoiceType5> itemsElementName = new List<Request.ItemsChoiceType5>();

            if (bodyPreferences != null)
            {
                foreach (Request.BodyPreference bodyPreference in bodyPreferences)
                {
                    items.Add(bodyPreference);
                    itemsElementName.Add(Request.ItemsChoiceType5.BodyPreference);

                    // Include the MIMESupport element in request to retrieve the MIME body
                    if (bodyPreference.Type == 4)
                    {
                        items.Add((byte)2);
                        itemsElementName.Add(Request.ItemsChoiceType5.MIMESupport);
                    }
                }
            }

            if (bodyPartPreferences != null)
            {
                foreach (Request.BodyPartPreference bodyPartPreference in bodyPartPreferences)
                {
                    items.Add(bodyPartPreference);
                    itemsElementName.Add(Request.ItemsChoiceType5.BodyPartPreference);
                }
            }

            if (items.Count > 0)
            {
                fetch.Options = new Request.ItemOperationsFetchOptions()
                {
                    ItemsElementName = itemsElementName.ToArray(),
                    Items = items.ToArray()
                };
            }

            request.RequestData.Items = new object[] { fetch };

            return request;
        }
        /// <summary>
        /// Builds a ItemOperations request to fetch the whole content of a single mail item
        /// by using the specified collectionId, emailServerId,bodyPreference and bodyPartPreference
        /// In general, returns the XML formatted ItemOperations request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <ItemOperations xmlns="ItemOperations" xmlns:airsync="AirSync" xmlns:airsyncbase="AirSyncBase">
        ///    <Fetch>
        ///       <Store>Mailbox</Store>
        ///       <airsync:CollectionId>5</airsync:CollectionId>
        ///       <airsync:ServerId>5:1</airsync:ServerId>
        ///       <Options>
        ///          <airsync:MIMESupport>2</airsync:MIMESupport>
        ///          <airsyncbase:BodyPreference>
        ///             <airsyncbase:Type>4</airsyncbase:Type>
        ///          </airsyncbase:BodyPreference>
        ///          <airsyncbase:BodyPreference>
        ///             <airsyncbase:Type>2</airsyncbase:Type>
        ///          </airsyncbase:BodyPreference>
        ///       </Options>
        ///    </Fetch>
        /// </ItemOperations>
        /// -->
        /// </summary>
        /// <param name="collectionId">Specify the folder of mailItem, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.2)</param>
        /// <param name="serverId">Specify a unique identifier that is assigned by the server for a mailItem, which can be returned by ActiveSync Sync command(Refer to [MS-ASCMD]2.2.3.151.5)</param>
        /// <param name="bodyPreference">Sets preference information related to the type and size of information for body (Refer to [MS-ASAIRS] 2.2.2.7)</param>
        /// <param name="bodyPartPreference">Sets preference information related to the type and size of information for a message part (Refer to [MS-ASAIRS] 2.2.2.6)</param>
        /// <param name="schema">Sets the schema information.</param>
        /// <returns>Returns the ItemOperationsRequest instance</returns>
        internal static ItemOperationsRequest CreateItemOperationsFetchRequest(
            string collectionId,
            string serverId,
            Request.BodyPreference bodyPreference,
            Request.BodyPartPreference bodyPartPreference,
            Request.Schema schema)
        {
            // Set the ItemOperations:Fetch Options (See [MS-ASCMD] 2.2.3.115.2 Options)
            //  :: To get the whole content of the specified mail item, just ignore Fetch and Range element.
            //     See [MS-ASCMD] 2.2.3.145 Schema and 2.2.3.130.1 Range
            //  :: UserName, Password is not required by MS-ASEMAIl test case
            Request.ItemOperationsFetchOptions fetchOptions = new Request.ItemOperationsFetchOptions();
            List<object> fetchOptionItems = new List<object>();
            List<Request.ItemsChoiceType5> fetchOptionItemsName = new List<Request.ItemsChoiceType5>();

            if (null != bodyPreference)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.BodyPreference);
                fetchOptionItems.Add(bodyPreference);

                // when body format is mime (Refer to  [MS-ASAIRS] 2.2.2.22 Type)
                if (bodyPreference.Type == 0x4)
                {
                    fetchOptionItemsName.Add(Request.ItemsChoiceType5.MIMESupport);

                    // Magic number '2' indicate server send MIME data for all messages but not S/MIME messages only
                    // (Refer to [MS-ASCMD] 2.2.3.100.1 MIMESupport)
                    fetchOptionItems.Add((byte)0x2);
                }
            }

            if (null != bodyPartPreference)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.BodyPartPreference);
                fetchOptionItems.Add(bodyPartPreference);
            }

            if (null != schema)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.Schema);
                fetchOptionItems.Add(schema);
            }

            fetchOptions.Items = fetchOptionItems.ToArray();
            fetchOptions.ItemsElementName = fetchOptionItemsName.ToArray();

            // *Only to fetch email item in mailbox* by using airsync:CollectionId & ServerId
            // So ignore LongId/LinkId/FileReference/RemoveRightsManagementProtection
            Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch()
            {
                CollectionId = collectionId,
                ServerId = serverId,
                Store = SearchName.Mailbox.ToString(),
                Options = fetchOptions
            };

            return Common.CreateItemOperationsRequest(new object[] { fetchElement });
        }
        /// <summary>
        /// Create an ItemOperations command request.
        /// </summary>
        /// <param name="collectionId">The collection id.</param>
        /// <param name="serverId">The serverId of the item.</param>
        /// <param name="bodyPreference">The bodyPreference in the options element.</param>
        /// <param name="schema">Sets the schema information.</param>
        /// <returns>An ItemOperations command request.</returns>
        internal static ItemOperationsRequest CreateItemOperationsRequest(string collectionId, string serverId, Request.BodyPreference bodyPreference, Request.Schema schema)
        {
            ItemOperationsRequest request = new ItemOperationsRequest { RequestData = new Request.ItemOperations() };
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                Store = SearchName.Mailbox.ToString(),
                CollectionId = collectionId,
                ServerId = serverId
            };

            List<object> items = new List<object>();
            List<Request.ItemsChoiceType5> itemsElementName = new List<Request.ItemsChoiceType5>();

            if (null != schema)
            {
                itemsElementName.Add(Request.ItemsChoiceType5.Schema);
                items.Add(schema);
            }

            if (null != bodyPreference)
            {
                itemsElementName.Add(Request.ItemsChoiceType5.BodyPreference);
                items.Add(bodyPreference);

                if (bodyPreference.Type == 0x4)
                {
                    itemsElementName.Add(Request.ItemsChoiceType5.MIMESupport);

                    // '2' indicates server sends MIME data for all messages but not S/MIME messages only
                    items.Add((byte)0x2);
                }
            }

            if (items.Count > 0)
            {
                fetch.Options = new Request.ItemOperationsFetchOptions()
                {
                    ItemsElementName = itemsElementName.ToArray(),
                    Items = items.ToArray()
                };
            }

            request.RequestData.Items = new object[] { fetch };

            return request;
        }
Beispiel #12
0
        /// <summary>
        /// Build an ItemOperations command request.
        /// </summary>
        /// <param name="collectionId">The collection id.</param>
        /// <param name="serverId">The server id of the mail.</param>
        /// <param name="fileReference">The file reference of the attachment.</param>
        /// <param name="bodyPreferences">The bodyPreference in the options element.</param>
        /// <param name="bodyPartPreferences">The bodyPartPreference in the options element.</param>
        /// <returns>An ItemOperations command request.</returns>
        internal static ItemOperationsRequest CreateItemOperationsRequest(string collectionId, string serverId, string fileReference, Request.BodyPreference[] bodyPreferences, Request.BodyPartPreference[] bodyPartPreferences)
        {
            ItemOperationsRequest request = new ItemOperationsRequest {
                RequestData = new Request.ItemOperations()
            };

            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch {
                Store = SearchName.Mailbox.ToString()
            };

            if (fileReference != null)
            {
                fetch.FileReference = fileReference;
            }
            else
            {
                fetch.CollectionId = collectionId;
                fetch.ServerId     = serverId;
            }

            List <object> items = new List <object>();
            List <Request.ItemsChoiceType5> itemsElementName = new List <Request.ItemsChoiceType5>();

            if (bodyPreferences != null)
            {
                foreach (Request.BodyPreference bodyPreference in bodyPreferences)
                {
                    items.Add(bodyPreference);
                    itemsElementName.Add(Request.ItemsChoiceType5.BodyPreference);

                    // Include the MIMESupport element in request to retrieve the MIME body
                    if (bodyPreference.Type == 4)
                    {
                        items.Add((byte)2);
                        itemsElementName.Add(Request.ItemsChoiceType5.MIMESupport);
                    }
                }
            }

            if (bodyPartPreferences != null)
            {
                foreach (Request.BodyPartPreference bodyPartPreference in bodyPartPreferences)
                {
                    items.Add(bodyPartPreference);
                    itemsElementName.Add(Request.ItemsChoiceType5.BodyPartPreference);
                }
            }

            if (items.Count > 0)
            {
                fetch.Options = new Request.ItemOperationsFetchOptions()
                {
                    ItemsElementName = itemsElementName.ToArray(),
                    Items            = items.ToArray()
                };
            }

            request.RequestData.Items = new object[] { fetch };

            return(request);
        }
        public void MSASRM_S02_TC01_ItemOperations_RightsManagedEmailMessages()
        {
            this.CheckPreconditions();

            #region The client logs on User1's account, calls Settings command to get a templateID with all rights allowed.
            string templateID = this.GetTemplateID("MSASRM_AllRights_AllowedTemplate");
            #endregion

            #region The client logs on User1's account, calls SendMail command with the templateID to send a rights-managed e-mail message to User2, switches to User2, and calls FolderSync command.
            string subject = this.SendMailAndFolderSync(templateID, false, null);
            #endregion

            #region The client logs on User2's account, calls Sync command with RightsManagementSupport element set to true to synchronize changes of Inbox folder in User2's mailbox, and gets the decompressed and decrypted rights-managed e-mail message.
            Sync item = this.SyncEmail(subject, this.UserTwoInformation.InboxCollectionId, true, true);
            Site.Assert.IsNotNull(item, "The returned item should not be null.");
            Site.Assert.IsNull(item.Email.Attachments, "The Attachments element in expected rights-managed e-mail message should be null.");
            Site.Assert.IsNotNull(item.Email.RightsManagementLicense, "The RightsManagementLicense element in expected rights-managed e-mail message should not be null.");
            Site.Assert.IsTrue(item.Email.RightsManagementLicense.ExportAllowed, "The ExportAllowed element in expected rights-managed e-mail message should be true.");
            #endregion

            #region The client logs on User2's account, calls ItemOperations command which contains the Fetch element without RemoveRightsManagementProtection element.
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                CollectionId = this.UserTwoInformation.InboxCollectionId,
                Store        = SearchName.Mailbox.ToString(),
                ServerId     = item.ServerId,
                Options      = new Request.ItemOperationsFetchOptions
                {
                    Items            = new object[] { true },
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.RightsManagementSupport }
                }
            };
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });
            ItemOperationsStore   itemOperationsStore   = this.ASRMAdapter.ItemOperations(itemOperationsRequest);
            Site.Assert.AreEqual <int>(1, itemOperationsStore.Items.Count, "There should be only 1 item fetched in ItemOperations command response.");
            ItemOperations itemOperations = itemOperationsStore.Items[0];
            Site.Assert.IsNotNull(itemOperations, "The returned item should not be null.");
            Site.Assert.IsNotNull(itemOperations.Email, "The expected rights-managed e-mail message should not be null.");
            Site.Assert.IsNull(itemOperations.Email.Attachments, "The Attachments element in expected rights-managed e-mail message should be null.");
            Site.Assert.IsNotNull(itemOperations.Email.RightsManagementLicense, "The RightsManagementLicense element in expected rights-managed e-mail message should not be null.");
            #endregion

            #region The client logs on User2's account, calls ItemOperations command which contains the Fetch element with RemoveRightsManagementProtection element.
            fetch.RemoveRightsManagementProtection = string.Empty;
            itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });
            itemOperationsStore   = this.ASRMAdapter.ItemOperations(itemOperationsRequest);
            Site.Assert.AreEqual <int>(1, itemOperationsStore.Items.Count, "There should be only 1 item fetched in ItemOperations command response.");
            itemOperations = itemOperationsStore.Items[0];
            Site.Assert.IsNotNull(itemOperations, "The returned item should not be null.");
            Site.Assert.IsNotNull(itemOperations.Email, "The expected rights-managed e-mail message should not be null.");
            Site.Assert.IsNull(itemOperations.Email.Attachments, "The Attachments element in expected rights-managed e-mail message should be null.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASRM_R91");

            // Verify MS-ASRM requirement: MS-ASRM_R91
            // If the response contains RightsManagementLicense element as null, represents the rights management protection is removed from the e-mail.
            Site.CaptureRequirementIfIsNull(
                itemOperations.Email.RightsManagementLicense,
                91,
                @"[In RemoveRightsManagementProtection] If present, it[RemoveRightsManagementProtection] indicates that the client is removing the IRM protection from the e-mail.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASRM_R94");

            // Verify MS-ASRM requirement: MS-ASRM_R94
            // If the response contains RightsManagementLicense element as null, represents the rights management protection is removed from the e-mail.
            Site.CaptureRequirementIfIsNull(
                itemOperations.Email.RightsManagementLicense,
                94,
                @"[In RemoveRightsManagementProtection] IRM protection can only be removed from e-mail messages when the ExportAllowed element is set to TRUE.");
            #endregion
        }
        public void MSASCMD_S08_TC18_ItemOperations_MoreThanOneFileReference_Status2()
        {
            #region Send a mail with normal attachment
            string subject = Common.GenerateResourceName(Site, "NormalAttachment_Subject");
            string body = Common.GenerateResourceName(Site, "NormalAttachment_Body");
            this.SendEmailWithAttachment(subject, body);
            #endregion

            #region Call method Sync to synchronize changes of Inbox folder in User2's mailbox between the client and the server.
            this.SwitchUser(this.User2Information);
            SyncResponse syncResponse = this.GetMailItem(this.User2Information.InboxCollectionId, subject);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            string serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", subject);
            Response.Attachments attachments = null;
            Response.SyncCollectionsCollection collection = ((Response.SyncCollections)syncResponse.ResponseData.Item).Collection[0];
            for (int i = 0; i < collection.ItemsElementName.Length; i++)
            {
                if (collection.ItemsElementName[i] == Response.ItemsChoiceType10.Commands)
                {
                    Response.SyncCollectionsCollectionCommands commands = ((Response.SyncCollections)syncResponse.ResponseData.Item).Collection[0].Items[i] as Response.SyncCollectionsCollectionCommands;
                    foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
                    {
                        if (add.ServerId.Equals(serverId))
                        {
                            for (int j = 0; j < add.ApplicationData.ItemsElementName.Length; j++)
                            {
                                if (add.ApplicationData.ItemsElementName[j] == Response.ItemsChoiceType8.Attachments)
                                {
                                    attachments = (Response.Attachments)add.ApplicationData.Items[j];
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    break;
                }
            }

            Site.Assert.IsNotNull(attachments, "The attachments element in expected email item should not be null.");
            #endregion

            #region Call method SendStringRequest to call ItemOperations method to get data of an attachment with two FileReference elements
            // Initialize a Fetch element.
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                FileReference = ((Response.AttachmentsAttachment)attachments.Items[0]).FileReference,
                Store = SearchName.Mailbox.ToString(),
                CollectionId = ((Response.AttachmentsAttachment)attachments.Items[0]).FileReference
            };

            // Create an ItemOperations command request and construct two FileReference elements
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });
            string request = itemOperationsRequest.GetRequestDataSerializedXML();
            request = request.Replace(@"CollectionId xmlns=""AirSync""", @"FileReference xmlns=""AirSyncBase""");
            request = request.Replace(@"/CollectionId", @"/FileReference");
            SendStringResponse sendStringResponse = this.CMDAdapter.SendStringRequest(CommandName.ItemOperations, null, request);

            string status = string.Empty;
            string xmlResponse = sendStringResponse.ResponseDataXML;
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlResponse);
            XmlNamespaceManager xmlNameSpaceManager = new XmlNamespaceManager(doc.NameTable);
            xmlNameSpaceManager.AddNamespace("e", "ItemOperations");
            XmlNode statusNode = doc.SelectSingleNode("/e:ItemOperations/e:Status", xmlNameSpaceManager);

            if (statusNode != null)
            {
                status = statusNode.InnerText;
            }

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R765");

            // Verify MS-ASCMD requirement: MS-ASCMD_R765
            Site.CaptureRequirementIfAreEqual<string>(
                "2",
                status,
                765,
                @"[In airsyncbase:FileReference] Violation of this constraint [in an ItemOperations request, only one airsyncbase:FileReference identifier can exist per Fetch node] results in a Status element (section 2.2.3.162.7) value of 2 being returned from the server.");
            #endregion
        }
        public void MSASCMD_S08_TC17_ItemOperations_Status15()
        {
            #region Call method ItemOperations to get data of an attachment with invalid attachment ID.
            // Initialize a Fetch element.
            Request.ItemOperationsFetch itemOperationsFetch = new Request.ItemOperationsFetch
            {
                FileReference = "InvalidAttachmentID",
                Store = SearchName.Mailbox.ToString()
            };

            // Create an ItemOperations command request.
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { itemOperationsFetch });

            // Send request and get response.
            ItemOperationsResponse itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.Inline);
            Response.ItemOperationsResponseFetch fetch = this.GetFetchElement(itemOperationsResponse);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4166");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4166
            Site.CaptureRequirementIfAreEqual<string>(
                "15",
                fetch.Status,
                4166,
                @"[In Status(ItemOperations)] [The meaning of the status value] 15 [is] Attachment fetch provider - Attachment or attachment ID is invalid.");
            #endregion
        }
        /// <summary>
        /// Builds a Fetch element for the ItemOperations request.
        /// </summary>
        /// <param name="linkId">A URL of the item to be fetched.</param>
        /// <returns>A Fetch element of the ItemOperations request.</returns>
        private ItemOperationsFetch FetchElementBuilder(string linkId)
        {
            // Initialize a fetch element.
            ItemOperationsFetch fetch = new ItemOperationsFetch
            {
                LinkId = linkId,
                Store = SearchName.DocumentLibrary.ToString(),
                Options = new ItemOperationsFetchOptions { ItemsElementName = new ItemsChoiceType5[2] }
            };

            // The user account is used to search the document from the document library
            fetch.Options.ItemsElementName[0] = ItemsChoiceType5.UserName;
            fetch.Options.ItemsElementName[1] = ItemsChoiceType5.Password;
            fetch.Options.Items = new string[2];
            fetch.Options.Items[0] = Common.GetConfigurationPropertyValue("UserName", this.Site);
            fetch.Options.Items[1] = Common.GetConfigurationPropertyValue("UserPassword", this.Site);

            return fetch;
        }
        public void MSASDOC_S02_TC02_ItemOperations_GetZeroOrMoreDocumentClass()
        {
            #region Client calls ItemOperations command to get data of a nonexistent document under a shared folder.

            // Build element Fetch.
            ItemOperationsFetch fetchZeroDoc = this.FetchElementBuilder(Common.GetConfigurationPropertyValue("SharedVisibleDocument", Site) + Guid.NewGuid().ToString());

            // Create an ItemOperation command request that zero document class value will be returned.
            ItemOperationsRequest itemOperationsGetZeroDocRequest = Common.CreateItemOperationsRequest(new object[] { fetchZeroDoc });

            // Send request and get response.
            ItemOperationsResponse itemOperationGetZeroDocResponse = this.ASDOCAdapter.ItemOperations(itemOperationsGetZeroDocRequest, DeliveryMethodForFetch.Inline);

            // Make sure this file doesn't exist.
            Site.Assert.AreEqual<int>(1, itemOperationGetZeroDocResponse.ResponseData.Response.Fetch.Length, "Only one fetch element should be returned.");
            Site.Assert.AreEqual<string>("6", itemOperationGetZeroDocResponse.ResponseData.Response.Fetch[0].Status, "Document information should not be returned.");

            #endregion

            #region Client calls ItemOperations command to get data of a shared visible document and a shared hidden document.

            // Build element Fetch.
            ItemOperationsFetch fetch1 = this.FetchElementBuilder(Common.GetConfigurationPropertyValue("SharedHiddenDocument", Site));
            ItemOperationsFetch fetch2 = this.FetchElementBuilder(Common.GetConfigurationPropertyValue("SharedVisibleDocument", Site));

            ItemOperationsFetch[] fetches = new ItemOperationsFetch[] { fetch1, fetch2 };

            // Create an ItemOperation command request that multiple document class value will be returned.
            ItemOperationsRequest itemOperationGetMoreDocRequest = Common.CreateItemOperationsRequest(fetches);

            // Send request and get response.
            ItemOperationsResponse itemOperationGetMoreDocResponse = this.ASDOCAdapter.ItemOperations(itemOperationGetMoreDocRequest, DeliveryMethodForFetch.Inline);

            // Information of the two documents is returned.
            Site.Assert.AreEqual<int>(2, itemOperationGetMoreDocResponse.ResponseData.Response.Fetch.Length, "Two document class items should be returned.");
            Site.Assert.AreEqual<string>("1", itemOperationGetMoreDocResponse.ResponseData.Response.Fetch[0].Status, "Document information should be returned.");
            Site.Assert.AreEqual<string>("1", itemOperationGetMoreDocResponse.ResponseData.Response.Fetch[1].Status, "Document information should be returned");

            #endregion

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R102");

            // Items that match the criteria are returned.
            Site.CaptureRequirement(
                102,
                @"[In ItemOperations Command Response] The server MUST return a Document class XML block for every item that matches the criteria specified in the client command request.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASDOC_R103");

            // Server can return zero or more documents class blocks which can be seen from two steps above.
            Site.CaptureRequirement(
                103,
                @"[In ItemOperations Command Response] The server can return zero or more Document class blocks in its response, depending on how many document items match the criteria specified in the client command request.");
        }
        /// <summary>
        /// Builds a ItemOperations request to fetch the whole content of a single mail item
        /// by using the specified collectionId, emailServerId,bodyPreference and bodyPartPreference
        /// In general, returns the XML formatted ItemOperations request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <ItemOperations xmlns="ItemOperations" xmlns:airsync="AirSync" xmlns:airsyncbase="AirSyncBase">
        ///    <Fetch>
        ///       <Store>Mailbox</Store>
        ///       <airsync:CollectionId>5</airsync:CollectionId>
        ///       <airsync:ServerId>5:1</airsync:ServerId>
        ///       <Options>
        ///          <airsync:MIMESupport>2</airsync:MIMESupport>
        ///          <airsyncbase:BodyPreference>
        ///             <airsyncbase:Type>4</airsyncbase:Type>
        ///          </airsyncbase:BodyPreference>
        ///          <airsyncbase:BodyPreference>
        ///             <airsyncbase:Type>2</airsyncbase:Type>
        ///          </airsyncbase:BodyPreference>
        ///       </Options>
        ///    </Fetch>
        /// </ItemOperations>
        /// -->
        /// </summary>
        /// <param name="collectionId">Specify the folder of mailItem, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.2)</param>
        /// <param name="serverIds">Specify a unique identifier that was assigned by the server for a mailItem, which can be returned by ActiveSync Sync command(Refer to [MS-ASCMD]2.2.3.151.5)</param>
        /// <param name="schema">Sets the schema information</param>
        /// <returns>Returns the ItemOperationsRequest instance</returns>
        internal static ItemOperationsRequest CreateItemOperationsFetchRequest(string collectionId, List<string> serverIds, Request.Schema schema)
        {
            Request.ItemOperations itemOperations = new Request.ItemOperations();
            List<object> items = new List<object>();

            Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch();

            if (serverIds != null)
            {
                foreach (string item in serverIds)
                {
                    fetchElement.CollectionId = collectionId;
                    fetchElement.ServerId = item;
                    items.Add(fetchElement);
                }
            }

            itemOperations.Items = items.ToArray();

            foreach (object item in itemOperations.Items)
            {
                Request.ItemOperationsFetch fetch = item as Request.ItemOperationsFetch;
                if (fetch != null)
                {
                    fetch.Store = SearchName.Mailbox.ToString();
                    Request.ItemOperationsFetchOptions fetchOptions = new Request.ItemOperationsFetchOptions();

                    List<object> fetchOptionItems = new List<object>();
                    List<Request.ItemsChoiceType5> fetchOptionItemsName = new List<Request.ItemsChoiceType5>
                    {
                        Request.ItemsChoiceType5.BodyPreference,
                        Request.ItemsChoiceType5.Schema
                    };

                    fetchOptionItems.Add(
                        new Request.BodyPreference()
                        {
                            AllOrNone = false,
                            AllOrNoneSpecified = false,
                            TruncationSize = 0,
                            TruncationSizeSpecified = false,
                            Preview = 0,
                            PreviewSpecified = false,
                            Type = 2,
                        });
                    fetchOptionItems.Add(schema);

                    fetchOptions.Items = fetchOptionItems.ToArray();
                    fetchOptions.ItemsElementName = fetchOptionItemsName.ToArray();
                    fetch.Options = fetchOptions;
                }
            }

            return Common.CreateItemOperationsRequest(itemOperations.Items);
        }
        public void MSASCMD_S08_TC12_ItemOperations_Status4()
        {
            #region Call method ItemOperations to get data of an invalid shared document with inline fetch.
            // Initialize a Fetch element.
            Request.ItemOperationsFetch itemOperationsFetch = new Request.ItemOperationsFetch
            {
                LinkId = "//invalidURI",
                Store = SearchName.DocumentLibrary.ToString(),
                Options = new Request.ItemOperationsFetchOptions
                {
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.UserName, Request.ItemsChoiceType5.Password },
                    Items = new string[] { this.User1Information.UserName, this.User1Information.UserPassword }
                }
            };

            // Create an ItemOperations command request.
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { itemOperationsFetch });

            // Send request and get response.
            ItemOperationsResponse itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.Inline);

            Response.ItemOperationsResponseFetch fetch = this.GetFetchElement(itemOperationsResponse);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4156");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4156
            Site.CaptureRequirementIfAreEqual<string>(
                "4",
                fetch.Status,
                4156,
                @"[In Status(ItemOperations)] [The meaning of the status value] 4 [is] Document library access - The specified URI is bad.");
            #endregion
        }
        /// <summary>
        /// Builds a ItemOperations request to fetch the whole content of the notes
        /// </summary>
        /// <param name="collectionId">Specifies the notes folder</param>
        /// <param name="serverIds">Specifies a unique identifier that is assigned by the server for the notes</param>
        /// <param name="longIds">Specifies a unique identifier that is assigned by the server to each result returned by a previous Search response.</param>
        /// <param name="bodyPreference">Sets preference information related to the type and size of the body.</param>
        /// <param name="schema">Specifies the schema of the item to be fetched.</param>
        /// <returns>Returns the ItemOperationsRequest instance</returns>
        internal static ItemOperationsRequest CreateItemOperationsFetchRequest(
            string collectionId,
            List<string> serverIds,
            List<string> longIds,
            Request.BodyPreference bodyPreference,
            Request.Schema schema)
        {
            Request.ItemOperationsFetchOptions fetchOptions = new Request.ItemOperationsFetchOptions();
            List<object> fetchOptionItems = new List<object>();
            List<Request.ItemsChoiceType5> fetchOptionItemsName = new List<Request.ItemsChoiceType5>();

            if (null != bodyPreference)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.BodyPreference);
                fetchOptionItems.Add(bodyPreference);
            }

            if (null != schema)
            {
                fetchOptionItemsName.Add(Request.ItemsChoiceType5.Schema);
                fetchOptionItems.Add(schema);
            }

            fetchOptions.Items = fetchOptionItems.ToArray();
            fetchOptions.ItemsElementName = fetchOptionItemsName.ToArray();

            List<Request.ItemOperationsFetch> fetchElements = new List<Request.ItemOperationsFetch>();

            if (serverIds != null)
            {
                foreach (string serverId in serverIds)
                {
                    Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch()
                    {
                        CollectionId = collectionId,
                        ServerId = serverId,
                        Store = SearchName.Mailbox.ToString(),
                        Options = fetchOptions
                    };
                    fetchElements.Add(fetchElement);
                }
            }

            if (longIds != null)
            {
                foreach (string longId in longIds)
                {
                    Request.ItemOperationsFetch fetchElement = new Request.ItemOperationsFetch()
                    {
                        LongId = longId,
                        Store = SearchName.Mailbox.ToString(),
                        Options = fetchOptions
                    };
                    fetchElements.Add(fetchElement);
                }
            }

            return Common.CreateItemOperationsRequest(fetchElements.ToArray());
        }
        public void MSASCMD_S08_TC13_ItemOperations_Status5()
        {
            #region Call method ItemOperations to get data of a shared document by a user with an invalid password.
            // Initialize a Fetch element.
            Request.ItemOperationsFetch itemOperationsFetch = new Request.ItemOperationsFetch
            {
                LinkId = Common.GetConfigurationPropertyValue("SharedDocument1", this.Site),
                Store = SearchName.DocumentLibrary.ToString(),
                Options = new Request.ItemOperationsFetchOptions
                {
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.UserName, Request.ItemsChoiceType5.Password },
                    Items = new string[] { this.User1Information.UserName, "invalidPassword" }
                }
            };

            // Create an ItemOperations command request.
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { itemOperationsFetch });

            // Send request and get response.
            ItemOperationsResponse itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.Inline);
            Response.ItemOperationsResponseFetch fetch = this.GetFetchElement(itemOperationsResponse);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4157");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4157
            Site.CaptureRequirementIfAreEqual<string>(
                "5",
                fetch.Status,
                4157,
                @"[In Status(ItemOperations)] [The meaning of the status value] 5 [is] Document library - Access denied.");
            #endregion
        }
        public void MSASCMD_S08_TC14_ItemOperations_Status8()
        {
            #region Call method ItemOperations to get data of a shared document with the byte range exceeded the actual length of document contents.
            // Initialize a Fetch element.
            Request.ItemOperationsFetch itemOperationsFetch = new Request.ItemOperationsFetch
            {
                LinkId = Common.GetConfigurationPropertyValue("SharedDocument1", this.Site),
                Store = SearchName.DocumentLibrary.ToString(),
                Options = new Request.ItemOperationsFetchOptions
                {
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.UserName, Request.ItemsChoiceType5.Password, Request.ItemsChoiceType5.Range },
                    Items = new string[] { this.User1Information.UserName, this.User1Information.UserPassword, "99-99" }
                }
            };

            // Create an ItemOperations command request.
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { itemOperationsFetch });

            // Send request and get response.
            ItemOperationsResponse itemOperationsResponse = this.CMDAdapter.ItemOperations(itemOperationsRequest, DeliveryMethodForFetch.Inline);
            Response.ItemOperationsResponseFetch fetch = this.GetFetchElement(itemOperationsResponse);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4160");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4160
            Site.CaptureRequirementIfAreEqual<string>(
                "8",
                fetch.Status,
                4160,
                @"[In Status(ItemOperations)] [The meaning of the status value] 8 [is] The byte-range is invalid or too large.");
            #endregion
        }
        public void MSASRM_S02_TC01_ItemOperations_RightsManagedEmailMessages()
        {
            this.CheckPreconditions();

            #region The client logs on User1's account, calls Settings command to get a templateID with all rights allowed.
            string templateID = this.GetTemplateID("MSASRM_AllRights_AllowedTemplate");
            #endregion

            #region The client logs on User1's account, calls SendMail command with the templateID to send a rights-managed e-mail message to User2, switches to User2, and calls FolderSync command.
            string subject = this.SendMailAndFolderSync(templateID, false, null);
            #endregion

            #region The client logs on User2's account, calls Sync command with RightsManagementSupport element set to true to synchronize changes of Inbox folder in User2's mailbox, and gets the decompressed and decrypted rights-managed e-mail message.
            Sync item = this.SyncEmail(subject, this.UserTwoInformation.InboxCollectionId, true, true);
            Site.Assert.IsNotNull(item, "The returned item should not be null.");
            Site.Assert.IsNull(item.Email.Attachments, "The Attachments element in expected rights-managed e-mail message should be null.");
            Site.Assert.IsNotNull(item.Email.RightsManagementLicense, "The RightsManagementLicense element in expected rights-managed e-mail message should not be null.");
            Site.Assert.IsTrue(item.Email.RightsManagementLicense.ExportAllowed, "The ExportAllowed element in expected rights-managed e-mail message should be true.");
            #endregion

            #region The client logs on User2's account, calls ItemOperations command which contains the Fetch element without RemoveRightsManagementProtection element.
            Request.ItemOperationsFetch fetch = new Request.ItemOperationsFetch
            {
                CollectionId = this.UserTwoInformation.InboxCollectionId,
                Store = SearchName.Mailbox.ToString(),
                ServerId = item.ServerId,
                Options = new Request.ItemOperationsFetchOptions
                {
                    Items = new object[] { true },
                    ItemsElementName = new Request.ItemsChoiceType5[] { Request.ItemsChoiceType5.RightsManagementSupport }
                }
            };
            ItemOperationsRequest itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });
            ItemOperationsStore itemOperationsStore = this.ASRMAdapter.ItemOperations(itemOperationsRequest);
            Site.Assert.AreEqual<int>(1, itemOperationsStore.Items.Count, "There should be only 1 item fetched in ItemOperations command response.");
            ItemOperations itemOperations = itemOperationsStore.Items[0];
            Site.Assert.IsNotNull(itemOperations, "The returned item should not be null.");
            Site.Assert.IsNotNull(itemOperations.Email, "The expected rights-managed e-mail message should not be null.");
            Site.Assert.IsNull(itemOperations.Email.Attachments, "The Attachments element in expected rights-managed e-mail message should be null.");
            Site.Assert.IsNotNull(itemOperations.Email.RightsManagementLicense, "The RightsManagementLicense element in expected rights-managed e-mail message should not be null.");
            #endregion

            #region The client logs on User2's account, calls ItemOperations command which contains the Fetch element with RemoveRightsManagementProtection element.
            fetch.RemoveRightsManagementProtection = string.Empty;
            itemOperationsRequest = Common.CreateItemOperationsRequest(new object[] { fetch });
            itemOperationsStore = this.ASRMAdapter.ItemOperations(itemOperationsRequest);
            Site.Assert.AreEqual<int>(1, itemOperationsStore.Items.Count, "There should be only 1 item fetched in ItemOperations command response.");
            itemOperations = itemOperationsStore.Items[0];
            Site.Assert.IsNotNull(itemOperations, "The returned item should not be null.");
            Site.Assert.IsNotNull(itemOperations.Email, "The expected rights-managed e-mail message should not be null.");
            Site.Assert.IsNull(itemOperations.Email.Attachments, "The Attachments element in expected rights-managed e-mail message should be null.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASRM_R91");

            // Verify MS-ASRM requirement: MS-ASRM_R91
            // If the response contains RightsManagementLicense element as null, represents the rights management protection is removed from the e-mail.
            Site.CaptureRequirementIfIsNull(
                itemOperations.Email.RightsManagementLicense,
                91,
                @"[In RemoveRightsManagementProtection] If present, it[RemoveRightsManagementProtection] indicates that the client is removing the IRM protection from the e-mail.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASRM_R94");

            // Verify MS-ASRM requirement: MS-ASRM_R94
            // If the response contains RightsManagementLicense element as null, represents the rights management protection is removed from the e-mail.
            Site.CaptureRequirementIfIsNull(
                itemOperations.Email.RightsManagementLicense,
                94,
                @"[In RemoveRightsManagementProtection] IRM protection can only be removed from e-mail messages when the ExportAllowed element is set to TRUE.");
            #endregion
        }