CreateInitialSyncRequest() static private method

Builds a initial Sync request by using the specified collection Id.
static private CreateInitialSyncRequest ( string collectionId ) : SyncRequest
collectionId string Folder collection Id to be synchronized.
return SyncRequest
        /// <summary>
        /// Call Sync command to fetch all notes
        /// </summary>
        /// <param name="bodyType">The type of the body</param>
        /// <returns>Return change result</returns>
        protected SyncStore SyncChanges(byte bodyType)
        {
            SyncRequest syncInitialRequest = TestSuiteHelper.CreateInitialSyncRequest(this.UserInformation.NotesCollectionId);
            SyncStore   syncInitialResult  = this.NOTEAdapter.Sync(syncInitialRequest, false);

            // Verify sync change result
            this.Site.Assert.AreEqual <byte>(
                1,
                syncInitialResult.CollectionStatus,
                "The server returns a Status 1 in the Sync command response indicate sync command success.",
                syncInitialResult.Status);

            SyncStore syncResult = this.SyncChanges(syncInitialResult.SyncKey, bodyType);

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

            this.Site.Assert.IsNotNull(
                syncResult.AddElements,
                "The server should return Add elements in response");

            Collection <Sync> expectedCommands = new Collection <Sync>();

            foreach (Sync sync in syncResult.AddElements)
            {
                this.Site.Assert.IsNotNull(
                    sync,
                    @"The Add element in response should not be null.");

                this.Site.Assert.IsNotNull(
                    sync.Note,
                    @"The note class in response should not be null.");

                if (this.ExistingNoteSubjects.Contains(sync.Note.Subject))
                {
                    expectedCommands.Add(sync);
                }
            }

            this.Site.Assert.AreEqual <int>(
                this.ExistingNoteSubjects.Count,
                expectedCommands.Count,
                @"The number of Add elements returned in response should be equal to the number of expected notes' subjects");

            syncResult.AddElements.Clear();
            foreach (Sync sync in expectedCommands)
            {
                syncResult.AddElements.Add(sync);
            }

            return(syncResult);
        }
Example #2
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>
        /// 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);
        }