A static class contains all helper methods used in test cases.
Exemplo n.º 1
0
        /// <summary>
        /// Call Sync command to add a task.
        /// </summary>
        /// <param name="addElements">The elements of a task item to be added.</param>
        /// <returns>Return the sync response.</returns>
        protected SyncStore SyncAddTask(Dictionary <Request.ItemsChoiceType8, object> addElements)
        {
            SyncStore initializeSyncResponse = this.TASKAdapter.Sync(Common.CreateInitialSyncRequest(this.UserInformation.TasksCollectionId));

            // Verify sync result
            Site.Assert.AreEqual <byte>(
                1,
                initializeSyncResponse.CollectionStatus,
                "The server should return a status code 1 in the Sync command response to indicate the Sync command executes successfully.");

            Dictionary <Request.ItemsChoiceType8, object> task = TestSuiteHelper.CreateTaskElements();

            // Add elements
            if (addElements != null)
            {
                foreach (KeyValuePair <Request.ItemsChoiceType8, object> item in addElements)
                {
                    if (task.ContainsKey(item.Key))
                    {
                        task[item.Key] = item.Value;
                    }
                    else
                    {
                        task.Add(item.Key, item.Value);
                    }
                }
            }

            List <object> addData = new List <object>();

            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId        = System.Guid.NewGuid().ToString(),
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    Items            = task.Values.ToArray <object>(),
                    ItemsElementName = task.Keys.ToArray <Request.ItemsChoiceType8>()
                }
            };
            addData.Add(add);

            SyncRequest syncRequest  = TestSuiteHelper.CreateSyncRequest(initializeSyncResponse.SyncKey, this.UserInformation.TasksCollectionId, addData);
            SyncStore   syncResponse = this.TASKAdapter.Sync(syncRequest);

            Site.Assert.AreEqual <byte>(
                1,
                syncResponse.CollectionStatus,
                "The server should return a Status 1 in the Sync command response indicate sync command succeed.");

            Site.Assert.IsNotNull(
                syncResponse.AddResponses,
                @"The Add elements in Responses element of the Sync response should not be null.");

            return(syncResponse);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Call Sync command to delete a task.
        /// </summary>
        /// <param name="syncKey">The sync key.</param>
        /// <param name="serverId">The server id of the task, which is returned by server.</param>
        /// <returns>Return the sync delete result.</returns>
        protected SyncStore SyncDeleteTask(string syncKey, string serverId)
        {
            List <object> deleteData = new List <object>();

            Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete {
                ServerId = serverId
            };
            deleteData.Add(delete);

            SyncRequest syncRequest  = TestSuiteHelper.CreateSyncRequest(syncKey, this.UserInformation.TasksCollectionId, deleteData);
            SyncStore   syncResponse = this.TASKAdapter.Sync(syncRequest);

            return(syncResponse);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Synchronize changes between client and server.
        /// </summary>
        /// <param name="collectionId">Specify the folder collection Id which needs to be synchronized.</param>
        /// <returns>Return the sync response.</returns>
        public SyncStore SyncChanges(string collectionId)
        {
            SyncStore syncResponse;

            int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
            int waitTime   = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site));
            int counter    = 0;

            // Synchronize to get the SyncKey.
            SyncStore   initializeSyncResponse = this.TASKAdapter.Sync(Common.CreateInitialSyncRequest(collectionId));
            SyncRequest syncRequest            = TestSuiteHelper.CreateSyncRequest(initializeSyncResponse.SyncKey, collectionId, null);

            do
            {
                Thread.Sleep(waitTime);

                // Get the server changes through sync command.
                syncResponse = this.TASKAdapter.Sync(syncRequest);
                if (syncResponse != null)
                {
                    if (syncResponse.CollectionStatus == 1)
                    {
                        break;
                    }
                }

                counter++;
            }while (counter < retryCount);

            // Verify sync response
            Site.Assert.AreEqual <byte>(
                1,
                syncResponse.CollectionStatus,
                "If the Sync command executes successfully, the Status in response should be 1.");

            return(syncResponse);
        }
