Beispiel #1
0
        /// <summary>
        /// Generate a Sync Add command with body element.
        /// </summary>
        /// <returns>Returns a command list instance.</returns>
        private static object[] CreateSyncAddCommands()
        {
            Request.Body addBody = new Request.Body {
                Type = 1, Data = "Test sync add"
            };

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

            items.Add(addBody);
            itemsElementName.Add(Request.ItemsChoiceType8.Body);

            Request.SyncCollectionAddApplicationData applicationData = new Request.SyncCollectionAddApplicationData
            {
                Items            = items.ToArray(),
                ItemsElementName = itemsElementName.ToArray()
            };

            Request.SyncCollectionAdd syncAdd = new Request.SyncCollectionAdd
            {
                ClientId        = Guid.NewGuid().ToString("N"),
                ApplicationData = applicationData
            };

            List <object> commandList = new List <object> {
                syncAdd
            };

            return(commandList.ToArray());
        }
        /// <summary>
        /// Call Sync command to add items to the specified folder.
        /// </summary>
        /// <param name="collectionId">The CollectionId of the specified folder.</param>
        /// <param name="subject">Subject of the item to add.</param>
        /// <param name="syncKey">The latest SyncKey.</param>
        protected void SyncAdd(string collectionId, string subject, string syncKey)
        {
            // Create Sync request.
            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId        = Guid.NewGuid().ToString(),
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    Items            = new object[] { subject },
                    ItemsElementName = new Request.ItemsChoiceType8[] { Request.ItemsChoiceType8.Subject2 }
                }
            };

            Request.SyncCollection collection = new Request.SyncCollection
            {
                Commands     = new object[] { add },
                CollectionId = collectionId,
                SyncKey      = syncKey
            };
            SyncRequest syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { collection });

            // Call Sync command to add the item.
            SyncStore syncStore = this.CONAdapter.Sync(syncRequest);

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

            this.LatestSyncKey = syncStore.SyncKey;
        }
Beispiel #3
0
        /// <summary>
        /// Add a meeting or appointment to server
        /// </summary>
        /// <param name="calendar">the calendar item</param>
        private void SyncAddCalendar(Calendar calendar)
        {
            Request.SyncCollectionAddApplicationData applicationData = SetApplicationDataFromCalendar(calendar);

            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            Request.SyncCollectionAdd addCalendar = new Request.SyncCollectionAdd
            {
                ClientId        = TestSuiteBase.ClientId,
                ApplicationData = applicationData
            };

            SyncRequest  syncAddCalendarRequest  = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, addCalendar);
            SyncResponse syncAddCalendarResponse = this.CMDAdapter.Sync(syncAddCalendarRequest);

            // Get data from response
            Response.SyncCollections syncCollections = (Response.SyncCollections)syncAddCalendarResponse.ResponseData.Item;
            Response.SyncCollectionsCollectionResponses syncResponses = null;
            for (int index = 0; index < syncCollections.Collection[0].ItemsElementName.Length; index++)
            {
                if (syncCollections.Collection[0].ItemsElementName[index] == Response.ItemsChoiceType10.Responses)
                {
                    syncResponses = (Response.SyncCollectionsCollectionResponses)syncCollections.Collection[0].Items[index];
                    break;
                }
            }

            Site.Assert.AreEqual(1, syncResponses.Add.Length, "User only upload one calendar item");
            int statusCode = int.Parse(syncResponses.Add[0].Status);

            Site.Assert.AreEqual(1, statusCode, "If upload calendar item successful, server should return status 1");
        }
Beispiel #4
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);
        }
        /// <summary>
        /// Create a Sync Add request.
        /// </summary>
        /// <param name="syncKey">Specify the sync key obtained from the last Sync response</param>
        /// <param name="collectionId">Specify the serverId of the folder to be synchronized.</param>
        /// <param name="applicationData">The data used to specify the Add element for Sync command.</param>
        /// <returns>The SyncRequest instance.</returns>
        internal static SyncRequest CreateSyncAddRequest(string syncKey, string collectionId, Request.SyncCollectionAddApplicationData applicationData)
        {
            SyncRequest syncAddRequest = TestSuiteHelper.CreateSyncRequest(syncKey, collectionId, null);
            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId = Guid.NewGuid().ToString("N"),
                ApplicationData = applicationData
            };

            List<object> commandList = new List<object> { add };

            syncAddRequest.RequestData.Collections[0].Commands = commandList.ToArray();

            return syncAddRequest;
        }
        /// <summary>
        /// Builds a Sync add request by using the specified sync key, folder collection ID and add application data.
        /// In general, returns the XMl formatted Sync request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <Sync xmlns="AirSync">
        ///   <Collections>
        ///     <Collection>
        ///       <SyncKey>0</SyncKey>
        ///       <CollectionId>5</CollectionId>
        ///       <GetChanges>1</GetChanges>
        ///       <WindowSize>152</WindowSize>
        ///        <Commands>
        ///            <Add>
        ///                <ServerId>5:1</ServerId>
        ///                <ApplicationData>
        ///                    ...
        ///                </ApplicationData>
        ///            </Add>
        ///        </Commands>
        ///     </Collection>
        ///   </Collections>
        /// </Sync>
        /// -->
        /// </summary>
        /// <param name="collectionId">Specify the server ID of the folder to be synchronized, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.5)</param>
        /// <param name="syncKey">Specify the sync key obtained from the last sync response(Refer to [MS-ASCMD]2.2.3.166.4)</param>
        /// <param name="addCalendars">Contains the data used to specify the Add element for Sync command(Refer to [MS-ASCMD]2.2.3.7.2)</param>
        /// <returns>Returns the SyncRequest instance</returns>
        internal static SyncRequest CreateSyncAddRequest(string collectionId, string syncKey, Request.SyncCollectionAddApplicationData addCalendars)
        {
            SyncRequest syncAddRequest;
            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteHelper.Next(),
                ApplicationData = addCalendars
            };

            List<object> commandList = new List<object> { add };

            // The Sync request include the GetChanges element of the Collection element will set to 0 (FALSE)
            syncAddRequest = TestSuiteHelper.CreateSyncRequest(collectionId, syncKey, false);
            syncAddRequest.RequestData.Collections[0].Commands = commandList.ToArray();

            return syncAddRequest;
        }
Beispiel #7
0
        /// <summary>
        /// Create a sync add request.
        /// </summary>
        /// <param name="syncKey">Specify the sync key obtained from the last sync response</param>
        /// <param name="collectionId">Specify the server ID of the folder to be synchronized, which can be returned by ActiveSync FolderSync command.</param>
        /// <param name="applicationData">Contains the data used to specify the Add element for Sync command.</param>
        /// <returns>Returns the SyncRequest instance.</returns>
        internal static SyncRequest CreateSyncAddRequest(string syncKey, string collectionId, Request.SyncCollectionAddApplicationData applicationData)
        {
            SyncRequest syncAddRequest = TestSuiteHelper.CreateSyncRequest(syncKey, collectionId, null);

            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId        = GetClientId(),
                ApplicationData = applicationData
            };

            List <object> commandList = new List <object> {
                add
            };

            syncAddRequest.RequestData.Collections[0].Commands = commandList.ToArray();

            return(syncAddRequest);
        }
