Ejemplo n.º 1
0
        /// <summary>
        /// Get the specified email item from the sync change response
        /// </summary>
        /// <param name="collectionId">The email folder server id.</param>
        /// <param name="calendarSubject">The subject value of calendar.</param>
        /// <returns>Return the specified email item.</returns>
        public SyncItem GetChangeItem(string collectionId, string calendarSubject)
        {
            SyncItem  resultItem = null;
            SyncStore syncResponse;

            if (collectionId == this.CurrentUserInformation.CalendarCollectionId)
            {
                // Get the server changes through sync command
                syncResponse = this.SyncChanges(collectionId);

                if (syncResponse != null && syncResponse.CollectionStatus == 1)
                {
                    foreach (SyncItem item in syncResponse.AddElements)
                    {
                        if (item.Calendar.Subject == calendarSubject)
                        {
                            resultItem = item;
                            break;
                        }
                    }
                }
            }
            else if (collectionId == this.CurrentUserInformation.InboxCollectionId || collectionId == this.CurrentUserInformation.DeletedItemsCollectionId)
            {
                int waitTime   = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site));
                int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
                int counter    = 0;

                // Get the mailbox changes
                do
                {
                    Thread.Sleep(waitTime);

                    // Get the server changes through sync command, get the new added email item
                    syncResponse = this.SyncChanges(collectionId);

                    if (syncResponse != null && syncResponse.CollectionStatus == 1)
                    {
                        foreach (SyncItem item in syncResponse.AddElements)
                        {
                            if (item.Email.Subject == calendarSubject)
                            {
                                resultItem = item;
                                break;
                            }
                        }
                    }

                    counter++;
                }while ((syncResponse == null || resultItem == null) && counter < retryCount);
            }

            return(resultItem);
        }
        public void MSASCAL_S01_TC31_UnchangedExceptions()
        {
            Site.Assume.AreNotEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The recurring calendar item cannot be created when protocol version is set to 16.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Calls Sync command to add a calendar to the server, and sync calendars from the server.

            Dictionary<Request.ItemsChoiceType8, object> calendarItem = new Dictionary<Request.ItemsChoiceType8, object>();

            DateTime exceptionStartTime = this.StartTime.AddDays(3);
            DateTime startTimeInException = exceptionStartTime.AddMinutes(15);
            DateTime endTimeInException = startTimeInException.AddHours(2);

            // Set Calendar StartTime, EndTime elements
            calendarItem.Add(Request.ItemsChoiceType8.StartTime, this.StartTime.ToString("yyyyMMddTHHmmssZ"));
            calendarItem.Add(Request.ItemsChoiceType8.EndTime, this.EndTime.ToString("yyyyMMddTHHmmssZ"));

            // Set Calendar Recurrence element including Occurrence sub-element
            byte recurrenceType = byte.Parse("0");
            Request.Recurrence recurrence = this.CreateCalendarRecurrence(recurrenceType, 6, 1);
            calendarItem.Add(Request.ItemsChoiceType8.Recurrence, recurrence);

            // Set Calendar Exceptions element
            Request.Exceptions exceptions = new Request.Exceptions { Exception = new Request.ExceptionsException[] { } };
            List<Request.ExceptionsException> exceptionList = new List<Request.ExceptionsException>();

            // Set ExceptionStartTime element in exception
            Request.ExceptionsException exception = TestSuiteHelper.CreateExceptionRequired(exceptionStartTime.ToString("yyyyMMddTHHmmssZ"));

            exception.StartTime = startTimeInException.ToString("yyyyMMddTHHmmssZ");
            exception.EndTime = endTimeInException.ToString("yyyyMMddTHHmmssZ");

            exception.Subject = "Calendar Exception";
            exception.Location = "Room 666";
            exceptionList.Add(exception);
            exceptions.Exception = exceptionList.ToArray();
            calendarItem.Add(Request.ItemsChoiceType8.Exceptions, exceptions);

            string subject = Common.GenerateResourceName(Site, "subject");
            calendarItem.Add(Request.ItemsChoiceType8.Subject, subject);

            this.AddSyncCalendar(calendarItem);

            SyncItem calendar = this.GetChangeItem(this.User1Information.CalendarCollectionId, subject);

            Site.Assert.IsNotNull(calendar.Calendar, "The calendar with subject {0} should exist in server.", subject);

            this.RecordCaseRelativeItems(this.User1Information.UserName, this.User1Information.CalendarCollectionId, subject);

            #endregion

            #region Calls Sync command to Sync calendars from the server.

            // Set Supported Element
            Request.Supported supportedElement = new Request.Supported();

            Dictionary<Request.ItemsChoiceType, object> supportedItem = new Dictionary<Request.ItemsChoiceType, object>
            {
                {
                    Request.ItemsChoiceType.Exceptions, exceptions
                },
                {
                    Request.ItemsChoiceType.DtStamp, string.Empty
                },
                {
                    Request.ItemsChoiceType.Categories, TestSuiteHelper.CreateCalendarCategories(new string[] { "Categories" })
                },
                {
                    Request.ItemsChoiceType.Sensitivity, (byte)1
                },
                {
                    Request.ItemsChoiceType.BusyStatus, (byte)1
                },
                {
                    Request.ItemsChoiceType.UID, string.Empty
                },
                {
                    Request.ItemsChoiceType.Timezone, string.Empty
                },
                {
                    Request.ItemsChoiceType.StartTime, string.Empty
                },
                {
                    Request.ItemsChoiceType.EndTime, string.Empty
                },
                {
                    Request.ItemsChoiceType.Subject, string.Empty
                },
                {
                    Request.ItemsChoiceType.Location, string.Empty
                },
                {
                    Request.ItemsChoiceType.Recurrence, recurrence
                },
                {
                    Request.ItemsChoiceType.AllDayEvent, (byte)1
                },
                {
                    Request.ItemsChoiceType.Reminder, string.Empty
                }
            };

            supportedElement.Items = supportedItem.Values.ToArray<object>();
            supportedElement.ItemsElementName = supportedItem.Keys.ToArray<Request.ItemsChoiceType>();

            // Sync calendars with supported element
            SyncStore syncResponse1 = this.InitializeSync(this.User1Information.CalendarCollectionId, supportedElement);

            SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(this.User1Information.CalendarCollectionId, syncResponse1.SyncKey, true);
            SyncStore syncResponse2 = this.CALAdapter.Sync(syncRequest);
            SyncItem createdCalendar = new SyncItem();

            foreach (SyncItem item in syncResponse2.AddElements)
            {
                if (item.Calendar.Subject == subject)
                {
                    createdCalendar = item;
                    break;
                }
            }

            Site.Assert.IsNotNull(createdCalendar.Calendar, "The calendar with subject {0} should exist in server.", subject);

            syncRequest = TestSuiteHelper.CreateSyncRequest(this.User1Information.CalendarCollectionId, syncResponse2.SyncKey, false);
            SyncStore syncResponse3 = this.CALAdapter.Sync(syncRequest);

            Site.Assert.AreEqual<int>(
                0,
                syncResponse3.AddResponses.Count,
                "This Sync command response should be null.");

            SyncItem updatedCalendar = this.GetChangeItem(this.User1Information.CalendarCollectionId, subject);

            Site.Assert.IsNotNull(updatedCalendar.Calendar, "The calendar with subject {0} should exist in server.", subject);

            #endregion

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

            // Verify MS-ASCAL requirement: MS-ASCAL_R54111
            Site.CaptureRequirementIfIsTrue(
                createdCalendar.Calendar.Exceptions.Exception[0].ExceptionStartTime == calendar.Calendar.Exceptions.Exception[0].ExceptionStartTime
                && createdCalendar.Calendar.Exceptions.Exception[0].StartTime == calendar.Calendar.Exceptions.Exception[0].StartTime
                && createdCalendar.Calendar.Exceptions.Exception[0].EndTime == calendar.Calendar.Exceptions.Exception[0].EndTime
                && createdCalendar.Calendar.Exceptions.Exception[0].Subject == calendar.Calendar.Exceptions.Exception[0].Subject
                && createdCalendar.Calendar.Exceptions.Exception[0].Location == calendar.Calendar.Exceptions.Exception[0].Location,
                54111,
                @"[In Removing Exceptions] [If an Exceptions element (section 2.2.2.20) is not specified in a Sync command request ([MS-ASCMD] section 2.2.2.19.2), then] any exceptions previously defined are unchanged, even if the client included the Exceptions element as a child of the Supported element, as specified in [MS-ASCMD] section 2.2.3.164.");

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

            // Verify MS-ASCAL requirement: MS-ASCAL_R541
            Site.CaptureRequirementIfIsTrue(
                updatedCalendar.Calendar.Exceptions.Exception[0].ExceptionStartTime == calendar.Calendar.Exceptions.Exception[0].ExceptionStartTime
                && updatedCalendar.Calendar.Exceptions.Exception[0].StartTime == calendar.Calendar.Exceptions.Exception[0].StartTime
                && updatedCalendar.Calendar.Exceptions.Exception[0].EndTime == calendar.Calendar.Exceptions.Exception[0].EndTime
                && updatedCalendar.Calendar.Exceptions.Exception[0].Subject == calendar.Calendar.Exceptions.Exception[0].Subject
                && updatedCalendar.Calendar.Exceptions.Exception[0].Location == calendar.Calendar.Exceptions.Exception[0].Location,
                541,
                @"[In Removing Exceptions] If an Exceptions element (section 2.2.2.20) is not specified in a Sync command request ([MS-ASCMD] section 2.2.2.19), then any exceptions previously defined are unchanged. ");
        }