Microsoft.Protocols.TestSuites.MS_OXWSSYNC.S02_SyncFolderItems.MSOXWSSYNC_S02_TC05_SyncFolderItems_TaskType C# (CSharp) Method

MSOXWSSYNC_S02_TC05_SyncFolderItems_TaskType() private method

private MSOXWSSYNC_S02_TC05_SyncFolderItems_TaskType ( ) : void
return void
        public void MSOXWSSYNC_S02_TC05_SyncFolderItems_TaskType()
        {
            #region Step 1. Client invokes SyncFolderItems operation to get initial syncState of tasks folder.
            DistinguishedFolderIdNameType taskFolder = DistinguishedFolderIdNameType.tasks;
            SyncFolderItemsType request = this.CreateSyncFolderItemsRequestWithoutOptionalElements(taskFolder, DefaultShapeNamesType.AllProperties);

            // Involve InlineImageUrlTemplate element in SyncFolderItems request
            if (Common.IsRequirementEnabled(37809, this.Site))
            {
                request.ItemShape.InlineImageUrlTemplate = "Test Template";
            }

            SyncFolderItemsResponseType response = this.SYNCAdapter.SyncFolderItems(request);
            SyncFolderItemsResponseMessageType responseMessage = TestSuiteHelper.EnsureResponse<SyncFolderItemsResponseMessageType>(response);
            #endregion

            #region Step 2. Client invokes CreateItem to create a TaskType item and get its ID.
            TaskType taskItem = new TaskType();

            // Create two items on server to verify if the MaxSyncChangesReturned is set to 1, the last item should not be included in response
            BaseItemIdType[] firstItemId = this.CreateItem(taskFolder, taskItem);
            BaseItemIdType[] secondItemId = this.CreateItem(taskFolder, taskItem);
            #endregion

            #region Step 3. Client invokes SyncFolderItems operation with previous SyncState to sync the operation result in Step 2 and verify related requirements.
            // Assert the SyncState is not null
            Site.Assert.IsNotNull(responseMessage.SyncState, "The synchronization should not be null.");
            request.SyncState = responseMessage.SyncState;

            // Set MaxSyncChangesReturned to a value that is less than the number of changes to be returned to verify the false value of "IncludesLastItemInRange" element
            request.MaxChangesReturned = 1;
            response = this.SYNCAdapter.SyncFolderItems(request);
            responseMessage = TestSuiteHelper.EnsureResponse<SyncFolderItemsResponseMessageType>(response);

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

            // There are two items created in step2, but the MaxSyncChangesReturned is set to 1, so the last item should not be included in response
            // Verify MS-OXWSSYNC requirement: MS-OXWSSYNC_R6702
            Site.CaptureRequirementIfIsFalse(
                responseMessage.IncludesLastItemInRange,
                6702,
                @"[In m:SyncFolderItemsResponseMessageType Complex Type] [The element IncludesLastItemInRange] False indicates the last item to synchronize is not included in the response.");

            // Assert the changes in response is not null
            Site.Assert.IsNotNull(responseMessage.Changes, "There is one item created on server, so the changes between server and client should not be null");
            SyncFolderItemsChangesType changes = responseMessage.Changes;

            // Assert both the Items and ItemsElementName are not null
            Site.Assert.IsNotNull(changes.ItemsElementName, "There should be changes information returned in SyncFolderItems response since there is one item created on server.");
            Site.Assert.IsNotNull(changes.Items, "There should be item information returned in SyncFolderItems response since there is one item created on server.");

            Site.Assert.AreEqual<int>(
                1,
                changes.Items.Length,
                "There are two TaskType items were created in previous step, but if the MaxChangesReturned is set to 1, the count of Items array in responseMessage.Changes should be 1.");

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

            // There are two items created on server, but if the value of MaxChangesRetured is set to 1, there should be just one item returned in changes
            // Verify MS-OXWSSYNC requirement: MS-OXWSSYNC_R3891
            Site.CaptureRequirement(
                3891,
                @"[In m:SyncFolderItemsType Complex Type] This element [MaxChangesReturned] is set between 1 and 512, inclusive, the correct changes number returned in a synchronization response.");

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

            // If the description of MS-OXWSSYNC_R3891 is true, then requirement MS-OXWSSYNC_R388 can be captured.
            // Verify MS-OXWSSYNC requirement: MS-OXWSSYNC_R388
            Site.CaptureRequirement(
                388,
                @"[In m:SyncFolderItemsType Complex Type] [The element MaxChangesReturned] specifies the maximum number of changes that can be returned in a synchronization response.");

            // If the type of item in SyncFolderItems response is TaskType, then requirement MS-OXWSSYNC_R172 can be captured.
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSSYNC_R172");

            // Verify MS-OXWSSYNC requirement: MS-OXWSSYNC_R172
            Site.CaptureRequirementIfIsInstanceOfType(
                (changes.Items[0] as SyncFolderItemsCreateOrUpdateType).Item,
                typeof(TaskType),
                172,
                @"[In t:SyncFolderItemsCreateOrUpdateType Complex Type]The type of Task is t:TaskType ([MS-OXWSTASK] section 2.2.4.6).");

            Site.Assert.AreEqual<int>(
                1,
                changes.ItemsElementName.Length,
                "There are two TaskType items were created in previous step, but if the MaxChangesReturned is set to 1, the count of ItemsElementName array in responseMessage.Changes should be 1.");

            bool isTaskTypeItemCreated = changes.ItemsElementName[0] == ItemsChoiceType1.Create &&
                    (changes.Items[0] as SyncFolderItemsCreateOrUpdateType).Item.GetType() == typeof(TaskType);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-OXWSSYNC_R1731. Expected value: ItemsElementName: {0}, item type: {1}; actual value: ItemsElementName: {2}, item type: {3}",
                ItemsChoiceType1.Create,
                typeof(TaskType),
                changes.ItemsElementName[0],
                (changes.Items[0] as SyncFolderItemsCreateOrUpdateType).Item.GetType());

            // If the ItemsElementName of Changes is Create and the type of Item is TaskType, it indicates a task 
            // has been created on server and synced on client, then requirement MS-OXWSSYNC_R1731 can be captured.
            // Verify MS-OXWSSYNC requirement: MS-OXWSSYNC_R1731
            Site.CaptureRequirementIfIsTrue(
                isTaskTypeItemCreated,
                1731,
                @"[In t:SyncFolderItemsCreateOrUpdateType Complex Type][The element Task] specifies a task to create in the client message store.");

            // If MS-OXWSSYNC_R37809 is enabled, then verify this requirement
            if (Common.IsRequirementEnabled(37809, this.Site))
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSSYNC_R37809");

                // If the request involves the InlineImageUrlTemplate element and response is successful, then requirement MS-OXWSSYNC_37809 can be captured.
                // Verify MS-OXWSSYNC: MS-OXWSSYNC_R37809
                Site.CaptureRequirementIfAreEqual<ResponseClassType>(
                    ResponseClassType.Success,
                    responseMessage.ResponseClass,
                    37809,
                    @"[In Appendix C: Product Behavior] Implementation does use the InlineImageUrlTemplate element. The InlineImageUrlTemplate element which is subelement 
                of ItemShape specifies the name of the template for the inline image URL. (Exchange 2013 and above follow this behavior.)");
            }
            #endregion

            #region Step 4. Client invokes DeleteItem operation to delete the second item that created in step2.
            this.DeleteItem(secondItemId);
            #endregion

            #region Step 5. Client invokes SyncFolderItems operation with previous SyncState to get the SyncState
            responseMessage = this.GetResponseMessage(taskFolder, responseMessage, DefaultShapeNamesType.AllProperties);
            #endregion

            #region Step 6. Client invokes UpdateItem operation to update the created item which created in Step 2.
            // Generate a new item subject
            string newItemSubject = Common.GenerateResourceName(this.Site, taskFolder + "NewItemSubject");
            this.UpdateItemSubject(firstItemId, newItemSubject);
            #endregion

            #region Step 7. Client invokes SyncFolderItems operation with previous SyncState to sync the operation result in Step 6 and verify related requirements.
            responseMessage = this.GetResponseMessage(taskFolder, responseMessage, DefaultShapeNamesType.AllProperties);

            // Assert the changes in response is not null
            Site.Assert.IsNotNull(responseMessage.Changes, "There is one item updated on server, so the changes between server and client should not be null");
            changes = responseMessage.Changes;

            // Assert both the Items and ItemsElementName are not null
            Site.Assert.IsNotNull(changes.ItemsElementName, "There should be changes information returned in SyncFolderItems response since there is one item updated on server.");
            Site.Assert.IsNotNull(changes.Items, "There should be item information returned in SyncFolderItems response since there is one item updated on server.");

            Site.Assert.AreEqual<int>(1, changes.Items.Length, "Just one TaskType item was updated in previous step, so the count of Items array in responseMessage.Changes should be 1.");
            Site.Assert.AreEqual<int>(1, changes.ItemsElementName.Length, "Just one TaskType item was updated in previous step, so the count of ItemsElementName array in responseMessage.Changes should be 1.");

            bool isTaskItemUpdated = changes.ItemsElementName[0] == ItemsChoiceType1.Update
                && (changes.Items[0] as SyncFolderItemsCreateOrUpdateType).Item.GetType() == typeof(TaskType);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-OXWSSYNC_R1732. Expected value: ItemsElementName: {0}, item type: {1}; actual value: ItemsElementName: {2}, item type: {3}",
                ItemsChoiceType1.Update,
                typeof(TaskType),
                changes.ItemsElementName[0],
                (changes.Items[0] as SyncFolderItemsCreateOrUpdateType).Item.GetType());

            // If the ItemsElementName of Changes is Update and the type of Item is TaskType, it indicates a task
            // has been updated on server and synced on client, then requirement MS-OXWSSYNC_R1732 can be captured.
            // Verify MS-OXWSSYNC requirement: MS-OXWSSYNC_R1732
            Site.CaptureRequirementIfIsTrue(
                isTaskItemUpdated,
                1732,
                @"[In t:SyncFolderItemsCreateOrUpdateType Complex Type][The element Task] specifies a task to update in the client message store.");
            #endregion

            #region Step 8. Client invokes DeleteItem operation to delete the TaskType item which updated in Step 6.
            this.DeleteItem(firstItemId);
            #endregion

            #region Step 9. Client invokes SyncFolderItems operation with previous SyncState to sync the operation result in Step 8.
            responseMessage = this.GetResponseMessage(taskFolder, responseMessage, DefaultShapeNamesType.AllProperties);

            // Assert the changes in response is not null
            Site.Assert.IsNotNull(responseMessage.Changes, "There is one item deleted on server, so the changes between server and client should not be null");
            changes = responseMessage.Changes;

            // Assert both the Items and ItemsElementName are not null
            Site.Assert.IsNotNull(changes.ItemsElementName, "There should be changes information returned in SyncFolderItems response since there is one item deleted on server.");
            Site.Assert.IsNotNull(changes.Items, "There should be item information returned in SyncFolderItems response since there is one item deleted on server.");

            Site.Assert.AreEqual<int>(1, changes.Items.Length, "Just one TaskType item was deleted in previous step, so the count of Items array in responseMessage.Changes should be 1.");
            Site.Assert.IsTrue(
                changes.Items[0].GetType() == typeof(SyncFolderItemsDeleteType),
                string.Format("The responseMessage.Changes.Items should be an instance of '{0}'.", typeof(SyncFolderItemsDeleteType)));

            Site.Assert.AreEqual<int>(1, changes.ItemsElementName.Length, "Just one TaskType item was deleted in previous step, so the count of ItemsElementName array in responseMessage.Changes should be 1.");
            Site.Assert.IsTrue(
                changes.ItemsElementName[0] == ItemsChoiceType1.Delete,
                string.Format("The responseMessage.Changes.ItemsElementName should be 'Delete', the actual value is '{0}'", changes.ItemsElementName[0]));
            #endregion
        }