/// <summary>
        /// Create a Request.Recurrence instance with child elements.
        /// </summary>
        /// <param name="recurrenceType">The recurrence type</param>
        /// <param name="occurrences">The value of Occurrences element.</param>
        /// <param name="interval">The value of Interval element.</param>
        /// <returns>The created Request.Recurrence instance without Until element.</returns>
        public Request.Recurrence CreateCalendarRecurrence(byte recurrenceType, int occurrences, int interval)
        {
            Request.Recurrence recurrence = new Request.Recurrence {
                Type = recurrenceType
            };

            if (occurrences != 0)
            {
                recurrence.Occurrences          = ushort.Parse(occurrences.ToString());
                recurrence.OccurrencesSpecified = true;
            }
            else
            {
                recurrence.OccurrencesSpecified = false;
            }

            recurrence.Interval = ushort.Parse(interval.ToString());

            // The value of WeekOfMonth MUST between 1 and 5. WeekOfMonth is required to be included when Type is either 3 or 6.
            if (recurrence.Type == 3 || recurrence.Type == 6)
            {
                recurrence.WeekOfMonth          = byte.Parse("1");
                recurrence.WeekOfMonthSpecified = true;
            }

            // DayOfWeek is required to be included when Type is 1, 3 or 6.
            if (recurrence.Type == 1 || recurrence.Type == 3 || recurrence.Type == 6)
            {
                recurrence.DayOfWeek          = ushort.Parse("1");
                recurrence.DayOfWeekSpecified = true;
            }

            // The value of MonthOfYear MUST between 1 and 12. MonthOfYear is required to be included when Type is either 5 or 6.
            if (recurrence.Type == 5 || recurrence.Type == 6)
            {
                recurrence.MonthOfYear          = byte.Parse("4");
                recurrence.MonthOfYearSpecified = true;
            }

            // The value of DayOfMonth MUST between 1 and 31. DayOfMonth is required to be included when Type is either 2 or 5.
            if (recurrence.Type == 2 || recurrence.Type == 5)
            {
                recurrence.DayOfMonth          = byte.Parse("1");
                recurrence.DayOfMonthSpecified = true;
            }

            // CalendarType is only included when Type is either 2, 3, 5, 6.
            // The CalendarType element is not supported when the MS-ASProtocolVersion header is set to 12.1
            if (!this.IsActiveSyncProtocolVersion121 && (recurrence.Type == 2 || recurrence.Type == 3 || recurrence.Type == 5 || recurrence.Type == 6))
            {
                recurrence.CalendarType          = byte.Parse("1");
                recurrence.CalendarTypeSpecified = true;
            }

            return(recurrence);
        }
        /// <summary>
        /// Create a Request.Recurrence instance including specified CalendarType element value.
        /// </summary>
        /// <param name="recurrenceInstance">The recurrence instance</param>
        /// <param name="calendarType">The calendarType value</param>
        /// <returns>The created Request.Recurrence instance.</returns>
        public Request.Recurrence CreateRecurrenceIncludingCalendarType(Request.Recurrence recurrenceInstance, byte calendarType)
        {
            Request.Recurrence recurrence = recurrenceInstance;

            if (!this.IsActiveSyncProtocolVersion121)
            {
                recurrence.CalendarType          = calendarType;
                recurrence.CalendarTypeSpecified = true;
            }

            return(recurrence);
        }
Example #3
0
        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
        }
        /// <summary>
        /// Create a Request.Recurrence instance with child elements.
        /// </summary>
        /// <param name="recurrenceType">The recurrence type</param>
        /// <param name="occurrences">The value of Occurrences element.</param>
        /// <param name="interval">The value of Interval element.</param>
        /// <returns>The created Request.Recurrence instance without Until element.</returns>
        public Request.Recurrence CreateCalendarRecurrence(byte recurrenceType, int occurrences, int interval)
        {
            Request.Recurrence recurrence = new Request.Recurrence { Type = recurrenceType };

            if (occurrences != 0)
            {
                recurrence.Occurrences = ushort.Parse(occurrences.ToString());
                recurrence.OccurrencesSpecified = true;
            }
            else
            {
                recurrence.OccurrencesSpecified = false;
            }

            recurrence.Interval = ushort.Parse(interval.ToString());

            // The value of WeekOfMonth MUST between 1 and 5. WeekOfMonth is required to be included when Type is either 3 or 6.
            if (recurrence.Type == 3 || recurrence.Type == 6)
            {
                recurrence.WeekOfMonth = byte.Parse("1");
                recurrence.WeekOfMonthSpecified = true;
            }

            // DayOfWeek is required to be included when Type is 1, 3 or 6.
            if (recurrence.Type == 1 || recurrence.Type == 3 || recurrence.Type == 6)
            {
                recurrence.DayOfWeek = ushort.Parse("1");
                recurrence.DayOfWeekSpecified = true;
            }

            // The value of MonthOfYear MUST between 1 and 12. MonthOfYear is required to be included when Type is either 5 or 6.
            if (recurrence.Type == 5 || recurrence.Type == 6)
            {
                recurrence.MonthOfYear = byte.Parse("4");
                recurrence.MonthOfYearSpecified = true;
            }

            // The value of DayOfMonth MUST between 1 and 31. DayOfMonth is required to be included when Type is either 2 or 5.
            if (recurrence.Type == 2 || recurrence.Type == 5)
            {
                recurrence.DayOfMonth = byte.Parse("1");
                recurrence.DayOfMonthSpecified = true;
            }

            // CalendarType is only included when Type is either 2, 3, 5, 6.
            // The CalendarType element is not supported when the MS-ASProtocolVersion header is set to 12.1
            if (!this.IsActiveSyncProtocolVersion121 && (recurrence.Type == 2 || recurrence.Type == 3 || recurrence.Type == 5 || recurrence.Type == 6))
            {
                recurrence.CalendarType = byte.Parse("1");
                recurrence.CalendarTypeSpecified = true;
            }

            return recurrence;
        }
Example #5
0
        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
        }