public void MSOXWSMTGS_S06_TC01_CalendarPermissionLevelOwner()
        {
            this.MTGSAdapter = new MS_OXWSMTGSAdapter();
            this.MTGSAdapter.Initialize(this.Site);
            this.SRCHAdapter = new MS_OXWSSRCHAdapter();
            this.SRCHAdapter.Initialize(this.Site);
            this.FOLDAdapter = new MS_OXWSFOLDAdapter();
            this.FOLDAdapter.Initialize(this.Site);

            #region Organizer creates a calendar folder in the inbox folder and grant Owner permission to attendee.

            // Switch to user organizer.
            this.FOLDAdapter.SwitchUser(this.Organizer, this.OrganizerPassword, this.Domain);

            CalendarPermissionSetType calendarPermissionSet = new CalendarPermissionSetType();
            calendarPermissionSet.CalendarPermissions = new CalendarPermissionType[1];
            calendarPermissionSet.CalendarPermissions[0] = new CalendarPermissionType();
            calendarPermissionSet.CalendarPermissions[0].CalendarPermissionLevel = CalendarPermissionLevelType.Owner;
            calendarPermissionSet.CalendarPermissions[0].UserId = new UserIdType();
            calendarPermissionSet.CalendarPermissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("AttendeeName", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "CustomFolderByOrganizer" }, new string[] { "IPF.Appointment" }, null);
            ((CalendarFolderType)createFolderRequest.Folders[0]).PermissionSet = calendarPermissionSet;

            // Create a new folder.
            CreateFolderResponseType createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(createFolderResponse, 1, this.Site);

            // Save the new created folder's folder id.
            FolderIdType newFolderIdByOrganizer = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.FolderToDelete = newFolderIdByOrganizer;
            #endregion

            #region Organizer gets the new created folder.

            // GetFolder request.
            GetFolderType getNewFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, newFolderIdByOrganizer);

            // Get the new created folder.
            GetFolderResponseType getInboxFolderResponse = this.FOLDAdapter.GetFolder(getNewFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getInboxFolderResponse, 1, this.Site);

            // Verify the folder is created successfully.
            FolderInfoResponseMessageType foldersResponseInfo = (FolderInfoResponseMessageType)getInboxFolderResponse.ResponseMessages.Items[0];
            Site.Assert.AreEqual<string>(newFolderIdByOrganizer.Id, foldersResponseInfo.Folders[0].FolderId.Id, "The calendar folder should be created successfully in inbox.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R507
            // The element with type CalendarFolderType is returned and pass the schema validation, this requirement can be captured.
            this.Site.CaptureRequirementIfIsInstanceOfType(
                foldersResponseInfo.Folders[0],
                typeof(CalendarFolderType),
                507,
                @"[In t:CalendarFolderType Complex Type] This complex type extends the BaseFolderType complex type, as specified in [MS-OXWSFOLD] section 2.2.4.6.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R143
            // The element with type CalendarFolderType is returned and pass the schema validation, this requirement can be captured.
            this.Site.CaptureRequirementIfIsInstanceOfType(
                foldersResponseInfo.Folders[0],
                typeof(CalendarFolderType),
                143,
                @"[In t:CalendarFolderType Complex Type] [its schema is] <xs:complexType name=""CalendarFolderType"">
                  <xs:complexContent>
                    <xs:extension
                      base=""t:BaseFolderType""
                      >
                    <xs:sequence>
                      <xs:element name=""SharingEffectiveRights""
                      type=""t:CalendarPermissionReadAccessType""
                      minOccurs=""0""
                    />
                    <xs:element name=""PermissionSet""
                      type=""t:CalendarPermissionSetType""
                      minOccurs=""0""
                    />
                  </xs:sequence>
                </xs:extension>
              </xs:complexContent>
            </xs:complexType>");

            CalendarFolderType folderInfo = (CalendarFolderType)foldersResponseInfo.Folders[0];

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R237
            this.Site.CaptureRequirementIfIsNotNull(
                folderInfo.PermissionSet,
                237,
                @"[In t:CalendarPermissionSetType Complex Type] [its schema is] <xs:complexType name=""CalendarPermissionSetType"">
                  <xs:sequence>
                    <xs:element name=""CalendarPermissions""
                      type=""t:ArrayOfCalendarPermissionsType""
                     />
                    <xs:element name=""UnknownEntries""
                      type=""t:ArrayOfUnknownEntriesType""
                      minOccurs=""0""
                     />
                  </xs:sequence>
                </xs:complexType>");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R146
            this.Site.CaptureRequirementIfIsNotNull(
                folderInfo.PermissionSet,
                146,
                @"[In t:CalendarFolderType Complex Type] The type of PermissionSet is t:CalendarPermissionSetType (section 2.2.4.5).");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R147
            this.Site.CaptureRequirementIfAreEqual<CalendarPermissionLevelType>(
                CalendarPermissionLevelType.Owner,
                folderInfo.PermissionSet.CalendarPermissions[2].CalendarPermissionLevel,
                147,
                @"[In t:CalendarFolderType Complex Type]PermissionSet: Specifies all permissions that are configured for a Calendar folder.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R534
            this.Site.CaptureRequirementIfIsNotNull(
                folderInfo.PermissionSet.CalendarPermissions,
                534,
                @"[In t:CalendarPermissionType Complex Type] This complex type extends the BasePermissionType complex type, as specified in [MS-OXWSFOLD] section 2.2.4.3.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R238
            this.Site.CaptureRequirementIfIsNotNull(
                folderInfo.PermissionSet.CalendarPermissions,
                238,
                @"[In t:CalendarPermissionSetType Complex Type] The type of CalendarPermissions is t:ArrayofCalendarPermissionsType ([MS-OXWSCDATA] section 2.2.4.4).");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R243
            this.Site.CaptureRequirementIfIsNotNull(
                folderInfo.PermissionSet.CalendarPermissions,
                243,
                @"[In t:CalendarPermissionType Complex Type] [its schema is] <xs:complexType name=""CalendarPermissionType"">
                  <xs:complexContent>
                    <xs:extension
                      base=""t:BasePermissionType""
                    >
                      <xs:sequence>
                        <xs:element name=""ReadItems""
                          type=""t:CalendarPermissionReadAccessType""
                          minOccurs=""0""
                          maxOccurs=""1""
                         />
                        <xs:element name=""CalendarPermissionLevel""
                          type=""t:CalendarPermissionLevelType""
                          minOccurs=""1""
                          maxOccurs=""1""
                         />
                      </xs:sequence>
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R244
            this.Site.CaptureRequirementIfIsTrue(
                folderInfo.PermissionSet.CalendarPermissions[2].ReadItemsSpecified,
                244,
                @"[In t:CalendarPermissionType Complex Type] The type of ReadItems is t:CalendarPermissionReadAccessType (section 2.2.5.5).");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R245
            // As organizer grants Owner to attendee, so ReadItems should be FullDetails.
            this.Site.CaptureRequirementIfAreEqual<CalendarPermissionReadAccessType>(
                CalendarPermissionReadAccessType.FullDetails,
                folderInfo.PermissionSet.CalendarPermissions[2].ReadItems,
                245,
                @"[In t:CalendarPermissionType Complex Type] ReadItems: Specifies the permissions a user has to view items in a Calendar folder.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R246
            this.Site.CaptureRequirementIfAreEqual<CalendarPermissionLevelType>(
                CalendarPermissionLevelType.Owner,
                folderInfo.PermissionSet.CalendarPermissions[2].CalendarPermissionLevel,
                246,
                @"[In t:CalendarPermissionType Complex Type] The type of CalendarPermissionLevel is t:CalendarPermissionLevelType (section 2.2.5.4).");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R247
            this.Site.CaptureRequirementIfAreEqual<CalendarPermissionLevelType>(
                CalendarPermissionLevelType.Owner,
                folderInfo.PermissionSet.CalendarPermissions[2].CalendarPermissionLevel,
                247,
                @"[In t:CalendarPermissionType Complex Type]CalendarPermissionLevel: Specifies the permission level that a user has on a Calendar folder.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R248
            this.Site.CaptureRequirementIfAreEqual<CalendarPermissionLevelType>(
                CalendarPermissionLevelType.Owner,
                folderInfo.PermissionSet.CalendarPermissions[2].CalendarPermissionLevel,
                248,
                @"[In t:CalendarPermissionType Complex Type] CalendarPermissionLevel: This element MUST exist if calendar permissions are set on a Calendar folder.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSMTGS_R97
            this.Site.CaptureRequirementIfIsTrue(
                folderInfo.PermissionSet.CalendarPermissions[2].IsFolderContactSpecified && folderInfo.PermissionSet.CalendarPermissions[2].IsFolderContact,
                97,
                @"[In t:CalendarPermissionLevelType Simple Type] Owner: The user is both folder owner and folder contact.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSMTGS_R239
            // This requirement can be captured directly after the verifications in above.
            this.Site.CaptureRequirement(
                239,
                @"[In t:CalendarPermissionSetType Complex Type] CalendarPermissions: Contains an array of calendar permissions for a folder.");

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R86
            // Element in type CalendarPermissionLevelType is returned, this requirement can be captured directly.
            this.Site.CaptureRequirement(
                86,
                @"[In t:CalendarPermissionLevelType Simple Type] [its schema is] <xs:simpleType name=""CalendarPermissionLevelType"">
                  <xs:restriction
                    base=""xs:string""
                  >
                    <xs:enumeration
                      value=""Author""
                     />
                    <xs:enumeration
                      value=""Contributor""
                     />
                    <xs:enumeration
                      value=""Custom""
                     />
                    <xs:enumeration
                      value=""Editor""
                     />
                    <xs:enumeration
                      value=""FreeBusyTimeAndSubjectAndLocation""
                     />
                    <xs:enumeration
                      value=""FreeBusyTimeOnly""
                     />
                    <xs:enumeration
                      value=""None""
                     />
                    <xs:enumeration
                      value=""NoneditingAuthor""
                     />
                    <xs:enumeration
                      value=""Owner""
                     />
                    <xs:enumeration
                      value=""PublishingAuthor""
                     />
                    <xs:enumeration
                      value=""PublishingEditor""
                     />
                    <xs:enumeration
                      value=""Reviewer""
                     />
                  </xs:restriction>
                </xs:simpleType>");
            #endregion

            #region Organizer creates a calendar item in the created folder.
            CalendarItemType calendarItembyOrganizer = new CalendarItemType();
            calendarItembyOrganizer.UID = Guid.NewGuid().ToString();
            calendarItembyOrganizer.Subject = Common.GenerateResourceName(this.Site, "CalendarItemCreatedByOrganizer");
            calendarItembyOrganizer.LegacyFreeBusyStatus = LegacyFreeBusyType.Busy;
            calendarItembyOrganizer.LegacyFreeBusyStatusSpecified = true;
            calendarItembyOrganizer.Location = this.Location;
            calendarItembyOrganizer.Body = new BodyType();
            calendarItembyOrganizer.Body.BodyType1 = BodyTypeType.Text;
            calendarItembyOrganizer.Body.Value = Common.GenerateResourceName(this.Site, "CalendarBody");
            NonEmptyArrayOfAllItemsType allItemArray = new NonEmptyArrayOfAllItemsType();
            allItemArray.Items = new ItemType[] { calendarItembyOrganizer };
            CreateItemType createItemRequest = new CreateItemType();
            createItemRequest.Items = allItemArray;
            createItemRequest.SendMeetingInvitationsSpecified = true;
            createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone;
            createItemRequest.SavedItemFolderId = new TargetFolderIdType();
            createItemRequest.SavedItemFolderId.Item = newFolderIdByOrganizer;
            CreateItemResponseType response = this.MTGSAdapter.CreateItem(createItemRequest);
            Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, response.ResponseMessages.Items[0].ResponseClass, "The calendar item should be created successfully.");
            ItemInfoResponseMessageType itemInfoResponse = response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
            Site.Assert.IsNotNull(itemInfoResponse, "The calendar item should be created successfully.");
            ItemIdType itemIdByOrganizer = itemInfoResponse.Items.Items[0].ItemId;
            #endregion

            #region Attendee creates a folder in the created folder.

            // Switch to user attendee.
            this.FOLDAdapter.SwitchUser(this.Attendee, this.AttendeePassword, this.Domain);

            createFolderRequest = this.GetCreateFolderRequest(newFolderIdByOrganizer.Id, new string[] { "CustomFolderByAttendee" }, new string[] { "IPF.Appointment" }, null);
            createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);
            bool canCreateSubFolder = ResponseClassType.Success == createFolderResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Attendee creates a calendar item in the created folder.
            this.SwitchMTGSUser(Role.Attendee);
            CalendarItemType calendarItembyAttendee = new CalendarItemType();
            calendarItembyAttendee.UID = Guid.NewGuid().ToString();
            calendarItembyAttendee.Subject = Common.GenerateResourceName(this.Site, "CalendarItemCreatedByAttendee");
            createItemRequest.Items.Items[0] = calendarItembyAttendee;
            response = this.MTGSAdapter.CreateItem(createItemRequest);
            Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, response.ResponseMessages.Items[0].ResponseClass, "The calendar item should be created successfully.");
            itemInfoResponse = response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
            bool canCreateOwnItem = null != itemInfoResponse;
            Site.Assert.IsTrue(canCreateOwnItem, "The calendar item should be created successfully.");
            ItemIdType itemIdByAttendee = itemInfoResponse.Items.Items[0].ItemId;
            #endregion

            #region Attendee gets the calendar item created by hisself.
            itemInfoResponse = this.GetSingleCalendarItem(Role.Attendee, itemIdByAttendee);
            bool canReadOwnItem = null != itemInfoResponse;
            #endregion

            #region Attendee updates the calendar item created by hisself.
            CalendarItemType calendarUpdate = new CalendarItemType();
            calendarUpdate.Location = this.LocationUpdate;

            AdapterHelper itemChangeInfo = new AdapterHelper();
            itemChangeInfo.FieldURI = UnindexedFieldURIType.calendarLocation;
            itemChangeInfo.Item = calendarUpdate;
            itemChangeInfo.ItemId = itemIdByAttendee;

            // Update the created calendar item.
            UpdateItemResponseMessageType updatedItem = this.UpdateSingleCalendarItem(Role.Attendee, itemChangeInfo, CalendarItemUpdateOperationType.SendToNone);
            bool canUpdateOwnItem = null != updatedItem;
            #endregion

            #region Attendee deletes the calendar item created by hisself.
            ResponseMessageType responseMessage = this.DeleteSingleCalendarItem(Role.Attendee, itemIdByAttendee, CalendarItemCreateOrDeleteOperationType.SendToNone);
            bool canDeleteOwnItem = null != responseMessage && responseMessage.ResponseClass == ResponseClassType.Success;
            #endregion

            #region Attendee gets the calendar item created by organizer.
            itemInfoResponse = this.GetSingleCalendarItem(Role.Attendee, itemIdByOrganizer);
            bool canReadNotOwnItem = null != itemInfoResponse;

            if (canReadNotOwnItem)
            {
                CalendarItemType temp = itemInfoResponse.Items.Items[0] as CalendarItemType;
                Site.Assert.AreEqual<string>(calendarItembyOrganizer.Subject, temp.Subject, "User should have permission to view subject of appointment.");
                Site.Assert.AreEqual<string>(calendarItembyOrganizer.Location, temp.Location, "User should have permission to view location of appointment.");
                Site.Assert.AreEqual<bool>(calendarItembyOrganizer.LegacyFreeBusyStatusSpecified, temp.LegacyFreeBusyStatusSpecified, "User should have permission to view free/busy time of appointment.");
                Site.Assert.AreEqual<LegacyFreeBusyType>(calendarItembyOrganizer.LegacyFreeBusyStatus, temp.LegacyFreeBusyStatus, "User should have permission to view free/busy time of appointment.");
                Site.Assert.IsNotNull(temp.Body, "User should have permission to view body of appointment.");
                Site.Assert.AreEqual<BodyTypeType>(calendarItembyOrganizer.Body.BodyType1, temp.Body.BodyType1, "User should have permission to view body of appointment.");
                Site.Assert.AreEqual<string>(calendarItembyOrganizer.Body.Value, temp.Body.Value, "User should have permission to view body of appointment.");

                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSMTGS_R107, the value of ReadItems is {0}", folderInfo.PermissionSet.CalendarPermissions[2].ReadItems);

                // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R107
                this.Site.CaptureRequirementIfIsTrue(
                    folderInfo.PermissionSet.CalendarPermissions[2].ReadItemsSpecified && folderInfo.PermissionSet.CalendarPermissions[2].ReadItems == CalendarPermissionReadAccessType.FullDetails,
                    107,
                    @"[In t:CalendarPermissionReadAccessType Simple Type] FullDetails: The user has permission to view all items in the calendar, including free/busy time and subject, location, and details of appointments.");

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

                // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R102
                this.Site.CaptureRequirement(
                    102,
                    @"[In t:CalendarPermissionReadAccessType Simple Type] [its schema is] <xs:simpleType name=""CalendarPermissionReadAccessType"">
                      <xs:restriction
                        base=""xs:string""                    
                      >
                        <xs:enumeration
                          value=""None""
                         />
                        <xs:enumeration
                          value=""TimeOnly""
                         />
                        <xs:enumeration
                          value=""TimeAndSubjectAndLocation""
                         />
                        <xs:enumeration
                          value=""FullDetails""
                         />
                      </xs:restriction>
                    </xs:simpleType>");
            }
            #endregion

            #region Attendee updates the calendar item created by organizer.
            calendarUpdate = new CalendarItemType();
            calendarUpdate.Location = this.LocationUpdate;

            itemChangeInfo = new AdapterHelper();
            itemChangeInfo.FieldURI = UnindexedFieldURIType.calendarLocation;
            itemChangeInfo.Item = calendarUpdate;
            itemChangeInfo.ItemId = itemIdByOrganizer;

            // Update the created calendar item.
            updatedItem = this.UpdateSingleCalendarItem(Role.Attendee, itemChangeInfo, CalendarItemUpdateOperationType.SendToNone);
            bool canUpdateNotOwnItem = null != updatedItem;
            #endregion

            #region Attendee deletes the calendar item created by organizer.
            responseMessage = this.DeleteSingleCalendarItem(Role.Attendee, itemIdByOrganizer, CalendarItemCreateOrDeleteOperationType.SendToNone);
            bool canDeleteNotOwnItem = null != responseMessage && responseMessage.ResponseClass == ResponseClassType.Success;
            #endregion

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R96
            bool isVerifiedR96 = canCreateOwnItem && canReadOwnItem && canUpdateOwnItem && canDeleteOwnItem && canReadNotOwnItem
                && canUpdateNotOwnItem && canDeleteNotOwnItem && canCreateSubFolder;

            Site.Assert.IsTrue(
                isVerifiedR96,
                "Can create own item is {0};\n" +
                "Can read own item is {1};\n" +
                "Can edit own item is {2};\n " +
                "Can delete own item is {3};\n" +
                "Can read not own item is {4};\n" +
                "Can edit not own item is {5};\n" +
                "Can delete not own item is {6};\n" +
                "Can create subfolders is {7};\n",
                canCreateOwnItem,
                canReadOwnItem,
                canUpdateOwnItem,
                canDeleteOwnItem,
                canReadNotOwnItem,
                canUpdateNotOwnItem,
                canDeleteNotOwnItem,
                canCreateSubFolder);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR96,
                96,
                @"[In t:CalendarPermissionLevelType Simple Type] Owner: The user can create, read, edit, and delete all items in the folder, and create subfolders.");
        }
        public void MSOXWSMTGS_S06_TC04_CalendarPermissionLevelEditor()
        {
            this.MTGSAdapter = new MS_OXWSMTGSAdapter();
            this.MTGSAdapter.Initialize(this.Site);
            this.SRCHAdapter = new MS_OXWSSRCHAdapter();
            this.SRCHAdapter.Initialize(this.Site);
            this.FOLDAdapter = new MS_OXWSFOLDAdapter();
            this.FOLDAdapter.Initialize(this.Site);

            #region Organizer creates a calendar folder in the inbox folder and grant Editor permission to attendee.

            // Switch to user organizer.
            this.FOLDAdapter.SwitchUser(this.Organizer, this.OrganizerPassword, this.Domain);

            CalendarPermissionSetType calendarPermissionSet = new CalendarPermissionSetType();
            calendarPermissionSet.CalendarPermissions = new CalendarPermissionType[1];
            calendarPermissionSet.CalendarPermissions[0] = new CalendarPermissionType();
            calendarPermissionSet.CalendarPermissions[0].CalendarPermissionLevel = CalendarPermissionLevelType.Editor;
            calendarPermissionSet.CalendarPermissions[0].UserId = new UserIdType();
            calendarPermissionSet.CalendarPermissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("AttendeeName", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "CustomFolderByOrganizer" }, new string[] { "IPF.Appointment" }, null);
            ((CalendarFolderType)createFolderRequest.Folders[0]).PermissionSet = calendarPermissionSet;

            // Create a new folder.
            CreateFolderResponseType createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(createFolderResponse, 1, this.Site);

            // Save the new created folder's folder id.
            FolderIdType newFolderIdByOrganizer = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.FolderToDelete = newFolderIdByOrganizer;
            #endregion

            #region Organizer gets the new created folder.

            // GetFolder request.
            GetFolderType getNewFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, newFolderIdByOrganizer);

            // Get the new created folder.
            GetFolderResponseType getInboxFolderResponse = this.FOLDAdapter.GetFolder(getNewFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getInboxFolderResponse, 1, this.Site);

            // Verify the folder is created successfully.
            FolderInfoResponseMessageType foldersResponseInfo = (FolderInfoResponseMessageType)getInboxFolderResponse.ResponseMessages.Items[0];
            Site.Assert.AreEqual<string>(newFolderIdByOrganizer.Id, foldersResponseInfo.Folders[0].FolderId.Id, "The calendar folder should be created successfully in inbox.");
            #endregion

            #region Organizer creates a calendar item in the created folder.
            CalendarItemType calendarItembyOrganizer = new CalendarItemType();
            calendarItembyOrganizer.UID = Guid.NewGuid().ToString();
            calendarItembyOrganizer.Subject = Common.GenerateResourceName(this.Site, "CalendarItemCreatedByOrganizer");
            NonEmptyArrayOfAllItemsType allItemArray = new NonEmptyArrayOfAllItemsType();
            allItemArray.Items = new ItemType[] { calendarItembyOrganizer };
            CreateItemType createItemRequest = new CreateItemType();
            createItemRequest.Items = allItemArray;
            createItemRequest.SendMeetingInvitationsSpecified = true;
            createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone;
            createItemRequest.SavedItemFolderId = new TargetFolderIdType();
            createItemRequest.SavedItemFolderId.Item = newFolderIdByOrganizer;
            CreateItemResponseType response = this.MTGSAdapter.CreateItem(createItemRequest);
            Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, response.ResponseMessages.Items[0].ResponseClass, "The calendar item should be created successfully.");
            ItemInfoResponseMessageType itemInfoResponse = response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
            Site.Assert.IsNotNull(itemInfoResponse, "The calendar item should be created successfully.");
            ItemIdType itemIdByOrganizer = itemInfoResponse.Items.Items[0].ItemId;
            #endregion

            #region Attendee creates a folder in the created folder.

            // Switch to user attendee.
            this.FOLDAdapter.SwitchUser(this.Attendee, this.AttendeePassword, this.Domain);

            createFolderRequest = this.GetCreateFolderRequest(newFolderIdByOrganizer.Id, new string[] { "CustomFolderByAttendee" }, new string[] { "IPF.Appointment" }, null);
            createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);
            bool canCreateSubFolder = ResponseClassType.Success == createFolderResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Attendee creates a calendar item in the created folder.
            this.SwitchMTGSUser(Role.Attendee);
            CalendarItemType calendarItembyAttendee = new CalendarItemType();
            calendarItembyAttendee.UID = Guid.NewGuid().ToString();
            calendarItembyAttendee.Subject = Common.GenerateResourceName(this.Site, "CalendarItemCreatedByAttendee");
            createItemRequest.Items.Items[0] = calendarItembyAttendee;
            response = this.MTGSAdapter.CreateItem(createItemRequest);
            Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, response.ResponseMessages.Items[0].ResponseClass, "The calendar item should be created successfully.");
            itemInfoResponse = response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
            bool canCreateOwnItem = null != itemInfoResponse;
            Site.Assert.IsTrue(canCreateOwnItem, "The calendar item should be created successfully.");
            ItemIdType itemIdByAttendee = itemInfoResponse.Items.Items[0].ItemId;
            #endregion

            #region Attendee gets the calendar item created by hisself.
            itemInfoResponse = this.GetSingleCalendarItem(Role.Attendee, itemIdByAttendee);
            bool canReadOwnItem = null != itemInfoResponse;
            #endregion

            #region Attendee updates the calendar item created by hisself.
            CalendarItemType calendarUpdate = new CalendarItemType();
            calendarUpdate.Location = this.LocationUpdate;

            AdapterHelper itemChangeInfo = new AdapterHelper();
            itemChangeInfo.FieldURI = UnindexedFieldURIType.calendarLocation;
            itemChangeInfo.Item = calendarUpdate;
            itemChangeInfo.ItemId = itemIdByAttendee;

            // Update the created calendar item.
            UpdateItemResponseMessageType updatedItem = this.UpdateSingleCalendarItem(Role.Attendee, itemChangeInfo, CalendarItemUpdateOperationType.SendToNone);
            bool canUpdateOwnItem = null != updatedItem;
            #endregion

            #region Attendee deletes the calendar item created by hisself.
            ResponseMessageType responseMessage = this.DeleteSingleCalendarItem(Role.Attendee, itemIdByAttendee, CalendarItemCreateOrDeleteOperationType.SendToNone);
            bool canDeleteOwnItem = null != responseMessage && responseMessage.ResponseClass == ResponseClassType.Success;
            #endregion

            #region Attendee gets the calendar item created by organizer.
            itemInfoResponse = this.GetSingleCalendarItem(Role.Attendee, itemIdByOrganizer);
            bool canReadNotOwnItem = null != itemInfoResponse;
            #endregion

            #region Attendee updates the calendar item created by organizer.
            calendarUpdate = new CalendarItemType();
            calendarUpdate.Location = this.LocationUpdate;

            itemChangeInfo = new AdapterHelper();
            itemChangeInfo.FieldURI = UnindexedFieldURIType.calendarLocation;
            itemChangeInfo.Item = calendarUpdate;
            itemChangeInfo.ItemId = itemIdByOrganizer;

            // Update the created calendar item.
            updatedItem = this.UpdateSingleCalendarItem(Role.Attendee, itemChangeInfo, CalendarItemUpdateOperationType.SendToNone);
            bool canUpdateNotOwnItem = null != updatedItem;
            #endregion

            #region Attendee deletes the calendar item created by organizer.
            responseMessage = this.DeleteSingleCalendarItem(Role.Attendee, itemIdByOrganizer, CalendarItemCreateOrDeleteOperationType.SendToNone);
            bool canDeleteNotOwnItem = null != responseMessage && responseMessage.ResponseClass == ResponseClassType.Success;
            #endregion

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R91
            bool isVerifiedR91 = canCreateOwnItem && canReadOwnItem && canUpdateOwnItem && canDeleteOwnItem && canReadNotOwnItem
                && canUpdateNotOwnItem && canDeleteNotOwnItem && !canCreateSubFolder;

            Site.Assert.IsTrue(
                isVerifiedR91,
                "Can create own item is {0};\n" +
                "Can read own item is {1};\n" +
                "Can edit own item is {2};\n " +
                "Can delete own item is {3};\n" +
                "Can read not own item is {4};\n" +
                "Can edit not own item is {5};\n" +
                "Can delete not own item is {6};\n" +
                "Can create subfolders is {7};\n",
                canCreateOwnItem,
                canReadOwnItem,
                canUpdateOwnItem,
                canDeleteOwnItem,
                canReadNotOwnItem,
                canUpdateNotOwnItem,
                canDeleteNotOwnItem,
                canCreateSubFolder);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR91,
                91,
                @"[In t:CalendarPermissionLevelType Simple Type] Editor: The user can create, read, edit and delete all items in the folder.");
        }
        public void MSOXWSMTGS_S01_TC23_CreateItemErrorMessageDispositionRequired()
        {
            #region Define a meeting to be created
            int timeInterval = this.TimeInterval;
            CalendarItemType meetingItem = new CalendarItemType();
            meetingItem.UID = Guid.NewGuid().ToString();
            meetingItem.Subject = this.Subject;
            meetingItem.Start = DateTime.Now.AddHours(timeInterval);
            meetingItem.StartSpecified = true;
            timeInterval++;
            meetingItem.End = DateTime.Now.AddHours(timeInterval);
            meetingItem.EndSpecified = true;
            meetingItem.Location = this.Location;
            meetingItem.RequiredAttendees = new AttendeeType[] { GetAttendeeOrResource(this.AttendeeEmailAddress) };
            meetingItem.OptionalAttendees = new AttendeeType[] { GetAttendeeOrResource(this.OrganizerEmailAddress) };
            #endregion

            #region Organizer creates a meeting with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll
            ItemInfoResponseMessageType item = this.CreateSingleCalendarItem(Role.Organizer, meetingItem, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll);
            Site.Assert.IsNotNull(item, "The meeting should be created successfully.");
            #endregion

            #region Attendee gets the meeting request message in the inbox
            MeetingRequestMessageType request = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.inbox, "IPM.Schedule.Meeting.Request", meetingItem.UID) as MeetingRequestMessageType;
            Site.Assert.IsNotNull(request, "The meeting request message should be found in attendee's Inbox folder after organizer calls CreateItem with CalendarItemCreateOrDeleteOperationType set to SendOnlyToAll.");
            #endregion

            #region Attendee calls CreateItem to accept the meeting request without setting MessageDisposition
            AcceptItemType acceptItem = new AcceptItemType();
            acceptItem.ReferenceItemId = new ItemIdType();
            acceptItem.ReferenceItemId.Id = request.ItemId.Id;
            NonEmptyArrayOfAllItemsType allItemArray = new NonEmptyArrayOfAllItemsType();
            allItemArray.Items = new ItemType[] { acceptItem };
            CreateItemType createItemRequest = new CreateItemType();
            createItemRequest.Items = allItemArray;
            createItemRequest.SendMeetingInvitationsSpecified = true;
            createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendOnlyToAll;
            CreateItemResponseType createItemResponse = this.MTGSAdapter.CreateItem(createItemRequest);

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R1342
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.ErrorMessageDispositionRequired,
                createItemResponse.ResponseMessages.Items[0].ResponseCode,
                1342,
                @"[In Messages] ErrorMessageDispositionRequired:This error code MUST be returned under the following conditions: 
                  [When the item that is being created or updated is a MessageType object. ]
                  For the CancelCalendarItemType, AcceptItemType, DeclineItemType, or TentativelyAcceptItemType response objects.");
            #endregion

            #region Attendee calls CreateItem to tentatively accept the meeting request without setting MessageDisposition
            TentativelyAcceptItemType tentativelyAcceptItem = new TentativelyAcceptItemType();
            tentativelyAcceptItem.ReferenceItemId = new ItemIdType();
            tentativelyAcceptItem.ReferenceItemId.Id = request.ItemId.Id;
            allItemArray = new NonEmptyArrayOfAllItemsType();
            allItemArray.Items = new ItemType[] { tentativelyAcceptItem };
            createItemRequest = new CreateItemType();
            createItemRequest.Items = allItemArray;
            createItemRequest.SendMeetingInvitationsSpecified = true;
            createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendOnlyToAll;
            createItemResponse = this.MTGSAdapter.CreateItem(createItemRequest);

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R1342
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.ErrorMessageDispositionRequired,
                createItemResponse.ResponseMessages.Items[0].ResponseCode,
                1342,
                @"[In Messages] ErrorMessageDispositionRequired:This error code MUST be returned under the following conditions: 
                  [When the item that is being created or updated is a MessageType object. ]
                  For the CancelCalendarItemType, AcceptItemType, DeclineItemType, or TentativelyAcceptItemType response objects.");
            #endregion

            #region Organizer cancels the meeting without setting MessageDisposition
            this.SwitchMTGSUser(Role.Organizer);
            CancelCalendarItemType cancelMeetingItem = new CancelCalendarItemType();
            cancelMeetingItem.ReferenceItemId = item.Items.Items[0].ItemId;
            allItemArray = new NonEmptyArrayOfAllItemsType();
            allItemArray.Items = new ItemType[] { cancelMeetingItem };
            createItemRequest = new CreateItemType();
            createItemRequest.Items = allItemArray;
            createItemRequest.SendMeetingInvitationsSpecified = true;
            createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendOnlyToAll;
            createItemResponse = this.MTGSAdapter.CreateItem(createItemRequest);

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R1342
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.ErrorMessageDispositionRequired,
                createItemResponse.ResponseMessages.Items[0].ResponseCode,
                1342,
                @"[In Messages] ErrorMessageDispositionRequired:This error code MUST be returned under the following conditions: 
                  [When the item that is being created or updated is a MessageType object. ]
                  For the CancelCalendarItemType, AcceptItemType, DeclineItemType, or TentativelyAcceptItemType response objects.");
            #endregion

            #region Clean up organizer's calendar folder, and attendee's inbox and calendar folders
            this.CleanupFoldersByRole(Role.Organizer, new List<DistinguishedFolderIdNameType>() { DistinguishedFolderIdNameType.calendar });
            this.CleanupFoldersByRole(Role.Attendee, new List<DistinguishedFolderIdNameType>() { DistinguishedFolderIdNameType.inbox, DistinguishedFolderIdNameType.calendar });
            #endregion
        }