Example #1
0
        /// <summary>
        /// Exports items from a specified folder.
        /// </summary>
        /// <param name="exportItemsRequest">Specify the request for ExportItems operation.</param>
        /// <returns>The response to this operation request.</returns>
        public ExportItemsResponseType ExportItems(ExportItemsType exportItemsRequest)
        {
            if (exportItemsRequest == null)
            {
                throw new ArgumentException("The exportItems should not be null.");
            }

            // Send the request and get the response.
            ExportItemsResponseType response = this.exchangeServiceBinding.ExportItems(exportItemsRequest);

            this.VerifyTransportType();
            this.VerifySoapVersion();
            this.VerifyExportItemsResponseType(response, this.exchangeServiceBinding.IsSchemaValidated);

            return(response);
        }
        public void MSOXWSBTRF_S01_TC04_ExportItems_Fail()
        {
            #region Get the exported items.
            // In the initialize step, multiple items in the specified parent folder have been created.
            // If that step executes successfully, the count of CreatedItemId list should be equal to the count of OriginalFolderId list.
            Site.Assert.AreEqual <int>(
                this.CreatedItemId.Count,
                this.OriginalFolderId.Count,
                string.Format(
                    "The exportedItemIds array should contain {0} item ids, actually, it contains {1}.",
                    this.OriginalFolderId.Count,
                    this.CreatedItemId.Count));
            #endregion

            #region Call ExportItems operation to export the items from the server.
            // Initialize three ExportItemsType instances.
            ExportItemsType exportItems = new ExportItemsType();

            // Initialize ItemIdType instances with three different situations:
            // 1.The ID attribute of ItemId is empty;
            // 2.The ID attribute of ItemId is valid and the ChangeKey is invalid;
            // 3.The ID attribute of ItemId is invalid and the ChangeKey is null.
            exportItems.ItemIds = new ItemIdType[3]
            {
                new ItemIdType
                {
                    Id        = string.Empty,
                    ChangeKey = null
                },
                new ItemIdType
                {
                    Id        = this.CreatedItemId[1].Id,
                    ChangeKey = InvalidChangeKey
                },
                new ItemIdType
                {
                    Id        = InvalidItemId,
                    ChangeKey = null
                }
            };

            // Call ExportItems operation.
            ExportItemsResponseType exportItemsResponse = this.BTRFAdapter.ExportItems(exportItems);

            // Check whether the ExportItems operation is executed successfully.
            foreach (ExportItemsResponseMessageType responseMessage in exportItemsResponse.ResponseMessages.Items)
            {
                Site.Assert.AreEqual <ResponseClassType>(
                    ResponseClassType.Error,
                    responseMessage.ResponseClass,
                    string.Format(
                        @"The ExportItems operation should be unsuccessful. Expected response code: {0}, actual response code: {1}",
                        ResponseClassType.Error,
                        responseMessage.ResponseClass));
            }
            #endregion

            #region Verify ExportItems fail related requirements.
            this.VerifyExportItemsErrorResponse(exportItemsResponse);
            #endregion
        }
        public void MSOXWSBTRF_S01_TC01_ExportAndUploadItems_CreateNew_Success()
        {
            #region Prerequisites.
            // In the initialize step, multiple items in the specified parent folder have been created.
            // If that step executes successfully, the count of CreatedItemId list should be equal to the count of OriginalFolderId list.
            Site.Assert.AreEqual <int>(
                this.CreatedItemId.Count,
                this.OriginalFolderId.Count,
                string.Format(
                    "The exportedItemIds array should contain {0} item ids, actually, it contains {1}",
                    this.OriginalFolderId.Count,
                    this.CreatedItemId.Count));
            #endregion

            #region Call ExportItems operation to export the items from the server.
            // Initialize three ExportItemsType instances.
            ExportItemsType exportItems = new ExportItemsType();

            // Initialize four ItemIdType instances with three different situations to cover the case:
            // 1. The ChangeKey is not present;
            // 2. If the ChangeKey attribute of the ItemIdType complex type is present, its value MUST be either valid or NULL.
            exportItems.ItemIds = new ItemIdType[4]
            {
                new ItemIdType
                {
                    // The ChangeKey is not present.
                    Id = this.CreatedItemId[0].Id,
                },
                new ItemIdType
                {
                    // The ChangeKey is null.
                    Id        = this.CreatedItemId[1].Id,
                    ChangeKey = null
                },
                new ItemIdType
                {
                    // The ChangeKey is valid.
                    Id        = this.CreatedItemId[2].Id,
                    ChangeKey = this.CreatedItemId[2].ChangeKey
                },
                new ItemIdType
                {
                    // The ChangeKey is not present.
                    Id = this.CreatedItemId[3].Id,
                }
            };

            // Call ExportItems operation.
            ExportItemsResponseType exportItemsResponse = this.BTRFAdapter.ExportItems(exportItems);
            Site.Assert.IsNotNull(exportItemsResponse, "The ExportItems response should not be null.");

            // Check whether the ExportItems operation is executed successfully.
            foreach (ExportItemsResponseMessageType responseMessage in exportItemsResponse.ResponseMessages.Items)
            {
                Site.Assert.AreEqual <ResponseClassType>(
                    ResponseClassType.Success,
                    responseMessage.ResponseClass,
                    string.Format(
                        @"The ExportItems operation should be successful. Expected response code: {0}, actual response code: {1}",
                        ResponseClassType.Success,
                        responseMessage.ResponseClass));
            }

            // If the operation executes successfully, the count of items in ExportItems response should be equal to the items in ExportItems request.
            Site.Assert.AreEqual <int>(
                exportItemsResponse.ResponseMessages.Items.Length,
                exportItems.ItemIds.Length,
                string.Format(
                    "The exportItems response should contain {0} items, actually, it contains {1}",
                    exportItems.ItemIds.Length,
                    exportItemsResponse.ResponseMessages.Items.Length));

            // Verify ManagementRole part of ExportItems operation
            this.VerifyManagementRolePart();
            #endregion

            #region Verify the ExportItems response related requirements
            // Verify the ExportItemsResponseType related requirements.
            this.VerifyExportItemsSuccessResponse(exportItemsResponse);

            // If the id in ExportItems request is same with the id in ExportItems response, then MS-OXWSBTRF_R169 and MS-OXWSBTRF_R182 can be captured.
            bool isSameItemId = false;
            for (int i = 0; i < exportItemsResponse.ResponseMessages.Items.Length; i++)
            {
                Site.Log.Add(
                    LogEntryKind.Debug,
                    "The exported item's id: '{0}' should be same with the created item's id: {1}.",
                    (exportItemsResponse.ResponseMessages.Items[i] as ExportItemsResponseMessageType).ItemId.Id,
                    this.CreatedItemId[i].Id);
                if ((exportItemsResponse.ResponseMessages.Items[i] as ExportItemsResponseMessageType).ItemId.Id == this.CreatedItemId[i].Id)
                {
                    isSameItemId = true;
                }
                else
                {
                    isSameItemId = false;
                    break;
                }
            }

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

            // Verify requirement MS-OXWSBTRF_R169
            Site.CaptureRequirementIfIsTrue(
                isSameItemId,
                169,
                @"[In m:ExportItemsResponseMessageType Complex Type][ItemId] specifies the item identifier of a single exported item.");

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

            // Verify requirement MS-OXWSBTRF_R182
            Site.CaptureRequirementIfIsTrue(
                isSameItemId,
                182,
                @"[In t:NonEmptyArrayOfItemIdsType Complex Type][ItemId] specifies the item identifier of an item to export from a mailbox.");
            #endregion

            #region Call UploadItems operation and set the CreateAction element to CreateNew to upload the items that exported in last step.
            ExportItemsResponseMessageType[] exportItemsResponseMessages = TestSuiteHelper.GetResponseMessages <ExportItemsResponseMessageType>(exportItemsResponse);

            // Initialize the upload items using the data of previous export items and set the item CreateAction to CreateNew.
            UploadItemsResponseMessageType[] uploadItemsResponse = this.UploadItems(exportItemsResponseMessages, this.OriginalFolderId, CreateActionType.CreateNew, true, true, false);
            #endregion

            #region Verify the UploadItems response related requirements when the CreateAction is CreateNew.
            // If the UploadItems response item's ID is not the same as the previous exported item's ID, then MS-OXWSBTRF_R228 can be captured.
            bool isNotSameItemId = false;
            for (int i = 0; i < uploadItemsResponse.Length; i++)
            {
                // Log the expected and actual value
                Site.Log.Add(
                    LogEntryKind.Debug,
                    "The uploaded item's id: '{0}' should not be same with the exported item's id when the CreateAction is set to CreateNew: {1}.",
                    uploadItemsResponse[i].ItemId.Id,
                    exportItemsResponseMessages[i].ItemId.Id);
                if (exportItemsResponseMessages[i].ItemId.Id != uploadItemsResponse[i].ItemId.Id)
                {
                    isNotSameItemId = true;
                }
                else
                {
                    isNotSameItemId = false;
                    break;
                }
            }

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

            // Verify Requirement: MS-OXWSBTRF_R228.
            Site.CaptureRequirementIfIsTrue(
                isNotSameItemId,
                228,
                @"[In CreateActionType Simple Type][CreateNew]
                    The <ItemId> element that is returned in the UploadItemsResponseMessageType complex type, as specified in section 3.1.4.2.3.2, 
                    MUST contain the new item identifier.");

            // Call getItem to get the items that was uploaded
            ItemIdType[] itemIds = new ItemIdType[uploadItemsResponse.Length];
            for (int i = 0; i < uploadItemsResponse.Length; i++)
            {
                itemIds[i] = uploadItemsResponse[i].ItemId;
            }

            ItemType[] getItems = this.GetItems(itemIds);

            // Verify the array of items uploaded to a mailbox
            this.VerifyItemsUploadedToMailbox(getItems);

            // If the verification of the items uploaded to mailbox is successful, then this requirement can be captured.
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R226");

            // Verify requirement MS-OXWSBTRF_R226
            Site.CaptureRequirement(
                226,
                @"[In CreateActionType Simple Type]The Value of CreateNew specifies that a new copy of the original item is uploaded to the mailbox.");

            // If the value of IsAssociated attribute in getItem response is same with the value in uploadItems request,
            // then requirement MS-OXWSBTRF_R222 can be captured.
            bool isSameIsAssociated = false;
            for (int i = 0; i < getItems.Length; i++)
            {
                // Log the expected and actual value
                Site.Log.Add(
                    LogEntryKind.Debug,
                    "The value of IsAssociated attribute: {0} in getItem response should be: true",
                    getItems[i].IsAssociated);
                if (true == getItems[i].IsAssociated)
                {
                    isSameIsAssociated = true;
                }
                else
                {
                    isSameIsAssociated = false;
                    break;
                }
            }

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

            // Verify requirement MS-OXWSBTRF_R222
            Site.CaptureRequirementIfIsTrue(
                isSameIsAssociated,
                222,
                @"[In m:UploadItemType Complex Type]If it [IsAssociated] is present, it indicates that the item is a folder associated item.");
            #endregion
        }
        private void MigrateItens(ref DataGridViewRow row, ExchangeServiceBinding srcService, ExchangeServiceBinding tgtService, DistinguishedFolderIdNameType folder, string srcUserMail, string tgtUserMail)
        {
            ResponseMessageType[] itemsResponse = this.GetFolderItems(srcService, folder);

            ExportItemsType exExportItems = new ExportItemsType();

            foreach (ResponseMessageType responseMessage in itemsResponse)
            {
                FindItemResponseMessageType firmt = responseMessage as FindItemResponseMessageType;
                FindItemParentType          fipt  = firmt.RootFolder;
                object obj   = fipt.Item;
                int    count = 0;

                // FindItem contains an array of items.
                if (obj is ArrayOfRealItemsType)
                {
                    ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);

                    exExportItems.ItemIds = new ItemIdType[(items.Items.Count() + 1)];

                    foreach (ItemType it in items.Items)
                    {
                        exExportItems.ItemIds[count]    = new ItemIdType();
                        exExportItems.ItemIds[count].Id = it.ItemId.Id;
                        count++;
                    }
                }
            }

            ExportItemsResponseType exResponse = srcService.ExportItems(exExportItems);

            ResponseMessageType[] rmResponses   = exResponse.ResponseMessages.Items;
            UploadItemsType       upUploadItems = new UploadItemsType();

            upUploadItems.Items = new UploadItemType[(rmResponses.Length + 1)];
            Int32 icItemCount = 0;

            foreach (ResponseMessageType rmReponse in rmResponses)
            {
                if (rmReponse.ResponseClass == ResponseClassType.Success)
                {
                    ExportItemsResponseMessageType exExportedItem = (ExportItemsResponseMessageType)rmReponse;
                    Byte[]         messageBytes = exExportedItem.Data;
                    UploadItemType upUploadItem = new UploadItemType();
                    upUploadItem.CreateAction          = CreateActionType.UpdateOrCreate;
                    upUploadItem.Data                  = messageBytes;
                    upUploadItem.IsAssociatedSpecified = true;
                    upUploadItem.IsAssociated          = false;
                    upUploadItems.Items[icItemCount]   = upUploadItem;

                    FolderIdManager folderIdMgr = new FolderIdManager();
                    FolderIdType    folderId    = new FolderIdType();
                    folderId.Id = folderIdMgr.GetFolderId(tgtUserMail, Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Contacts, Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP2);


                    upUploadItem.ParentFolderId = folderId;
                    icItemCount += 1;
                }
            }
            //Erro de Internal Server Error nessa etapa
            UploadItemsResponseType upLoadResponse = tgtService.UploadItems(upUploadItems);
            Int32 Success = 0;
            Int32 Failure = 0;

            foreach (ResponseMessageType upResponse in upLoadResponse.ResponseMessages.Items)
            {
                if (upResponse.ResponseClass == ResponseClassType.Success)
                {
                    Success++;
                }
                if (upResponse.ResponseClass == ResponseClassType.Error)
                {
                    Failure++;
                }
            }


            string resTask = string.Format("Items Copied Sucessfull : {0} - Failure: {1}", Success, Failure);

            Tools.SetRowValue(ref row, EColumns.results, resTask);

            //iv.Offset += fiItems.Items.Count;
        }
        /// <summary>
        /// Get the ExportItemsResponseMessageType response of ExportItems operation.
        /// </summary>
        /// <param name="configureSOAPHeader">A Boolean value specifies whether configuring the SOAP header before calling operations.</param>
        /// <returns>The array of ExportItemsResponseMessageType response.</returns>
        protected ExportItemsResponseMessageType[] ExportItems(bool configureSOAPHeader)
        {
            #region Prerequisite.
            // In the initialize step, three items in the specified sub folder have been created.
            // If that step executes successfully, the length of CreatedItemId list should be equal to the length of OriginalFolderId list.
            Site.Assert.AreEqual <int>(
                this.CreatedItemId.Count,
                this.OriginalFolderId.Count,
                string.Format(
                    "The exportedItemIds array should contain {0} item ids, actually, it contains {1}",
                    this.OriginalFolderId.Count,
                    this.CreatedItemId.Count));
            #endregion

            #region Call ExportItems operation to export the items from the server.
            // Initialize the export items' instances.
            ExportItemsType exportItems = new ExportItemsType();

            // Initialize three ItemIdType instances.
            exportItems.ItemIds = new ItemIdType[this.ItemCount];
            for (int i = 0; i < exportItems.ItemIds.Length; i++)
            {
                exportItems.ItemIds[i]    = new ItemIdType();
                exportItems.ItemIds[i].Id = this.CreatedItemId[i].Id;
            }

            // Initialize a ExportItemsResponseType instance.
            ExportItemsResponseType exportItemsResponse = this.BTRFAdapter.ExportItems(exportItems);

            // Check whether the operation is executed successfully.
            foreach (ExportItemsResponseMessageType exportResponse in exportItemsResponse.ResponseMessages.Items)
            {
                Site.Assert.AreEqual <ResponseClassType>(
                    ResponseClassType.Success,
                    exportResponse.ResponseClass,
                    string.Format(
                        "Export items should be successful! Expected response code: {0}, actual response code: {1}",
                        ResponseCodeType.NoError,
                        exportResponse.ResponseCode));
            }

            // If the operation executes successfully, the items in exportItems response should be equal to the value of ItemCount
            Site.Assert.AreEqual <int>(
                exportItemsResponse.ResponseMessages.Items.Length,
                this.ItemCount,
                string.Format(
                    "The exportItems response should contain {0} items, actually, it contains {1}",
                    this.ItemCount,
                    exportItemsResponse.ResponseMessages.Items.Length));
            #endregion

            #region Verify the ExportItems response related requirements.
            // Verify the ExportItemsResponseType related requirements.
            this.VerifyExportItemsSuccessResponse(exportItemsResponse);
            #endregion

            #region Get the ExportItemsResponseMessageType items.
            ExportItemsResponseMessageType[] exportItemsResponseMessages =
                TestSuiteHelper.GetResponseMessages <ExportItemsResponseMessageType>(exportItemsResponse);
            return(exportItemsResponseMessages);

            #endregion
        }
        /// <summary>
        /// Verify the ExportItems operation responses related requirements.
        /// </summary>
        /// <param name="exportItems"> The ExportItemsResponseType object indicates ExportItems operation response.</param>
        /// <param name="isSchemaValidated"> A Boolean value indicates whether the schema has been verified.</param>
        private void VerifyExportItemsResponseType(ExportItemsResponseType exportItems, bool isSchemaValidated)
        {
            // Assert ExportItems operation response is not null.
            Site.Assert.IsNotNull(exportItems, "The response of ExportItems operation should not be null.");

            // If the proxy can communicate with server successfully, then all the WSDL related requirements can be captured.
            // Add debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R36001");

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R36001
            Site.CaptureRequirement(
                36001,
                @"[In ExportItems]The following is the WSDL port type definition of the operation.
                <wsdl:operation name=""ExportItems"">
                    <wsdl:input message=""tns:ExportItemsSoapIn""/>
                    <wsdl:output message=""tns:ExportItemsSoapOut""/>
                </wsdl:operation>");

            // If the schema validation is successful, then MS-OXWSBTRF_R51, MS-OXWSBTRF_R251, MS-OXWSBTRF_R252, MS-OXWSBTRF_R253 
            // and MS-OXWSBTRF_R254 can be captured.
            // Add debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R51");

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R51
            Site.CaptureRequirementIfIsTrue(
                isSchemaValidated,
                51,
                @"[In tns:ExportItemsSoapOut Message]The ExportItemsSoapOut WSDL message specifies the SOAP message that represents a response that contains exported items.
                <wsdl:message name=""ExportItemsSoapOut"">
                    <wsdl:part name=""ExportItemsResult"" element=""tns:ExportItemsResponse""/>
                    <wsdl:part name=""ServerVersion"" element=""t:ServerVersionInfo""/>
                </wsdl:message>");

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

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R251
            Site.CaptureRequirementIfIsTrue(
                isSchemaValidated,
                251,
                @"[In tns:ExportItemsSoapOut Message]The Element/type of ExportItemsResult is tns:ExportItemsResponse (section 3.1.4.1.2.2).");

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

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R252
            Site.CaptureRequirementIfIsTrue(
                isSchemaValidated,
                252,
                @"[In tns:ExportItemsSoapOut Message][The part ExportItemsResult] specifies the SOAP body of the response.");
            if (this.exchangeServiceBinding.ServerVersionInfoValue != null)
            {
                // Add debug information.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R253");

                // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R253
                Site.CaptureRequirementIfIsTrue(
                    isSchemaValidated,
                    253,
                    @"[In tns:ExportItemsSoapOut Message]The type of ServerVersion is ServerVersion ([MS-OXWSCDATA] section 2.2.3.12).");

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

                // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R254
                Site.CaptureRequirementIfIsTrue(
                    isSchemaValidated,
                    254,
                    @"[In tns:ExportItemsSoapOut Message][The part ServerVersion]specifies the SOAP header that identifies the server version for the response.");
            }

            // Verify BaseResponseMessageType related requirements in the protocol document MS-OXWSCDATA.
            this.VerifyBaseResponseMessageType(isSchemaValidated);

            // Verify ExportItemsResponseMessageType related requirements.
            foreach (ExportItemsResponseMessageType exportItem in exportItems.ResponseMessages.Items)
            {
                this.VerifyExportItemsResponseMessageType(exportItem, isSchemaValidated);
            }

            // If the schema validation and the above BaseResponseMessageType validation is successful, then MS-OXWSBTRF_R175 can be captured.
            // Add debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R75");

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R75
            Site.CaptureRequirementIfIsTrue(
                isSchemaValidated,
                75,
                @"[In ExportItemsResponseType Complex Type][The schema of ExportItemsResponseType is:]<xs:complexType name=""ExportItemsResponseType""><xs:complexContent><xs:extension
                    base=""m:BaseResponseMessageType""/></xs:complexContent>
                    </xs:complexType>");

            // If the schema validation is successful, then the type of ExportItemsResponse element is ExportItemsResponseType, then MS-OXWSBTRF_R63 can be captured.
            // Add debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R63");

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R63
            Site.CaptureRequirementIfIsTrue(
                isSchemaValidated,
                63,
                @"[In ExportItemsResponse Element][The schema of ExportItemsResponse is:]<xs:element name=""ExportItemsResponse""
                type=""m:ExportItemsResponseType""/>");

            // If the response from the ExportItems is not null, then MS-OXWSBTRF_R165 can be captured.
            // Add debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R165");

            // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R165
            Site.CaptureRequirementIfIsNotNull(
                exportItems,
                165,
                @"[In ExportItemsResponse Element]This element [ExportItemsResponse] MUST be present.");

            // If the schema validation is successful, the server version related requirements can be captured.
            this.VerifyServerVersion(isSchemaValidated);
        }