Microsoft.Protocols.TestSuites.MS_ASNOTE.TestSuiteHelper.CheckSyncChangeCommands C# (CSharp) Method

CheckSyncChangeCommands() static private method

This method is used to check the Sync Change commands.
static private CheckSyncChangeCommands ( SyncStore result, string subject, ITestSite site ) : bool
result Microsoft.Protocols.TestSuites.Common.DataStructures.SyncStore The sync result which is returned from server
subject string The expected note's subject
site ITestSite An instance of interface ITestSite which provides logging, assertions, and adapters for test code onto its execution context.
return bool
        internal static bool CheckSyncChangeCommands(SyncStore result, string subject, ITestSite site)
        {
            site.Assert.AreEqual<byte>(
                1,
                result.CollectionStatus,
                "The server should return a Status 1 in the Sync command response indicate sync command succeed.");

            bool isNoteFound = false;
            foreach (Sync sync in result.ChangeElements)
            {
                site.Assert.IsNotNull(
                    sync,
                    @"The Change element in response should not be null.");

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

                if (sync.Note.Subject.Equals(subject))
                {
                    isNoteFound = true;
                }
            }

            return isNoteFound;
        }

Usage Example

Example #1
0
        public void MSASNOTE_S01_TC03_Sync_LastModifiedDateIgnored()
        {
            #region Call method Sync to add a note to the server
            Dictionary <Request.ItemsChoiceType8, object> addElements = this.CreateNoteElements();
            string lastModifiedDate = DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture);
            addElements.Add(Request.ItemsChoiceType8.LastModifiedDate, lastModifiedDate);
            System.Threading.Thread.Sleep(1000);
            SyncStore addResult = this.SyncAdd(addElements, 1);
            Response.SyncCollectionsCollectionResponsesAdd item = addResult.AddResponses[0];
            #endregion

            #region Call method Sync to synchronize the note item with the server.
            SyncStore result = this.SyncChanges(1);

            Note note = null;

            for (int i = 0; i < result.AddElements.Count; i++)
            {
                if (addResult.AddElements != null && addResult.AddElements.Count > 0)
                {
                    if (result.AddElements[i].ServerId.Equals(addResult.AddElements[0].ServerId))
                    {
                        note = result.AddElements[i].Note;
                        break;
                    }
                }
                else if (addResult.AddResponses != null && addResult.AddResponses.Count > 0)
                {
                    if (result.AddElements[i].ServerId.Equals(addResult.AddResponses[0].ServerId))
                    {
                        note = result.AddElements[i].Note;
                        break;
                    }
                }
            }
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASNOTE_R84");

            // Verify MS-ASNOTE requirement: MS-ASNOTE_R84
            Site.CaptureRequirementIfAreNotEqual <string>(
                lastModifiedDate,
                note.LastModifiedDate.ToString("yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture),
                84,
                @"[In LastModifiedDate Element] If it is included in a Sync command request, the server will ignore it.");

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

            // Verify MS-ASNOTE requirement: MS-ASNOTE_R209
            // this requirement can be captured directly after MS-ASNOTE_R84.
            Site.CaptureRequirement(
                209,
                @"[In LastModifiedDate Element] If a Sync command request includes the LastModifiedDate element, the server ignores the element and returns the actual time that the note was last modified.");

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

            bool isVerifiedR126 = note.Body != null && note.Subject != null && note.MessageClass != null && note.IsLastModifiedDateSpecified && note.Categories != null && note.Categories.Category != null;

            // Verify MS-ASNOTE requirement: MS-ASNOTE_R126
            Site.CaptureRequirementIfIsTrue(
                isVerifiedR126,
                126,
                @"[In Sync Command Response] Any of the elements for the Notes class[airsyncbase:Body, Subject, MessageClass, LastModifiedDate, Categories or Category], as specified in section 2.2.2, can be included in a Sync command response as child elements of the airsync:ApplicationData element ([MS-ASCMD] section 2.2.3.11) within [either] an airsync:Add element ([MS-ASCMD] section 2.2.3.7.2) [or an airsync:Change element ([MS-ASCMD] section 2.2.3.24)].");

            #endregion

            #region Call method Sync to only change the note's LastModifiedDate element, the server will ignore the change, and the note item should be unchanged.
            // changeElements: Change the note's LastModifiedDate by replacing its LastModifiedDate with a new LastModifiedDate.
            Dictionary <Request.ItemsChoiceType7, object> changeElements = new Dictionary <Request.ItemsChoiceType7, object>();
            lastModifiedDate = DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture);
            changeElements.Add(Request.ItemsChoiceType7.LastModifiedDate, lastModifiedDate);
            this.SyncChange(result.SyncKey, item.ServerId, changeElements);

            #endregion

            #region Call method Sync to synchronize the changes with the server.

            SyncStore result2 = this.SyncChanges(result.SyncKey, 1);

            bool isNoteFound;
            if (result2.ChangeElements != null)
            {
                isNoteFound = TestSuiteHelper.CheckSyncChangeCommands(result, addElements[Request.ItemsChoiceType8.Subject1].ToString(), this.Site);

                Site.Assert.IsFalse(isNoteFound, "The note with subject:{0} should not be returned in Sync command response.", addElements[Request.ItemsChoiceType8.Subject1].ToString());
            }
            else
            {
                Site.Log.Add(LogEntryKind.Debug, @"The Change elements are null.");
            }
            #endregion

            #region Call method Sync to change the note's LastModifiedDate and subject.
            // changeElements: Change the note's LastModifiedDate by replacing its LastModifiedDate with a new LastModifiedDate.
            // changeElements: Change the note's subject by replacing its subject with a new subject.
            changeElements   = new Dictionary <Request.ItemsChoiceType7, object>();
            lastModifiedDate = DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture);
            changeElements.Add(Request.ItemsChoiceType7.LastModifiedDate, lastModifiedDate);
            string changedSubject = Common.GenerateResourceName(Site, "subject");
            changeElements.Add(Request.ItemsChoiceType7.Subject1, changedSubject);
            changeElements = TestSuiteHelper.CombineChangeAndAddNoteElements(addElements, changeElements);
            this.SyncChange(result.SyncKey, item.ServerId, changeElements);

            #endregion

            #region Call method Sync to synchronize the note item with the server.

            result = this.SyncChanges(result.SyncKey, 1);

            isNoteFound = TestSuiteHelper.CheckSyncChangeCommands(result, changeElements[Request.ItemsChoiceType7.Subject1].ToString(), this.Site);

            Site.Assert.IsTrue(isNoteFound, "The note with subject:{0} should be returned in Sync command response.", changeElements[Request.ItemsChoiceType7.Subject1].ToString());

            // The subject of the note is updated.
            this.ExistingNoteSubjects.Remove(addElements[Request.ItemsChoiceType8.Subject1].ToString());
            this.ExistingNoteSubjects.Add(changeElements[Request.ItemsChoiceType7.Subject1].ToString());

            note = result.ChangeElements[0].Note;

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

            bool isVerifiedR210 = note.Body != null && note.Subject != null && note.MessageClass != null && note.IsLastModifiedDateSpecified && note.Categories != null && note.Categories.Category != null;

            // Verify MS-ASNOTE requirement: MS-ASNOTE_R210
            Site.CaptureRequirementIfIsTrue(
                isVerifiedR210,
                210,
                @"[In Sync Command Response] Any of the elements for the Notes class[airsyncbase:Body, Subject, MessageClass, LastModifiedDate, Categories or Category], as specified in section 2.2.2, can be included in a Sync command response as child elements of the airsync:ApplicationData element ([MS-ASCMD] section 2.2.3.11) within [either an airsync:Add element ([MS-ASCMD] section 2.2.3.7.2) or] an airsync:Change element ([MS-ASCMD] section 2.2.3.24).");

            Site.Assert.AreEqual <string>(
                changeElements[Request.ItemsChoiceType7.Subject1].ToString(),
                note.Subject,
                "The subject element in Change Command response should be the same with the changed value of subject in Change Command request.");

            #endregion
        }
All Usage Examples Of Microsoft.Protocols.TestSuites.MS_ASNOTE.TestSuiteHelper::CheckSyncChangeCommands