Beispiel #8
0
        public void MSASNOTE_S01_TC05_Sync_InvalidMessageClass()
        {
            #region Call method Sync to add a note to the server
            Dictionary <Request.ItemsChoiceType8, object> addElements = this.CreateNoteElements();
            addElements[Request.ItemsChoiceType8.MessageClass] = "IPM.invalidClass";
            SyncRequest syncRequest = TestSuiteHelper.CreateInitialSyncRequest(this.UserInformation.NotesCollectionId);
            SyncStore   syncResult  = this.NOTEAdapter.Sync(syncRequest, false);

            Site.Assert.AreEqual <byte>(
                1,
                syncResult.CollectionStatus,
                "The server should return a status code 1 in the Sync command response indicate sync command success.");

            List <object>             addData = new List <object>();
            Request.SyncCollectionAdd add     = new Request.SyncCollectionAdd
            {
                ClientId        = System.Guid.NewGuid().ToString(),
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    ItemsElementName = new Request.ItemsChoiceType8[addElements.Count],
                    Items            = new object[addElements.Count]
                }
            };

            addElements.Keys.CopyTo(add.ApplicationData.ItemsElementName, 0);
            addElements.Values.CopyTo(add.ApplicationData.Items, 0);
            addData.Add(add);

            syncRequest = TestSuiteHelper.CreateSyncRequest(syncResult.SyncKey, this.UserInformation.NotesCollectionId, addData);
            SyncStore addResult = this.NOTEAdapter.Sync(syncRequest, false);

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

            // Verify MS-ASNOTE requirement: MS-ASNOTE_R119
            Site.CaptureRequirementIfAreEqual <int>(
                6,
                int.Parse(addResult.AddResponses[0].Status),
                119,
                @"[In MessageClass Element] If a client submits a Sync command request ([MS-ASCMD] section 2.2.2.19) that contains a MessageClass element value that does not conform to the requirements specified in section 2.2.2.5, the server MUST respond with a Status element with a value of 6, as specified in [MS-ASCMD] section 2.2.3.162.16.");

            #endregion
        }
        /// <summary>
        /// Builds a Sync add request by using the specified sync key, folder collection ID and add application data.
        /// In general, returns the XMl formatted Sync request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <Sync xmlns="AirSync">
        ///   <Collections>
        ///     <Collection>
        ///       <SyncKey>0</SyncKey>
        ///       <CollectionId>5</CollectionId>
        ///       <GetChanges>1</GetChanges>
        ///       <WindowSize>152</WindowSize>
        ///        <Commands>
        ///            <Add>
        ///                <ServerId>5:1</ServerId>
        ///                <ApplicationData>
        ///                    ...
        ///                </ApplicationData>
        ///            </Add>
        ///        </Commands>
        ///     </Collection>
        ///   </Collections>
        /// </Sync>
        /// -->
        /// </summary>
        /// <param name="collectionId">Specify the server ID of the folder to be synchronized, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.5)</param>
        /// <param name="syncKey">Specify the sync key obtained from the last sync response(Refer to [MS-ASCMD]2.2.3.166.4)</param>
        /// <param name="addCalendars">Contains the data used to specify the Add element for Sync command(Refer to [MS-ASCMD]2.2.3.7.2)</param>
        /// <returns>Returns the SyncRequest instance</returns>
        internal static SyncRequest CreateSyncAddRequest(string collectionId, string syncKey, Request.SyncCollectionAddApplicationData addCalendars)
        {
            SyncRequest syncAddRequest;

            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId        = TestSuiteHelper.Next(),
                ApplicationData = addCalendars
            };

            List <object> commandList = new List <object> {
                add
            };

            // The Sync request include the GetChanges element of the Collection element will set to 0 (FALSE)
            syncAddRequest = TestSuiteHelper.CreateSyncRequest(collectionId, syncKey, false);
            syncAddRequest.RequestData.Collections[0].Commands = commandList.ToArray();

            return(syncAddRequest);
        }
        /// <summary>
        /// Call Sync command to add a note
        /// </summary>
        /// <param name="addElements">The elements of a note item to be added</param>
        /// <param name="count">The number of the note</param>
        /// <returns>Return the sync add result</returns>
        protected SyncStore SyncAdd(Dictionary<Request.ItemsChoiceType8, object> addElements, int count)
        {
            SyncRequest syncRequest = TestSuiteHelper.CreateInitialSyncRequest(this.UserInformation.NotesCollectionId);
            SyncStore syncResult = this.NOTEAdapter.Sync(syncRequest, false);

            // Verify sync change result
            this.Site.Assert.AreEqual<byte>(
                1,
                syncResult.CollectionStatus,
                "The server should return a status code 1 in the Sync command response indicate sync command success.");

            List<object> addData = new List<object>();
            string[] subjects = new string[count];

            // Construct every note
            for (int i = 0; i < count; i++)
            {
                Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
                {
                    ClientId = System.Guid.NewGuid().ToString(),
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName = new Request.ItemsChoiceType8[addElements.Count],
                        Items = new object[addElements.Count]
                    }
                };

                // Since only one subject is generated in addElement, if there are multiple notes, generate unique subjects with index for every note.
                if (count > 1)
                {
                    addElements[Request.ItemsChoiceType8.Subject1] = Common.GenerateResourceName(this.Site, "subject", (uint)(i + 1));
                }

                subjects[i] = addElements[Request.ItemsChoiceType8.Subject1].ToString();
                addElements.Keys.CopyTo(add.ApplicationData.ItemsElementName, 0);
                addElements.Values.CopyTo(add.ApplicationData.Items, 0);
                addData.Add(add);
            }

            syncRequest = TestSuiteHelper.CreateSyncRequest(syncResult.SyncKey, this.UserInformation.NotesCollectionId, addData);
            SyncStore addResult = this.NOTEAdapter.Sync(syncRequest, false);

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

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

            this.Site.Assert.AreEqual<int>(
                count,
                addResult.AddResponses.Count,
                @"The actual number of note items should be returned in Sync response as the expected number.");

            for (int i = 0; i < count; i++)
            {
                this.Site.Assert.IsNotNull(
                    addResult.AddResponses[i],
                    @"The Add element in response should not be null.");

                this.Site.Assert.AreEqual<int>(
                    1,
                    int.Parse(addResult.AddResponses[i].Status),
                    "The server should return a Status 1 in the Sync command response indicate sync command succeed.");

                this.ExistingNoteSubjects.Add(subjects[i]);
            }

            return addResult;
        }
        /// <summary>
        /// Call Sync command to add a note
        /// </summary>
        /// <param name="addElements">The elements of a note item to be added</param>
        /// <param name="count">The number of the note</param>
        /// <returns>Return the sync add result</returns>
        protected SyncStore SyncAdd(Dictionary <Request.ItemsChoiceType8, object> addElements, int count)
        {
            SyncRequest syncRequest = TestSuiteHelper.CreateInitialSyncRequest(this.UserInformation.NotesCollectionId);
            SyncStore   syncResult  = this.NOTEAdapter.Sync(syncRequest, false);

            // Verify sync change result
            this.Site.Assert.AreEqual <byte>(
                1,
                syncResult.CollectionStatus,
                "The server should return a status code 1 in the Sync command response indicate sync command success.");

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

            string[] subjects = new string[count];

            // Construct every note
            for (int i = 0; i < count; i++)
            {
                Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
                {
                    ClientId        = System.Guid.NewGuid().ToString(),
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName = new Request.ItemsChoiceType8[addElements.Count],
                        Items            = new object[addElements.Count]
                    }
                };

                // Since only one subject is generated in addElement, if there are multiple notes, generate unique subjects with index for every note.
                if (count > 1)
                {
                    addElements[Request.ItemsChoiceType8.Subject1] = Common.GenerateResourceName(this.Site, "subject", (uint)(i + 1));
                }

                subjects[i] = addElements[Request.ItemsChoiceType8.Subject1].ToString();
                addElements.Keys.CopyTo(add.ApplicationData.ItemsElementName, 0);
                addElements.Values.CopyTo(add.ApplicationData.Items, 0);
                addData.Add(add);
            }

            syncRequest = TestSuiteHelper.CreateSyncRequest(syncResult.SyncKey, this.UserInformation.NotesCollectionId, addData);
            SyncStore addResult = this.NOTEAdapter.Sync(syncRequest, false);

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

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

            this.Site.Assert.AreEqual <int>(
                count,
                addResult.AddResponses.Count,
                @"The actual number of note items should be returned in Sync response as the expected number.");

            for (int i = 0; i < count; i++)
            {
                this.Site.Assert.IsNotNull(
                    addResult.AddResponses[i],
                    @"The Add element in response should not be null.");

                this.Site.Assert.AreEqual <int>(
                    1,
                    int.Parse(addResult.AddResponses[i].Status),
                    "The server should return a Status 1 in the Sync command response indicate sync command succeed.");

                this.ExistingNoteSubjects.Add(subjects[i]);
            }

            return(addResult);
        }
        public void MSASCMD_S19_TC49_Sync_SoftDelete()
        {
            Site.Assume.AreNotEqual<string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Class element is not supported in a Sync command response when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Add a new calendar before 14 days
            string calendarSubject = Common.GenerateResourceName(Site, "calendarSubject");
            string location = Common.GenerateResourceName(Site, "Room");
            DateTime startTime = DateTime.Now.AddDays(-16);
            DateTime endTime = startTime.AddHours(1.0);
            Request.SyncCollectionAdd calendarData;

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                calendarData = new Request.SyncCollectionAdd
                {
                    ClientId = TestSuiteBase.ClientId,
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Location,
                            Request.ItemsChoiceType8.StartTime, Request.ItemsChoiceType8.EndTime,
                            Request.ItemsChoiceType8.UID
                        },
                        Items =
                            new object[]
                        {
                            calendarSubject, location, startTime.ToString("yyyyMMddTHHmmssZ"),
                            endTime.ToString("yyyyMMddTHHmmssZ"), Guid.NewGuid().ToString()
                        }
                    },
                    Class = "Calendar"
                };
            }
            else
            {
                calendarData = new Request.SyncCollectionAdd
                {
                    ClientId = TestSuiteBase.ClientId,
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Location1,
                            Request.ItemsChoiceType8.StartTime, Request.ItemsChoiceType8.EndTime
                        },
                        Items =
                            new object[]
                        {
                            calendarSubject, 
                            new Request.Location
                            {
                            LocationUri=location
                            }, 
                            startTime.ToString("yyyyMMddTHHmmssZ"),
                            endTime.ToString("yyyyMMddTHHmmssZ")
                        }
                    },
                    Class = "Calendar"
                };
            }

            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId));

            SyncRequest syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            SyncResponse syncResponse = this.Sync(syncRequest, true);
            Response.SyncCollectionsCollectionResponses responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);
            #endregion

            #region Add a new calendar within 14 days
            calendarSubject = Common.GenerateResourceName(this.Site, "calendarSubject");
            location = Common.GenerateResourceName(this.Site, "Room");
            startTime = DateTime.Now.AddDays(-10);
            endTime = startTime.AddHours(1.0);

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                calendarData = new Request.SyncCollectionAdd
                {
                    ClientId = TestSuiteBase.ClientId,
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Location,
                            Request.ItemsChoiceType8.StartTime, Request.ItemsChoiceType8.EndTime,
                            Request.ItemsChoiceType8.UID
                        },
                        Items =
                            new object[]
                        {
                            calendarSubject, location, startTime.ToString("yyyyMMddTHHmmssZ"),
                            endTime.ToString("yyyyMMddTHHmmssZ"), Guid.NewGuid().ToString()
                        }
                    },
                    Class = "Calendar"
                };
            }
            else
            {
                calendarData = new Request.SyncCollectionAdd
                {
                    ClientId = TestSuiteBase.ClientId,
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Location1,
                            Request.ItemsChoiceType8.StartTime, Request.ItemsChoiceType8.EndTime
                        },
                        Items =
                            new object[]
                        {
                            calendarSubject, 
                            new Request.Location
                            {
                            LocationUri=location
                            }, 
                            startTime.ToString("yyyyMMddTHHmmssZ"),
                            endTime.ToString("yyyyMMddTHHmmssZ")
                        }
                    },
                    Class = "Calendar"
                };
            }

            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId));

            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            syncResponse = this.Sync(syncRequest, true);
            responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);
            #endregion

            #region Call Sync command with FilterType of 4 to get the number of the filtered-out SoftDelete elements.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest, false);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The Item element in the Sync response should not be null.");

            Response.SyncCollectionsCollectionCommands commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            Site.Assert.IsNotNull(commands.SoftDelete, "The SoftDelete element in the commands should not be null.");
            int filteredOut = commands.SoftDelete.Length;
            #endregion

            #region Call Sync with FilterType of 0 to get all items in the Calendar folder.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 0);
            this.Sync(syncRequest, false);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest, false);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            Site.Assert.IsNotNull(commands.Add, "The Add element in the commands should not be null.");
            int total = commands.Add.Length;
            #endregion

            #region Call Sync command with FilterType of 4 to get the number of the filtered-in Add elements.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            this.Sync(syncRequest, false);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest, false);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            Site.Assert.IsNotNull(commands.Add, "The Add element in the commands should not be null.");
            int filterdIn = commands.Add.Length;

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3967
            Site.CaptureRequirementIfAreEqual<int>(
                total - filterdIn,
                filteredOut,
                3967,
                @"[In SoftDelete] The SoftDelete element contains any items that are filtered out of the Sync query due to being outside the FilterType date range [, or no longer specified as part of the SyncOptions instructions].");
            #endregion
        }
        public void MSASCMD_S19_TC50_Sync_Class()
        {
            Site.Assume.AreNotEqual<string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Class element is not supported in a Sync command response when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Add a new Note item
            string noteSubject = Common.GenerateResourceName(Site, "noteSubject");
            Request.Body noteBody = new Request.Body { Type = 1, Data = "Content of the body." };
            Request.Categories3 categories = new Request.Categories3 { Category = new string[] { "blue category" } };

            Request.SyncCollectionAdd noteData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    ItemsElementName =
                        new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.Subject1, 
                            Request.ItemsChoiceType8.Body,
                            Request.ItemsChoiceType8.Categories2, 
                            Request.ItemsChoiceType8.MessageClass
                        },
                    Items =
                        new object[]
                        {
                            noteSubject, 
                            noteBody, 
                            categories,
                            "IPM.StickyNote"
                        }
                },
                Class = "Calendar"
            };

            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.NotesCollectionId));

            SyncRequest syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.NotesCollectionId, noteData);
            SyncResponse syncResponse = this.Sync(syncRequest, false);

            Response.SyncCollectionsCollectionResponses responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            #endregion

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R941
            Site.CaptureRequirementIfAreEqual<string>(
                "Calendar",
                responses.Add[0].Class,
                941,
                @"[In Class(Sync)] As a child element of the Add element in the Sync command response, the Class element<20> identifies the class of the item being added to the collection.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R9945
            Site.CaptureRequirementIfAreEqual<string>(
                "Calendar",
                responses.Add[0].Class,
                9945,
                @"[In Class(Sync)] In all contexts of a Sync command request or Sync command response, the valid Class element value is Calendar.");
        }
        /// <summary>
        /// Create a default calendar object in the current login user calendar folder
        /// </summary>
        /// <param name="subject">The calendar subject</param>
        /// <param name="organizerEmailAddress">The organizer email address</param>
        /// <param name="attendeeEmailAddress">The attendee email address</param>
        /// <param name="calendarUID">The uid of calendar</param>
        /// <param name="timestamp">The DtStamp of calendar</param>
        /// <param name="startTime">The StartTime of calendar</param>
        /// <param name="endTime">The EndTime of calendar</param>
        /// <returns>Returns the Calendar instance</returns>
        protected Calendar CreateDefaultCalendar(
            string subject,
            string organizerEmailAddress,
            string attendeeEmailAddress,
            string calendarUID,
            DateTime?timestamp,
            DateTime?startTime,
            DateTime?endTime)
        {
            #region Configure the default calendar application data
            Request.SyncCollectionAdd syncAddCollection = new Request.SyncCollectionAdd();
            string clientId = TestSuiteHelper.GetClientId();
            syncAddCollection.ClientId        = clientId;
            syncAddCollection.ApplicationData = new Request.SyncCollectionAddApplicationData();

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

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("12.1"))
            {
                items.Add(true);
                itemsElementName.Add(Request.ItemsChoiceType8.ResponseRequested);
            }
            #region TIME/Subject/Location/UID
            items.Add(string.Format("{0:yyyyMMddTHHmmss}Z", null == startTime ? DateTime.UtcNow.AddDays(5) : startTime.Value));
            itemsElementName.Add(Request.ItemsChoiceType8.StartTime);

            items.Add(string.Format("{0:yyyyMMddTHHmmss}Z", null == endTime ? DateTime.UtcNow.AddDays(5).AddMinutes(30) : endTime.Value));
            itemsElementName.Add(Request.ItemsChoiceType8.EndTime);

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0") && !Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.1"))
            {
                items.Add(string.Format("{0:yyyyMMddTHHmmss}Z", null == timestamp ? DateTime.UtcNow.AddDays(5) : timestamp.Value));
                itemsElementName.Add(Request.ItemsChoiceType8.DtStamp);
            }

            items.Add(subject);
            itemsElementName.Add(Request.ItemsChoiceType8.Subject);

            items.Add(calendarUID ?? Guid.NewGuid().ToString());
            if (Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0") || Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.1"))
            {
                itemsElementName.Add(Request.ItemsChoiceType8.ClientUid);
            }
            else
            {
                itemsElementName.Add(Request.ItemsChoiceType8.UID);
            }

            if (Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0") || Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.1"))
            {
                Request.Location location = new Request.Location();
                location.DisplayName = "OFFICE";
                items.Add(location);
                itemsElementName.Add(Request.ItemsChoiceType8.Location);
            }
            else
            {
                items.Add("OFFICE");
                itemsElementName.Add(Request.ItemsChoiceType8.Location1);
            }
            #endregion

            #region Attendee/Organizer
            Request.AttendeesAttendee attendee = new Request.AttendeesAttendee
            {
                Email                 = attendeeEmailAddress,
                Name                  = new MailAddress(attendeeEmailAddress).User,
                AttendeeStatus        = 0x0,
                AttendeeTypeSpecified = true,
                AttendeeType          = 0x1
            };

            // 0x0 = Response unknown

            // 0x1 = Required
            items.Add(new Request.Attendees()
            {
                Attendee = new Request.AttendeesAttendee[] { attendee }
            });
            itemsElementName.Add(Request.ItemsChoiceType8.Attendees);

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0") && !Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.1"))
            {
                items.Add(organizerEmailAddress);
                itemsElementName.Add(Request.ItemsChoiceType8.OrganizerEmail);
                items.Add(new MailAddress(organizerEmailAddress).DisplayName);
                itemsElementName.Add(Request.ItemsChoiceType8.OrganizerName);
            }
            #endregion

            #region Sensitivity/BusyStatus/AllDayEvent
            // 0x0 == Normal
            items.Add((byte)0x0);
            itemsElementName.Add(Request.ItemsChoiceType8.Sensitivity);

            // 0x1 == Tentative
            items.Add((byte)0x1);
            itemsElementName.Add(Request.ItemsChoiceType8.BusyStatus);

            // 0x0 not an all-day event
            items.Add((byte)0x0);
            itemsElementName.Add(Request.ItemsChoiceType8.AllDayEvent);
            #endregion

            syncAddCollection.ApplicationData.Items            = items.ToArray();
            syncAddCollection.ApplicationData.ItemsElementName = itemsElementName.ToArray();
            #endregion

            #region Execute the Sync command to upload the calendar
            SyncStore   initSyncResponse      = this.InitializeSync(this.User1Information.CalendarCollectionId);
            SyncRequest uploadCalendarRequest = TestSuiteHelper.CreateSyncAddRequest(initSyncResponse.SyncKey, this.User1Information.CalendarCollectionId, syncAddCollection);
            this.EMAILAdapter.Sync(uploadCalendarRequest);
            #endregion

            #region Get the new added calendar item
            SyncStore getItemResponse = this.GetSyncResult(subject, this.User1Information.CalendarCollectionId, null);
            Sync      calendarItem    = TestSuiteHelper.GetSyncAddItem(getItemResponse, subject);
            Site.Assert.IsNotNull(calendarItem, "The item with subject {0} should be found in the folder {1}.", subject, FolderType.Calendar.ToString());
            #endregion

            return(calendarItem.Calendar);
        }
        public void MSASEMAIL_S01_TC27_CreateDraftEMailAndSend()
        {
            Site.Assume.AreEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Bcc element is supported when the ActiveSyncProtocolVersion is 16.0.");

            #region Add an email item with Sync command and send it.
            // Call FolderSync command to synchronize the collection hierarchy.
            FolderSyncRequest folderSyncRequest = Common.CreateFolderSyncRequest("0");
            FolderSyncResponse folderSyncResponse = this.EMAILAdapter.FolderSync(folderSyncRequest);

            string draftCollectionId = Common.GetDefaultFolderServerId(folderSyncResponse, FolderType.Drafts, this.Site);

            string subject = Common.GenerateResourceName(Site, "subject");
            string to = Common.GetMailAddress(this.User2Information.UserName, this.User1Information.UserDomain);
            Request.SyncCollectionAdd syncAddCollection = new Request.SyncCollectionAdd();
           
            string clientId = TestSuiteHelper.GetClientId();
            syncAddCollection.ClientId = clientId;
            syncAddCollection.ApplicationData = new Request.SyncCollectionAddApplicationData();
            List<object> items = new List<object>();
            List<Request.ItemsChoiceType8> itemsElementName = new List<Request.ItemsChoiceType8>();
            itemsElementName.Add(Request.ItemsChoiceType8.Subject3);
            items.Add(subject);
            itemsElementName.Add(Request.ItemsChoiceType8.To);
            items.Add(to);

            syncAddCollection.ApplicationData.Items = items.ToArray();
            syncAddCollection.ApplicationData.ItemsElementName = itemsElementName.ToArray();
            syncAddCollection.Class = "Email";
            syncAddCollection.Send = string.Empty;

            SyncStore initSyncResponse = this.InitializeSync(draftCollectionId);
            SyncRequest addEMailRequest = TestSuiteHelper.CreateSyncAddRequest(initSyncResponse.SyncKey, draftCollectionId, syncAddCollection);
            this.EMAILAdapter.Sync(addEMailRequest);
            #endregion

            #region Call Sync command wihtout including BodyPreference to synchronize the e-mail items with server.
            this.SwitchUser(this.User2Information, true);
            // Get the new added email item
            SyncStore syncChangeResult = this.GetSyncResult(subject, User2Information.InboxCollectionId, null);
            Sync item = TestSuiteHelper.GetSyncAddItem(syncChangeResult, subject);
            
            this.Site.CaptureRequirementIfAreEqual<bool>(
                false,
                item.Email.IsDraft.Value,
                1279,
                @"[In IsDraft] The value 0 (FALSE) indicates that the email is not a draft.");
            #endregion
        }
        public void MSASCMD_S19_TC12_Sync_Calendar_FilterType()
        {
            Site.Assume.AreNotEqual<string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Class element is not supported in a Sync command response when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "Recurrences cannot be added in protocol version 16.0");
            #region Add a new calendar
            string calendarSubject = Common.GenerateResourceName(Site, "calendarSubject");
            DateTime startTime = DateTime.Now.AddDays(1.0);
            DateTime endTime = startTime.AddMinutes(10.0);

            Request.SyncCollectionAdd calendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData =
                    new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                            {
                                Request.ItemsChoiceType8.Subject, 
                                Request.ItemsChoiceType8.StartTime, 
                                Request.ItemsChoiceType8.EndTime
                            },
                        Items =
                            new object[]
                            {
                                calendarSubject, 
                                startTime.ToString("yyyyMMddTHHmmssZ"),
                                endTime.ToString("yyyyMMddTHHmmssZ")
                             }
                    },
                Class = "Calendar"
            };

            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId));

            SyncRequest syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            SyncResponse syncResponse = this.Sync(syncRequest);

            Response.SyncCollectionsCollectionResponses responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);
            #endregion

            #region Call Sync command to verify server supports to filter calendar when FilterType set to 0.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 0);
            this.Sync(syncRequest);

            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3044
            Site.CaptureRequirementIfAreEqual<uint>(
                1,
                Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)),
                3044,
                @"[In FilterType(Sync)] Yes. [Applies to calendar, if FilterType is 0, Status element value is 1.]");

            Response.SyncCollectionsCollectionCommands commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            int itemsWithFilter = commands.Add.Length;

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            int itemsWithoutFilter = commands.Add.Length;

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3076
            Site.CaptureRequirementIfAreEqual<int>(
                itemsWithFilter,
                itemsWithoutFilter,
                3076,
                @"[In FilterType(Sync)] If the FilterType element is omitted, all objects are sent from the server without regard for their age.");
            #endregion

            #region Call Sync command to verify server does not support to filter calendar when FilterType set to 1.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 1);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3045
            Site.CaptureRequirementIfAreNotEqual<string>(
                "1",
                syncResponse.ResponseData.Status,
                3045,
                @"[In FilterType(Sync)] No, [Applies to calendar, if FilterType is 1, status is not 1.]");

            #endregion

            #region Call Sync command to verify server does not support to filter calendar when FilterType set to 2.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 2);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3046
            Site.CaptureRequirementIfAreNotEqual<string>(
                "1",
                syncResponse.ResponseData.Status,
                3046,
                @"[In FilterType(Sync)] No, [Applies to calendar, if FilterType is 2, status is not 1.]");

            #endregion

            #region Call Sync command to verify server does not support to filter calendar when FilterType set to 3.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 3);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3047
            Site.CaptureRequirementIfAreNotEqual<string>(
                "1",
                syncResponse.ResponseData.Status,
                3047,
                @"[In FilterType(Sync)] No, [Applies to calendar, if FilterType is 3, status is not 1.]");

            #endregion

            #region Call Sync command to verify server supports to filter calendar when FilterType set to 4.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3048
            Site.CaptureRequirementIfAreEqual<uint>(
                1,
                Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)),
                3048,
                @"[In FilterType(Sync)] Yes, [Applies to calendar, if FilterType is 4, Status element value is 1.]");

            // Create a future calendar
            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            calendarSubject = Common.GenerateResourceName(this.Site, "canlendarSubject");
            startTime = DateTime.Now.AddDays(15.0);
            endTime = startTime.AddMinutes(10.0);

            calendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData =
                    new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                            {
                                Request.ItemsChoiceType8.Subject,
                                Request.ItemsChoiceType8.StartTime, 
                                Request.ItemsChoiceType8.EndTime
                            },
                        Items =
                            new object[]
                            {
                                calendarSubject, 
                                startTime.ToString("yyyyMMddTHHmmssZ"),
                                endTime.ToString("yyyyMMddTHHmmssZ")
                            }
                    },
                Class = "Calendar"
            };

            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");
            responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            bool isVerifyR3065 = !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", calendarSubject));

            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            isVerifyR3065 = isVerifyR3065 && !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", calendarSubject));

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3065
            Site.CaptureRequirementIfIsTrue(
                isVerifyR3065,
                3065,
                @"[In FilterType(Sync)] Calendar items that are in the future [or that have recurrence but no end date] are sent to the client regardless of the FilterType element value.");

            // create a recurrence calendar without EndTime
            Request.Recurrence recurrence = new Request.Recurrence
            {
                Type = 1,
                OccurrencesSpecified = false,
                DayOfWeek = 2,
                DayOfWeekSpecified = true,
                IsLeapMonthSpecified = false
            };

            string recurrenceCalendarSubject = Common.GenerateResourceName(Site, "recurrenceCanlendarSubject");

            Request.SyncCollectionAdd recurrenceCalendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData =
                    new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[] { Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Recurrence, Request.ItemsChoiceType8.UID },
                        Items = new object[] { recurrenceCalendarSubject, recurrence, Guid.NewGuid().ToString() }
                    },
                Class = "Calendar"
            };

            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, recurrenceCalendarData);
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");
            responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, recurrenceCalendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            bool isVerifyR5878 = !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", recurrenceCalendarSubject));

            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            isVerifyR5878 = isVerifyR5878 && !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", recurrenceCalendarSubject));

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R5878
            Site.CaptureRequirementIfIsTrue(
                isVerifyR5878,
                5878,
                @"[In FilterType(Sync)] Calendar items [that are in the future or] that have recurrence but no end date are sent to the client regardless of the FilterType element value.");
            #endregion

            #region Call Sync command to verify server supports to filter calendar when FilterType set to 5.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 5);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3049
            Site.CaptureRequirementIfAreEqual<uint>(
                1,
                Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)),
                3049,
                @"[In FilterType(Sync)] Yes. [Applies to calendar, if FilterType is 5, Status element value is 1.]");
            #endregion

            #region Call Sync command to verify server supports to filter calendar when FilterType set to 6.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 6);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3050
            Site.CaptureRequirementIfAreEqual<uint>(
                1,
                Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)),
                3050,
                @"[In FilterType(Sync)] Yes. [Applies to calendar, if FilterType is 6, Status element value is 1.]");
            #endregion

            #region Call Sync command to verify server supports to filter calendar when FilterType set to 7.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 7);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3051
            Site.CaptureRequirementIfAreEqual<uint>(
                1,
                Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)),
                3051,
                @"[In FilterType(Sync)] Yes. [Applies to calendar, if FilterType is 7, Status element value is 1.]");

            commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            int original = commands.Add.Length;

            // Create a overdue calendar
            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            calendarSubject = Common.GenerateResourceName(this.Site, "canlendarSubject");
            startTime = DateTime.Now.AddMonths(-7);
            endTime = startTime.AddHours(1.0);

            calendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData =
                    new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                            {
                                Request.ItemsChoiceType8.Subject,
                                   Request.ItemsChoiceType8.StartTime,
                                   Request.ItemsChoiceType8.EndTime,
                            },
                        Items =
                            new object[]
                            {
                                calendarSubject, 
                                startTime.ToString("yyyyMMddTHHmmssZ"),
                                endTime.ToString("yyyyMMddTHHmmssZ")
                            }
                    },
                Class = "Calendar"
            };

            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            syncResponse = this.Sync(syncRequest);
            responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);

            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 7);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");
            commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            int current = commands.Add.Length;

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R2987
            Site.CaptureRequirementIfAreEqual<int>(
                original,
                current,
                2987,
                @"[In FilterType(Sync)] If a FilterType element is specified, the server sends only objects that are dated within the specified time window.");
            #endregion

            #region Call Sync command to verify server does not support to filter calendar when FilterType set to 8.
            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 8);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3052
            Site.CaptureRequirementIfAreNotEqual<string>(
                "1",
                syncResponse.ResponseData.Status,
                3052,
                @"[In FilterType(Sync)] No, [The result of including a FilterType element value of 8 for a Calendar item is undefined.]");
            #endregion
        }
        public void MSASCMD_S19_TC51_Sync_Change_Exceptions()
        {
            Site.Assume.AreNotEqual<string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Class element is not supported in a Sync command response when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "Recurrences cannot be added in protocol version 16.0");

            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId));

            #region Call Sync Add operation to add a new recurrence calendar.
            string recurrenceCalendarSubject = Common.GenerateResourceName(Site, "calendarSubject");
            string location = Common.GenerateResourceName(Site, "Room");
            DateTime currentDate = DateTime.Now.AddDays(1);
            DateTime startTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 10, 0, 0);
            DateTime endTime = startTime.AddHours(10);

            Request.ExceptionsException exception = new Request.ExceptionsException();
            exception.ExceptionStartTime = startTime.AddDays(2).ToString("yyyyMMddTHHmmssZ");
            Request.Exceptions exceptions = new Request.Exceptions() { Exception = new Request.ExceptionsException[] { exception } };

            Request.Recurrence recurrence = new Request.Recurrence
            {
                Type = 0
            };

            Request.SyncCollectionAdd recurrenceCalendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData =
                    new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[] 
                            { 
                                Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Location,
                                Request.ItemsChoiceType8.StartTime, Request.ItemsChoiceType8.EndTime,
                                Request.ItemsChoiceType8.Recurrence, Request.ItemsChoiceType8.Exceptions,
                                Request.ItemsChoiceType8.UID
                            },
                        Items =
                        new object[] 
                        { 
                            recurrenceCalendarSubject, location, 
                            startTime.ToString("yyyyMMddTHHmmssZ"),
                            endTime.ToString("yyyyMMddTHHmmssZ"),
                            recurrence, exceptions, Guid.NewGuid().ToString()
                        }
                    },
                Class = "Calendar"
            };

            SyncRequest syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, recurrenceCalendarData);
            SyncResponse syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");
            Response.SyncCollectionsCollectionResponses responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, recurrenceCalendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            string serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", recurrenceCalendarSubject);
            Site.Assert.IsNotNull(serverId, "The recurrence calendar should be found.");
            #endregion

            #region Change the subject of the added recurrence calendar.
            string updatedCalendarSubject = Common.GenerateResourceName(Site, "updatedCalendarSubject");

            Request.SyncCollectionChangeApplicationData changeCalednarData = new Request.SyncCollectionChangeApplicationData();
            changeCalednarData.ItemsElementName = new Request.ItemsChoiceType7[] { Request.ItemsChoiceType7.Subject, Request.ItemsChoiceType7.Recurrence };
            changeCalednarData.Items = new object[] { updatedCalendarSubject, recurrence };

            Request.SyncCollectionChange appDataChange = new Request.SyncCollectionChange
            {
                ApplicationData = changeCalednarData,
                ServerId = serverId
            };

            syncRequest = CreateSyncChangeRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, appDataChange);
            syncResponse = this.Sync(syncRequest);
            Site.Assert.AreEqual<uint>(1, Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)), "The FileAs of the contact should be updated successfully.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, recurrenceCalendarSubject);
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, updatedCalendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", updatedCalendarSubject);
            Site.Assert.IsNotNull(serverId, "The recurrence calendar should be found.");

            Response.SyncCollectionsCollectionCommands commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            Site.Assert.IsNotNull(commands.Add, "The Add element should not be null.");

            foreach (Response.SyncCollectionsCollectionCommandsAdd item in commands.Add)
            {
                if (item.ServerId == serverId)
                {
                    for (int i = 0; i < item.ApplicationData.ItemsElementName.Length; i++)
                    {
                        if (item.ApplicationData.ItemsElementName[i] == Response.ItemsChoiceType8.Exceptions)
                        {
                            Response.Exceptions currentExceptions = item.ApplicationData.Items[i] as Response.Exceptions;
                            Site.Assert.IsNotNull(currentExceptions, "The Exceptions element should exist.");

                            Response.ExceptionsException currentException = currentExceptions.Exception[0];

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

                            // Verify MS-ASCMD requirement: MS-ASCMD_R877
                            Site.CaptureRequirementIfAreEqual<string>(
                                exception.ExceptionStartTime.ToString(),
                                currentException.ExceptionStartTime.ToString(),
                                877,
                                @"[In Change] If a calendar:Exception ([MS-ASCAL] section 2.2.2.19) node within the calendar:Exceptions node is not present, that particular exception will remain unchanged.");

                            break;
                        }
                    }

                    break;
                }
            }
            #endregion

            #region Change the subject of the added recurrence calendar again.
            string allNewCalendarSubject = Common.GenerateResourceName(Site, "updatedCalendarSubject");

            changeCalednarData.ItemsElementName = new Request.ItemsChoiceType7[] { Request.ItemsChoiceType7.Subject, Request.ItemsChoiceType7.Recurrence, Request.ItemsChoiceType7.Exceptions, Request.ItemsChoiceType7.UID };
            changeCalednarData.Items = new object[] { allNewCalendarSubject, recurrence, null, Guid.NewGuid().ToString() };

            appDataChange = new Request.SyncCollectionChange
            {
                ApplicationData = changeCalednarData,
                ServerId = serverId
            };

            syncRequest = CreateSyncChangeRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, appDataChange);
            syncResponse = this.Sync(syncRequest);
            Site.Assert.AreEqual<uint>(1, Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)), "The FileAs of the contact should be updated successfully.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, updatedCalendarSubject);
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, allNewCalendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", allNewCalendarSubject);
            Site.Assert.IsNotNull(serverId, "The recurrence calendar should be found.");

            commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            Site.Assert.IsNotNull(commands.Add, "The Add element should not be null.");

            foreach (Response.SyncCollectionsCollectionCommandsAdd item in commands.Add)
            {
                if (item.ServerId == serverId)
                {
                    for (int i = 0; i < item.ApplicationData.ItemsElementName.Length; i++)
                    {
                        if (item.ApplicationData.ItemsElementName[i] == Response.ItemsChoiceType8.Exceptions)
                        {
                            Response.Exceptions currentExceptions = item.ApplicationData.Items[i] as Response.Exceptions;
                            Site.Assert.IsNotNull(currentExceptions, "The Exceptions element should exist.");

                            Response.ExceptionsException currentException = currentExceptions.Exception[0];

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

                            // Verify MS-ASCMD requirement: MS-ASCMD_R876
                            Site.CaptureRequirementIfAreEqual<string>(
                                exception.ExceptionStartTime.ToString(),
                                currentException.ExceptionStartTime.ToString(),
                                876,
                                @"[In Change] [Certain in-schema properties remain untouched in the following three cases:] If a calendar:Exceptions ([MS-ASCAL] section 2.2.2.20) node is not specified, the properties for that calendar:Exceptions node will remain unchanged.");

                            break;
                        }
                    }

                    break;
                }
            }
            #endregion
        }
        /// <summary>
        /// Generate a Sync Add command with body element.
        /// </summary>
        /// <returns>Returns a command list instance.</returns>
        private static object[] CreateSyncAddCommands()
        {
            Request.Body addBody = new Request.Body { Type = 1, Data = "Test sync add" };

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

            items.Add(addBody);
            itemsElementName.Add(Request.ItemsChoiceType8.Body);

            Request.SyncCollectionAddApplicationData applicationData = new Request.SyncCollectionAddApplicationData
            {
                Items = items.ToArray(),
                ItemsElementName = itemsElementName.ToArray()
            };

            Request.SyncCollectionAdd syncAdd = new Request.SyncCollectionAdd
            {
                ClientId = Guid.NewGuid().ToString("N"),
                ApplicationData = applicationData
            };

            List<object> commandList = new List<object> { syncAdd };
            return commandList.ToArray();
        }
        public void MSASEMAIL_S01_TC26_CreateDraftEMail()
        {
            Site.Assume.AreEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Bcc element is supported when the ActiveSyncProtocolVersion is 16.0.");

            #region Add an email item with Sync command.
            // Call FolderSync command to synchronize the collection hierarchy.
            FolderSyncRequest folderSyncRequest = Common.CreateFolderSyncRequest("0");
            FolderSyncResponse folderSyncResponse = this.EMAILAdapter.FolderSync(folderSyncRequest);

            string draftCollectionId = Common.GetDefaultFolderServerId(folderSyncResponse, FolderType.Drafts, this.Site);

            string subject = Common.GenerateResourceName(Site, "subject");
            string to = Common.GetMailAddress(this.User1Information.UserName, this.User1Information.UserDomain);
            string bcc = Common.GetMailAddress(this.User2Information.UserName, this.User2Information.UserDomain);
            Request.SyncCollectionAdd syncAddCollection = new Request.SyncCollectionAdd();
            string clientId = TestSuiteHelper.GetClientId();
            syncAddCollection.ClientId = clientId;
            syncAddCollection.ApplicationData = new Request.SyncCollectionAddApplicationData();
            List<object> items = new List<object>();
            List<Request.ItemsChoiceType8> itemsElementName = new List<Request.ItemsChoiceType8>();
            itemsElementName.Add(Request.ItemsChoiceType8.Subject3);
            items.Add(subject);
            itemsElementName.Add(Request.ItemsChoiceType8.To);
            items.Add(to);
            itemsElementName.Add(Request.ItemsChoiceType8.Bcc);
            items.Add(bcc);
 
            syncAddCollection.ApplicationData.Items = items.ToArray();
            syncAddCollection.ApplicationData.ItemsElementName = itemsElementName.ToArray();
            syncAddCollection.Class = "Email";

            SyncStore initSyncResponse = this.InitializeSync(draftCollectionId);
            SyncRequest addEMailRequest = TestSuiteHelper.CreateSyncAddRequest(initSyncResponse.SyncKey, draftCollectionId, syncAddCollection);
            this.EMAILAdapter.Sync(addEMailRequest);
            #endregion

            #region Call Sync command wihtout including BodyPreference to synchronize the e-mail items with server.
            // Get the new added email item
            SyncStore syncChangeResult = this.GetSyncResult(subject, draftCollectionId, null);
            Sync item = TestSuiteHelper.GetSyncAddItem(syncChangeResult, subject);

            this.Site.CaptureRequirementIfAreEqual<bool>(
                true,
                item.Email.IsDraft.Value,
                1278,
                @"[In IsDraft] The value 1 (TRUE) indicates that the email is a draft.");

            this.Site.CaptureRequirementIfIsNotNull(
                item.Email.IsDraft,
                1273,
                @"[In IsDraft] This element [email2:IsDraft] is present in a Sync command response ([MS-ASCMD] section 2.2.2.20)[, a Search command response ([MS-ASCMD] section 2.2.2.15), or an ItemOperations command response ([MS-ASCMD] section 2.2.2.9)].");
            
            this.Site.CaptureRequirementIfIsTrue(
                !string.IsNullOrEmpty(item.Email.ConversationId),
                1184,
                @"[In ConversationId] In protocol version 16.0: When the client adds a new draft item, the server response will contain the email2:ConversationId element for that draft item.");

            this.Site.CaptureRequirementIfIsTrue(
                !string.IsNullOrEmpty(item.Email.ConversationIndex),
                1190,
                @"[In ConversationIndex] In protocol version 16.0: When the client adds a new draft item, the server response will include the email2:ConversationIndex element for that draft item.");
            #endregion

            #region Call Search command to Search email from server.
            // Search email from server
            SearchRequest searchRequest = TestSuiteHelper.CreateSearchRequest(subject, draftCollectionId);
            SearchResponse searchResponse = this.EMAILAdapter.Search(searchRequest);

            SearchStore searchStore = Common.LoadSearchResponse(searchResponse);
            Search searchItem = null;
            if (searchStore.Results.Count != 0)
            {
                foreach (Search resultItem in searchStore.Results)
                {
                    if (resultItem.Email.Subject == subject)
                    {
                        searchItem = resultItem;
                        break;
                    }
                }
            }

            Site.Assert.IsNotNull(searchItem, "The email message with subject {0} should be found.", subject);

            this.Site.CaptureRequirementIfIsNotNull(
                searchItem.Email.IsDraft,
                1274,
                @"[In IsDraft] This element [email2:IsDraft] is present in [a Sync command response ([MS-ASCMD] section 2.2.2.20),] a Search command response ([MS-ASCMD] section 2.2.2.15)[, or an ItemOperations command response ([MS-ASCMD] section 2.2.2.9)].");
            #endregion

            #region Call ItemOperations command without including BodyPreference element to fetch all the information about the e-mail
            ItemOperationsRequest itemOperationRequest = TestSuiteHelper.CreateItemOperationsFetchRequest(draftCollectionId, item.ServerId, null, null, null);
            ItemOperationsStore itemOperationResult = this.EMAILAdapter.ItemOperations(itemOperationRequest);
            ItemOperations itemOperationsItem = TestSuiteHelper.GetItemOperationsItem(itemOperationResult, subject);
     
            this.Site.CaptureRequirementIfIsNotNull(
                itemOperationsItem.Email.IsDraft,
                1275,
                @"[In IsDraft] This element [email2:IsDraft] is present in [a Sync command response ([MS-ASCMD] section 2.2.2.20), a Search command response ([MS-ASCMD] section 2.2.2.15), or] an ItemOperations command response ([MS-ASCMD] section 2.2.2.9).");
            #endregion
        }
 /// <summary>
 /// Create an add Email request.
 /// </summary>
 /// <param name="to">The value of the To element.</param>
 /// <param name="clientId">The value of the ClientId element.</param>
 /// <returns>The add Email request.</returns>
 private static Request.SyncCollectionAdd CreateAddEmailCommand(string to, string clientId)
 {
     Request.SyncCollectionAdd appData = new Request.SyncCollectionAdd
     {
         ClientId = clientId,
         ApplicationData = new Request.SyncCollectionAddApplicationData
         {
             ItemsElementName = new Request.ItemsChoiceType8[] { Request.ItemsChoiceType8.To },
             Items = new object[] { to }
         },
         Class = "Email"
     };
     return appData;
 }
        public void MSASCMD_S07_TC05_GetItemEstimate_Calendar_FilterType()
        {
            Site.Assume.AreNotEqual<string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The Options element is not supported when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "Recurrences cannot be added in protocol version 16.0");

            #region Add a new calendar
            string calendarSubject = Common.GenerateResourceName(Site, "calendarSubject");
            DateTime startTime = DateTime.Now.AddDays(1.0);
            DateTime endTime = startTime.AddMinutes(10.0);

            Request.SyncCollectionAdd calendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    ItemsElementName =
                        new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.Subject, 
                            Request.ItemsChoiceType8.StartTime, 
                            Request.ItemsChoiceType8.EndTime                 
                        },
                    Items =
                        new object[]
                        {
                            calendarSubject, 
                            startTime.ToString("yyyyMMddTHHmmssZ"),
                            endTime.ToString("yyyyMMddTHHmmssZ")
                        }
                },
                Class = "Calendar"
            };

            this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId));

            SyncRequest syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            SyncResponse syncResponse = this.Sync(syncRequest);

            Response.SyncCollectionsCollectionResponses responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);
            #endregion

            #region Call GetItemEstimate with FilterType setting to 0 to get estimate number of all items in Calendar folder.
            GetItemEstimateResponse getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)0);
            Site.Assert.IsNotNull(getItemEstimateResponse.ResponseData.Response, "The response of GetItemEstimate command should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3008
            Site.CaptureRequirementIfAreEqual<int>(
                1,
                int.Parse(getItemEstimateResponse.ResponseData.Response[0].Status),
                3008,
                @"[In FilterType(GetItemEstimate)] Yes. [Applies to calendar, if FilterType is 0, Status element value is 1.]");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 1 to get estimate number of items within 1 day in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)1);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3009
            Site.CaptureRequirementIfAreEqual<int>(
                110,
                int.Parse(getItemEstimateResponse.ResponseData.Status),
                3009,
                @"[In FilterType(GetItemEstimate)] No, [Applies to calendar, if FilterType is 1,] Status element (section 2.2.3.162.6) value is 110.");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 2 to get estimate number of items within 3 days in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)2);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3010
            Site.CaptureRequirementIfAreEqual<int>(
                110,
                int.Parse(getItemEstimateResponse.ResponseData.Status),
                3010,
                @"[In FilterType(GetItemEstimate)] No, [Applies to calendar, if FilterType is 2,] Status element value is 110.");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 3 to get estimate number of items within 1 week in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)3);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3011
            Site.CaptureRequirementIfAreEqual<int>(
                110,
                int.Parse(getItemEstimateResponse.ResponseData.Status),
                3011,
                @"[In FilterType(GetItemEstimate)] No, [Applies to calendar, if FilterType is 3,] Status element value is 110.");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 4 to get estimate number of items within 2 weeks in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)4);
            Site.Assert.IsNotNull(getItemEstimateResponse.ResponseData.Response, "The response of GetItemEstimate command should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3012
            Site.CaptureRequirementIfAreEqual<int>(
                1,
                int.Parse(getItemEstimateResponse.ResponseData.Response[0].Status),
                3012,
                @"[In FilterType(GetItemEstimate)] Yes. [Applies to calendar, if FilterType is 4, Status element value 1]");
            #endregion

            #region Create a future calendar
            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            calendarSubject = Common.GenerateResourceName(this.Site, "canlendarSubject");
            startTime = DateTime.Now.AddDays(15.0);
            endTime = startTime.AddMinutes(10.0);

            calendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    ItemsElementName = new Request.ItemsChoiceType8[]
                    {
                        Request.ItemsChoiceType8.Subject,
                        Request.ItemsChoiceType8.StartTime,
                        Request.ItemsChoiceType8.EndTime,
                    },
                    Items = new object[]
                    {
                        calendarSubject,
                        startTime.ToString("yyyyMMddTHHmmssZ"),
                        endTime.ToString("yyyyMMddTHHmmssZ"),
                    }
                },
                Class = "Calendar"
            };

            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");
            responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, calendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            bool isVerifyR2971 = !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", calendarSubject));

            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            this.Sync(syncRequest);

            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            isVerifyR2971 = isVerifyR2971 && !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", calendarSubject));

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R2971
            Site.CaptureRequirementIfIsTrue(
                isVerifyR2971,
                2971,
                @"[In FilterType(GetItemEstimate)] Calendar items that are in the future [or that have recurrence, but no end date], are sent to the client regardless of the airsync:FilterType element value.");
            #endregion

            #region Create a recurrence calendar without EndTime
            string recurrenceCalendarSubject = Common.GenerateResourceName(Site, "recurrenceCanlendarSubject");

            Request.SyncCollectionAdd recurrenceCalendarData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    ItemsElementName = new Request.ItemsChoiceType8[] { Request.ItemsChoiceType8.Subject, Request.ItemsChoiceType8.Recurrence },
                    Items = new object[]
                    {
                        recurrenceCalendarSubject,
                        new Request.Recurrence
                        {
                            Type = 1,
                            OccurrencesSpecified = false,
                            DayOfWeek = 2,
                            DayOfWeekSpecified = true,
                            IsLeapMonthSpecified = false
                        },
                    }
                },
                Class = "Calendar"
            };

            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, recurrenceCalendarData);
            syncResponse = this.Sync(syncRequest);
            responses = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.AreEqual<int>(1, int.Parse(responses.Add[0].Status), "The calendar should be added successfully.");
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.CalendarCollectionId, recurrenceCalendarSubject);

            syncResponse = this.SyncChanges(this.User1Information.CalendarCollectionId);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            bool isVerifyR5877 = !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", recurrenceCalendarSubject));

            syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.CalendarCollectionId, 4);
            this.Sync(syncRequest);

            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            isVerifyR5877 = isVerifyR5877 && !string.IsNullOrEmpty(TestSuiteBase.FindServerId(syncResponse, "Subject", recurrenceCalendarSubject));

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R5877
            Site.CaptureRequirementIfIsTrue(
                isVerifyR5877,
                5877,
                @"[In FilterType(GetItemEstimate)] Calendar items [that are in the future or] that have recurrence, but no end date, are sent to the client regardless of the airsync:FilterType element value.");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 5 to get estimate number of items within 1 month in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)5);
            Site.Assert.IsNotNull(getItemEstimateResponse.ResponseData.Response, "The response of GetItemEstimate command should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3013
            Site.CaptureRequirementIfAreEqual<int>(
                1,
                int.Parse(getItemEstimateResponse.ResponseData.Response[0].Status),
                3013,
                @"[In FilterType(GetItemEstimate)] Yes. [Applies to calendar, if FilterType is 5, Status element value is 1.]");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 6 to get estimate number of items within 3 months in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)6);
            Site.Assert.IsNotNull(getItemEstimateResponse.ResponseData.Response, "The response of GetItemEstimate command should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3014
            Site.CaptureRequirementIfAreEqual<int>(
                1,
                int.Parse(getItemEstimateResponse.ResponseData.Response[0].Status),
                3014,
                @"[In FilterType(GetItemEstimate)] Yes. [Applies to calendar, if FilterType is 6, Status element value 1]");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 7 to get estimate number of items within 6 months in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)7);
            Site.Assert.IsNotNull(getItemEstimateResponse.ResponseData.Response, "The response of GetItemEstimate command should not be null.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3015
            Site.CaptureRequirementIfAreEqual<int>(
                1,
                int.Parse(getItemEstimateResponse.ResponseData.Response[0].Status),
                3015,
                @"[In FilterType(GetItemEstimate)] Yes. [Applies to calendar, if FilterType is 7, Status element value is 1.]");
            #endregion

            #region Call GetItemEstimate with FilterType setting to 8 to get estimate number of incomplete tasks in Calendar folder.
            getItemEstimateResponse = this.GetItemEstimateWithFilterType(this.User1Information.CalendarCollectionId, (byte)8);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R3016
            Site.CaptureRequirementIfAreEqual<int>(
                110,
                int.Parse(getItemEstimateResponse.ResponseData.Status),
                3016,
                @"[In FilterType(GetItemEstimate)] No, [Applies to calendar, if FilterType is 8,] Status element value is 110.");
            #endregion
        }
        /// <summary>
        /// Create one sample calendar object.
        /// </summary>
        /// <param name="subject">Meeting subject.</param>
        /// <param name="attendeeEmailAddress">Meeting attendee email address.</param>
        /// <param name="createdCalendar">The calendar object</param>
        /// <returns>One sample calendar object.</returns> 
        protected Calendar CreateCalendar(string subject, string attendeeEmailAddress, Calendar createdCalendar)
        {
            Dictionary<Request.ItemsChoiceType8, object> elementsToValueMap = this.SetMeetingProperties(subject, attendeeEmailAddress, this.Site);
            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("12.1"))
            {
                elementsToValueMap.Add(Request.ItemsChoiceType8.ResponseRequested, true);
            }

            if (createdCalendar != null)
            {
                if (createdCalendar.DtStamp != null)
                {
                    elementsToValueMap.Add(Request.ItemsChoiceType8.DtStamp, DateTime.Parse(createdCalendar.DtStamp.ToString()).ToString("yyyyMMddTHHmmssZ"));
                }
                if (createdCalendar.StartTime != null)
                {
                    elementsToValueMap.Add(Request.ItemsChoiceType8.StartTime, DateTime.Parse(createdCalendar.StartTime.ToString()).ToString("yyyyMMddTHHmmssZ"));
                }
                if (createdCalendar.EndTime != null)
                {
                    elementsToValueMap.Add(Request.ItemsChoiceType8.EndTime, DateTime.Parse(createdCalendar.EndTime.ToString()).ToString("yyyyMMddTHHmmssZ"));
                }
            }
            // Call Sync command with Add element to add a meeting
            Request.SyncCollectionAddApplicationData applicationData = new Request.SyncCollectionAddApplicationData
            {
                Items = new object[elementsToValueMap.Count],
                ItemsElementName = new Request.ItemsChoiceType8[elementsToValueMap.Count]
            };

            if (elementsToValueMap.Count > 0)
            {
                elementsToValueMap.Values.CopyTo(applicationData.Items, 0);
                elementsToValueMap.Keys.CopyTo(applicationData.ItemsElementName, 0);
            }

            Request.SyncCollectionAdd calendarData = new Request.SyncCollectionAdd()
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = applicationData,
            };
            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            SyncRequest syncAddRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, calendarData);
            SyncResponse syncResponse = this.Sync(syncAddRequest);

            SyncStore getChangeResult = this.GetSyncResult(subject, this.User1Information.CalendarCollectionId, null);
            Sync calendar = this.GetSyncAddItem(getChangeResult, subject);

            return calendar.Calendar;
        }
        /// <summary>
        /// Create a request to add a contact with job title.
        /// </summary>
        /// <param name="firstName">The first name of the contact.</param>
        /// <param name="middleName">The middle name of the contact.</param>
        /// <param name="lastName">The last name of the contact.</param>
        /// <param name="fileAs">The filing string for the contact.</param>
        /// <param name="jobTitle">The job title of the contact.</param>
        /// <returns>The request to add a contact.</returns>
        protected Request.SyncCollectionAdd CreateAddContactCommand(string firstName, string middleName, string lastName, string fileAs, string jobTitle)
        {
            Request.SyncCollectionAdd appData = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = new Request.SyncCollectionAddApplicationData()
            };

            firstName = Common.GenerateResourceName(this.Site, firstName);
            middleName = Common.GenerateResourceName(this.Site, middleName);
            lastName = Common.GenerateResourceName(this.Site, lastName);

            if (string.IsNullOrEmpty(jobTitle))
            {
                appData.ApplicationData.ItemsElementName = new Request.ItemsChoiceType8[] { Request.ItemsChoiceType8.FileAs, Request.ItemsChoiceType8.FirstName, Request.ItemsChoiceType8.MiddleName, Request.ItemsChoiceType8.LastName };
                appData.ApplicationData.Items = new object[] { fileAs, firstName, middleName, lastName };
            }
            else
            {
                jobTitle = Common.GenerateResourceName(this.Site, jobTitle);
                appData.ApplicationData.ItemsElementName = new Request.ItemsChoiceType8[] { Request.ItemsChoiceType8.FileAs, Request.ItemsChoiceType8.FirstName, Request.ItemsChoiceType8.MiddleName, Request.ItemsChoiceType8.LastName, Request.ItemsChoiceType8.JobTitle };
                appData.ApplicationData.Items = new object[] { fileAs, firstName, middleName, lastName, jobTitle };
            }

            if ("12.1" != Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site))
            {
                appData.Class = "Contacts";
            }

            return appData;
        }
        /// <summary>
        /// Add a meeting or appointment to server
        /// </summary>
        /// <param name="calendar">the calendar item</param>
        private void SyncAddCalendar(Calendar calendar)
        {
            Request.SyncCollectionAddApplicationData applicationData = SetApplicationDataFromCalendar(calendar);

            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            Request.SyncCollectionAdd addCalendar = new Request.SyncCollectionAdd
            {
                ClientId = TestSuiteBase.ClientId,
                ApplicationData = applicationData
            };

            SyncRequest syncAddCalendarRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, addCalendar);
            SyncResponse syncAddCalendarResponse = this.CMDAdapter.Sync(syncAddCalendarRequest);

            // Get data from response
            Response.SyncCollections syncCollections = (Response.SyncCollections)syncAddCalendarResponse.ResponseData.Item;
            Response.SyncCollectionsCollectionResponses syncResponses = null;
            for (int index = 0; index < syncCollections.Collection[0].ItemsElementName.Length; index++)
            {
                if (syncCollections.Collection[0].ItemsElementName[index] == Response.ItemsChoiceType10.Responses)
                {
                    syncResponses = (Response.SyncCollectionsCollectionResponses)syncCollections.Collection[0].Items[index];
                    break;
                }
            }

            Site.Assert.AreEqual(1, syncResponses.Add.Length, "User only upload one calendar item");
            int statusCode = int.Parse(syncResponses.Add[0].Status);
            Site.Assert.AreEqual(1, statusCode, "If upload calendar item successful, server should return status 1");
        }
        /// <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;
        }
        /// <summary>
        /// Create a SyncCollectionAdd instance for adding a contact.
        /// </summary>
        /// <param name="fileAs">The FileAs element for the contact.</param>
        /// <param name="data">The body data of contact.</param>
        /// <param name="truncated">The Truncated element for the contact.</param>
        /// <returns>Return a SyncCollectionAdd instance.</returns>
        private static Request.SyncCollectionAdd CreateSyncAddContact(string fileAs, string data, bool? truncated)
        {
            Request.SyncCollectionAdd syncAdd = new Request.SyncCollectionAdd { ClientId = Guid.NewGuid().ToString("N") };

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

            items.Add(fileAs);
            itemsElementName.Add(Request.ItemsChoiceType8.FileAs);

            Request.Body addBody = new Request.Body { Type = 1, Data = data };

            if (truncated != null)
            {
                addBody.TruncatedSpecified = true;
                addBody.Truncated = (bool)truncated;
            }

            items.Add(addBody);
            itemsElementName.Add(Request.ItemsChoiceType8.Body);

            Request.SyncCollectionAddApplicationData applicationData = new Request.SyncCollectionAddApplicationData
            {
                Items = items.ToArray(),
                ItemsElementName = itemsElementName.ToArray()
            };
            syncAdd.ApplicationData = applicationData;

            return syncAdd;
        }
        /// <summary>
        /// Create a default calendar object in the current login user calendar folder
        /// </summary>
        /// <param name="subject">The calendar subject</param>
        /// <param name="organizerEmailAddress">The organizer email address</param>
        /// <param name="attendeeEmailAddress">The attendee email address</param>
        /// <param name="calendarUID">The uid of calendar</param>
        /// <param name="timestamp">The DtStamp of calendar</param>
        /// <param name="startTime">The StartTime of calendar</param>
        /// <param name="endTime">The EndTime of calendar</param>
        /// <returns>Returns the Calendar instance</returns>
        protected Calendar CreateDefaultCalendar(
            string subject,
            string organizerEmailAddress,
            string attendeeEmailAddress,
            string calendarUID,
            DateTime? timestamp,
            DateTime? startTime,
            DateTime? endTime)
        {
            #region Configure the default calendar application data
            Request.SyncCollectionAdd syncAddCollection = new Request.SyncCollectionAdd();
            string clientId = TestSuiteHelper.GetClientId();
            syncAddCollection.ClientId = clientId;
            syncAddCollection.ApplicationData = new Request.SyncCollectionAddApplicationData();

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

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("12.1"))
            {
                items.Add(true);
                itemsElementName.Add(Request.ItemsChoiceType8.ResponseRequested);
            }
            #region TIME/Subject/Location/UID
            items.Add(string.Format("{0:yyyyMMddTHHmmss}Z", null == startTime ? DateTime.UtcNow.AddDays(5) : startTime.Value));
            itemsElementName.Add(Request.ItemsChoiceType8.StartTime);

            items.Add(string.Format("{0:yyyyMMddTHHmmss}Z", null == endTime ? DateTime.UtcNow.AddDays(5).AddMinutes(30) : endTime.Value));
            itemsElementName.Add(Request.ItemsChoiceType8.EndTime);

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                items.Add(string.Format("{0:yyyyMMddTHHmmss}Z", null == timestamp ? DateTime.UtcNow.AddDays(5) : timestamp.Value));
                itemsElementName.Add(Request.ItemsChoiceType8.DtStamp);
            }

            items.Add(subject);
            itemsElementName.Add(Request.ItemsChoiceType8.Subject);

            items.Add(calendarUID ?? Guid.NewGuid().ToString());
            if (Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                itemsElementName.Add(Request.ItemsChoiceType8.ClientUid);
            }
            else
            {
                itemsElementName.Add(Request.ItemsChoiceType8.UID);
            }

            if (Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                Request.Location location = new Request.Location();
                location.DisplayName = "OFFICE";
                items.Add(location);
                itemsElementName.Add(Request.ItemsChoiceType8.Location1);
            }
            else
            {
                items.Add("OFFICE");
                itemsElementName.Add(Request.ItemsChoiceType8.Location);
            }
            #endregion

            #region Attendee/Organizer
            Request.AttendeesAttendee attendee = new Request.AttendeesAttendee
            {
                Email = attendeeEmailAddress,
                Name = new MailAddress(attendeeEmailAddress).User,
                AttendeeStatus = 0x0,
                AttendeeTypeSpecified = true,
                AttendeeType = 0x1
            };

            // 0x0 = Response unknown

            // 0x1 = Required
            items.Add(new Request.Attendees() { Attendee = new Request.AttendeesAttendee[] { attendee } });
            itemsElementName.Add(Request.ItemsChoiceType8.Attendees);

            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                items.Add(organizerEmailAddress);
                itemsElementName.Add(Request.ItemsChoiceType8.OrganizerEmail);
                items.Add(new MailAddress(organizerEmailAddress).DisplayName);
                itemsElementName.Add(Request.ItemsChoiceType8.OrganizerName);
            }
            #endregion

            #region Sensitivity/BusyStatus/AllDayEvent
            // 0x0 == Normal
            items.Add((byte)0x0);
            itemsElementName.Add(Request.ItemsChoiceType8.Sensitivity);

            // 0x1 == Tentative
            items.Add((byte)0x1);
            itemsElementName.Add(Request.ItemsChoiceType8.BusyStatus);

            // 0x0 not an all-day event
            items.Add((byte)0x0);
            itemsElementName.Add(Request.ItemsChoiceType8.AllDayEvent);
            #endregion

            syncAddCollection.ApplicationData.Items = items.ToArray();
            syncAddCollection.ApplicationData.ItemsElementName = itemsElementName.ToArray();
            #endregion

            #region Execute the Sync command to upload the calendar
            SyncStore initSyncResponse = this.InitializeSync(this.User1Information.CalendarCollectionId);
            SyncRequest uploadCalendarRequest = TestSuiteHelper.CreateSyncAddRequest(initSyncResponse.SyncKey, this.User1Information.CalendarCollectionId, syncAddCollection);
            this.EMAILAdapter.Sync(uploadCalendarRequest);
            #endregion

            #region Get the new added calendar item
            SyncStore getItemResponse = this.GetSyncResult(subject, this.User1Information.CalendarCollectionId, null);
            Sync calendarItem = TestSuiteHelper.GetSyncAddItem(getItemResponse, subject);
            Site.Assert.IsNotNull(calendarItem, "The item with subject {0} should be found in the folder {1}.", subject, FolderType.Calendar.ToString());
            #endregion

            return calendarItem.Calendar;
        }
        public void MSASNOTE_S01_TC05_Sync_InvalidMessageClass()
        {
            #region Call method Sync to add a note to the server
            Dictionary<Request.ItemsChoiceType8, object> addElements = this.CreateNoteElements();
            addElements[Request.ItemsChoiceType8.MessageClass] = "IPM.invalidClass";
            SyncRequest syncRequest = TestSuiteHelper.CreateInitialSyncRequest(this.UserInformation.NotesCollectionId);
            SyncStore syncResult = this.NOTEAdapter.Sync(syncRequest, false);

            Site.Assert.AreEqual<byte>(
                1,
                syncResult.CollectionStatus,
                "The server should return a status code 1 in the Sync command response indicate sync command success.");

            List<object> addData = new List<object>();
            Request.SyncCollectionAdd add = new Request.SyncCollectionAdd
            {
                ClientId = System.Guid.NewGuid().ToString(),
                ApplicationData = new Request.SyncCollectionAddApplicationData
                {
                    ItemsElementName = new Request.ItemsChoiceType8[addElements.Count],
                    Items = new object[addElements.Count]
                }
            };

            addElements.Keys.CopyTo(add.ApplicationData.ItemsElementName, 0);
            addElements.Values.CopyTo(add.ApplicationData.Items, 0);
            addData.Add(add);

            syncRequest = TestSuiteHelper.CreateSyncRequest(syncResult.SyncKey, this.UserInformation.NotesCollectionId, addData);
            SyncStore addResult = this.NOTEAdapter.Sync(syncRequest, false);

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

            // Verify MS-ASNOTE requirement: MS-ASNOTE_R119
            Site.CaptureRequirementIfAreEqual<int>(
                6,
                int.Parse(addResult.AddResponses[0].Status),
                119,
                @"[In MessageClass Element] If a client submits a Sync command request ([MS-ASCMD] section 2.2.2.19) that contains a MessageClass element value that does not conform to the requirements specified in section 2.2.2.5, the server MUST respond with a Status element with a value of 6, as specified in [MS-ASCMD] section 2.2.3.162.16.");

            #endregion
        }
        /// <summary>
        /// Create an add Calendar request.
        /// </summary>
        /// <param name="to">Recipient of the calendar.</param>
        /// <param name="subject">Subject of the calendar.</param>
        /// <param name="location">Location of the calendar.</param>
        /// <param name="endTime">End time of the calendar.</param>
        /// <returns>The add Calendar request.</returns>
        private Request.SyncCollectionAdd CreateAddCalendarCommand(string to, string subject, string location, string endTime)
        {
            if (!Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site).Equals("16.0"))
            {
                Request.SyncCollectionAdd appData = new Request.SyncCollectionAdd
                {
                    ClientId = TestSuiteBase.ClientId,
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.To, Request.ItemsChoiceType8.Subject,
                            Request.ItemsChoiceType8.Location,
                            Request.ItemsChoiceType8.EndTime
                        },
                        Items = new object[] { to, subject, location, endTime }
                    },
                    Class = "Calendar"
                };
                return appData;
            }

            else
            {
                Request.SyncCollectionAdd appData = new Request.SyncCollectionAdd
                {
                    ClientId = TestSuiteBase.ClientId,
                    ApplicationData = new Request.SyncCollectionAddApplicationData
                    {
                        ItemsElementName =
                            new Request.ItemsChoiceType8[]
                        {
                            Request.ItemsChoiceType8.To, Request.ItemsChoiceType8.Subject,
                            Request.ItemsChoiceType8.Location1,
                            Request.ItemsChoiceType8.EndTime
                        },
                        Items = new object[] { 
                        to, 
                        subject, 
                        new Request.Location
                        {
                        LocationUri=location
                        }, 
                        endTime }
                    },
                    Class = "Calendar"
                };
                return appData;
            }
        }