Exemplo n.º 4
0
        public void MSASTASK_S02_TC01_RetrieveTaskItemWithItemOperations()
        {
            #region Call Sync command to create a task item

            Dictionary <Request.ItemsChoiceType8, object> taskItem = new Dictionary <Request.ItemsChoiceType8, object>();
            string subject = Common.GenerateResourceName(Site, "subject");
            taskItem.Add(Request.ItemsChoiceType8.Subject2, subject);

            #endregion

            #region Call Sync command to add the task to the server

            // add task
            SyncStore syncResponse = this.SyncAddTask(taskItem);
            Site.Assert.AreEqual <int>(1, int.Parse(syncResponse.AddResponses[0].Status), "Adding a task item to server should success.");
            SyncItem task = this.GetChangeItem(this.UserInformation.TasksCollectionId, subject);
            Site.Assert.IsNotNull(task.Task, "The task which subject is {0} should exist in server.", subject);
            ItemsNeedToDelete.Add(subject);

            #endregion

            #region Call ItemOperations command to fetch tasks

            syncResponse = this.SyncChanges(this.UserInformation.TasksCollectionId);

            List <string> serverIds = new List <string>();
            for (int i = 0; i < syncResponse.AddElements.Count; i++)
            {
                serverIds.Add(syncResponse.AddElements[i].ServerId);
            }

            Request.Schema schema = new Request.Schema
            {
                ItemsElementName = new Request.ItemsChoiceType4[1],
                Items            = new object[1]
            };
            schema.ItemsElementName[0] = Request.ItemsChoiceType4.Body;
            schema.Items[0]            = new Request.Body();

            Request.BodyPreference bodyReference = new Request.BodyPreference {
                Type = 1
            };

            ItemOperationsRequest itemOperationsRequest  = TestSuiteHelper.CreateItemOperationsFetchRequest(this.UserInformation.TasksCollectionId, serverIds, null, bodyReference, schema);
            ItemOperationsStore   itemOperationsResponse = this.TASKAdapter.ItemOperations(itemOperationsRequest);
            Site.Assert.AreEqual <string>("1", itemOperationsResponse.Status, "The ItemOperations response should be successful.");

            #endregion

            // Get task item that created in this case.
            ItemOperations taskReturnedInItemOperations = null;
            foreach (ItemOperations item in itemOperationsResponse.Items)
            {
                if (task.Task.Body.Data.ToString().Contains(item.Task.Body.Data))
                {
                    taskReturnedInItemOperations = item;
                }
            }

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

            // Verify MS-ASTASK requirement: MS-ASTASK_R356
            // If the Task item in response is not null, this requirement will be captured.
            Site.CaptureRequirementIfIsNotNull(
                taskReturnedInItemOperations.Task,
                356,
                @"[In ItemOperations Command Response] When a client uses an ItemOperations command request ([MS-ASCMD] section 2.2.2.8) to retrieve data from the server for one or more specific Task items, as specified in section 3.1.5.1, the server responds with an ItemOperations command response ([MS-ASCMD] section 2.2.2.8).");

            bool otherPropertiesNull = true;

            // Loop to verify if other properties except "Body" are not returned.
            foreach (System.Reflection.PropertyInfo propertyInfo in typeof(Task).GetProperties())
            {
                if (propertyInfo.Name != "Body")
                {
                    object value = propertyInfo.GetValue(taskReturnedInItemOperations.Task, null);
                    if (value != null)
                    {
                        otherPropertiesNull = false;
                        break;
                    }
                }
            }

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

            // Verify MS-ASTASK requirement: MS-ASTASK_R358
            // If the body of the Task item in response is not null, this requirement can be captured.
            Site.CaptureRequirementIfIsTrue(
                otherPropertiesNull,
                358,
                @"[In ItemOperations Command Response] If an itemoperations:Schema element ([MS-ASCMD] section 2.2.3.135) is included in the ItemOperations command request, then the elements returned in the ItemOperations command response MUST be restricted to the elements that were included as child elements of the itemoperations:Schema element in the command request.");

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

            // Since MS-ASTASK_R358 is captured, this requirement can be captured.
            Site.CaptureRequirement(
                359,
                @"[In ItemOperations Command Response] Top-level Task class elements, as specified in section 2.2, MUST be returned as child elements of the itemoperations:Properties element ([MS-ASCMD] section 2.2.3.128) in the ItemOperations command response.");
        }
        public void MSASTASK_S03_TC01_RetrieveTaskItemWithSearch()
        {
            #region Call Sync command to create a task item

            Dictionary <Request.ItemsChoiceType8, object> taskItem = new Dictionary <Request.ItemsChoiceType8, object>();
            string subject = Common.GenerateResourceName(Site, "subject");
            taskItem.Add(Request.ItemsChoiceType8.Subject2, subject);

            #endregion

            #region Call Sync command to add the task to the server

            // add task
            SyncStore syncResponse = this.SyncAddTask(taskItem);
            Site.Assert.AreEqual <int>(1, int.Parse(syncResponse.AddResponses[0].Status), "Adding a task item to server should success.");
            SyncItem task = this.GetChangeItem(this.UserInformation.TasksCollectionId, subject);
            Site.Assert.IsNotNull(task.Task, "The task which subject is {0} should exist in server.", subject);
            ItemsNeedToDelete.Add(subject);

            #endregion

            #region Call Search command to search task on the server

            Request.Options1 option = new Request.Options1();
            Dictionary <Request.ItemsChoiceType6, object> items = new Dictionary <Request.ItemsChoiceType6, object>
            {
                {
                    Request.ItemsChoiceType6.DeepTraversal, string.Empty
                },
                {
                    Request.ItemsChoiceType6.RebuildResults, string.Empty
                },
                {
                    Request.ItemsChoiceType6.Range, "0-9"
                }
            };
            option.Items            = items.Values.ToArray <object>();
            option.ItemsElementName = items.Keys.ToArray <Request.ItemsChoiceType6>();

            Request.queryType queryItem = new Request.queryType
            {
                Items = new object[] { "Tasks", this.UserInformation.TasksCollectionId, subject },

                ItemsElementName = new Request.ItemsChoiceType2[]
                {
                    Request.ItemsChoiceType2.Class,
                    Request.ItemsChoiceType2.CollectionId,
                    Request.ItemsChoiceType2.FreeText
                }
            };

            Request.queryType queryType = new Request.queryType
            {
                Items            = new object[] { queryItem },
                ItemsElementName = new Request.ItemsChoiceType2[] { Request.ItemsChoiceType2.And }
            };

            SearchRequest searchRequest = TestSuiteHelper.CreateSearchRequest(SearchName.Mailbox.ToString(), option, queryType);

            // Search the task
            SearchStore searchResponse = this.TASKAdapter.Search(searchRequest);

            // Verify search response
            Site.Assert.AreNotEqual <int>(0, searchResponse.Range.Length, "The search response should be successful");

            #endregion

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

            // Verify MS-ASTASK requirement: MS-ASTASK_R361
            // If the Task item in response is not null, this requirement can be captured.
            Site.CaptureRequirementIfIsNotNull(
                searchResponse.Results[0].Task,
                361,
                @"[In Search Command Response] When a client uses the Search command request ([MS-ASCMD] section 2.2.2.14) to retrieve Task class items from the server that match the criteria specified by the client, as specified in section 3.1.5.2, the server responds with a Search command response ([MS-ASCMD] section 2.2.2.14).");

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

            // Since MS-ASTASK_R361 is captured, this requirement can be captured too.
            Site.CaptureRequirement(
                363,
                @"[In Search Command Response] Top-level Task class elements, as specified in section 2.2, are returned as child elements of the search:Properties element ([MS-ASCMD] section 2.2.3.128) in the Search command response.");
        }