public void MSOXWSFOLD_S08_TC01_AllOperationsWithAllOptionalElements()
        {
            #region Configure SOAP header

            this.ConfigureSOAPHeader();

            #endregion

            #region Create new folders in the inbox folder.

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(
                DistinguishedFolderIdNameType.inbox.ToString(),
                new string[] { "Custom Folder1", "Custom Folder2", "Custom Folder3", "Custom Folder4" },
                new string[] { "IPF.MyCustomFolderClass", "IPF.Appointment", "IPF.Contact", "IPF.Task" },
                null);

            // Set ExtendedProperty defined in BaseFolderType.
            PathToExtendedFieldType publishInAddressBook = new PathToExtendedFieldType();

            // A hexadecimal tag of the extended property.
            publishInAddressBook.PropertyTag = "0x671E";
            publishInAddressBook.PropertyType = MapiPropertyTypeType.Boolean;
            ExtendedPropertyType pubAddressbook = new ExtendedPropertyType();
            pubAddressbook.ExtendedFieldURI = publishInAddressBook;
            pubAddressbook.Item = "1";
            ExtendedPropertyType[] extendedProperties = new ExtendedPropertyType[1];
            extendedProperties[0] = pubAddressbook;

            createFolderRequest.Folders[0].ExtendedProperty = extendedProperties;
            createFolderRequest.Folders[1].ExtendedProperty = extendedProperties;
            createFolderRequest.Folders[2].ExtendedProperty = extendedProperties;
            createFolderRequest.Folders[3].ExtendedProperty = extendedProperties;

            // Define a permissionSet with all optional elements
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].ReadItems = new PermissionReadAccessType();
            permissionSet.Permissions[0].ReadItems = PermissionReadAccessType.FullDetails;
            permissionSet.Permissions[0].ReadItemsSpecified = true;
            permissionSet.Permissions[0].CanCreateItems = true;
            permissionSet.Permissions[0].CanCreateItemsSpecified = true;
            permissionSet.Permissions[0].CanCreateSubFolders = true;
            permissionSet.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSet.Permissions[0].IsFolderVisible = true;
            permissionSet.Permissions[0].IsFolderVisibleSpecified = true;
            permissionSet.Permissions[0].IsFolderContact = true;
            permissionSet.Permissions[0].IsFolderContactSpecified = true;
            permissionSet.Permissions[0].IsFolderOwner = true;
            permissionSet.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSet.Permissions[0].IsFolderContact = true;
            permissionSet.Permissions[0].IsFolderContactSpecified = true;
            permissionSet.Permissions[0].EditItems = new PermissionActionType();
            permissionSet.Permissions[0].EditItems = PermissionActionType.All;
            permissionSet.Permissions[0].EditItemsSpecified = true;
            permissionSet.Permissions[0].DeleteItems = new PermissionActionType();
            permissionSet.Permissions[0].DeleteItems = PermissionActionType.All;
            permissionSet.Permissions[0].DeleteItemsSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // Set PermissionSet for FolderType folder.
            ((FolderType)createFolderRequest.Folders[0]).PermissionSet = permissionSet;

            // Set PermissionSet for ContactsType folder.
            ((ContactsFolderType)createFolderRequest.Folders[2]).PermissionSet = permissionSet;

            // Set PermissionSet for TasksFolderType folder.
            ((TasksFolderType)createFolderRequest.Folders[3]).PermissionSet = permissionSet;

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

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

            // Folder ids.
            FolderIdType[] folderIds = new FolderIdType[createFolderResponse.ResponseMessages.Items.Length];

            for (int index = 0; index < createFolderResponse.ResponseMessages.Items.Length; index++)
            {
                Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, createFolderResponse.ResponseMessages.Items[index].ResponseClass, "Folder should be created successfully!");

                // Save folder ids.
                folderIds[index] = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[index]).Folders[0].FolderId;

                // Save the new created folder's folder id.
                this.NewCreatedFolderIds.Add(folderIds[index]);
            }

            #endregion

            #region Create a managedfolder

            CreateManagedFolderRequestType createManagedFolderRequest = this.GetCreateManagedFolderRequest(Common.GetConfigurationPropertyValue("ManagedFolderName1", this.Site));

            // Add an email address into request.
            EmailAddressType mailBox = new EmailAddressType()
            {
                EmailAddress = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site)
            };

            createManagedFolderRequest.Mailbox = mailBox;

            // Create the specified managed folder.
            CreateManagedFolderResponseType createManagedFolderResponse = this.FOLDAdapter.CreateManagedFolder(createManagedFolderRequest);

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

            // Save the new created managed folder's folder id.
            FolderIdType newFolderId = ((FolderInfoResponseMessageType)createManagedFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Get the new created folders

            // GetFolder request.
            GetFolderType getCreatedFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, folderIds);

            // Get the new created folder.
            GetFolderResponseType getCreatedFolderResponse = this.FOLDAdapter.GetFolder(getCreatedFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getCreatedFolderResponse, 4, this.Site);

            for (int index = 0; index < getCreatedFolderResponse.ResponseMessages.Items.Length; index++)
            {
                Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, getCreatedFolderResponse.ResponseMessages.Items[index].ResponseClass, "Folder information should be returned!");
            }

            #endregion

            #region Update the new created folders

            // UpdateFolder request.
            UpdateFolderType updateFolderRequest = this.GetUpdateFolderRequest(
                new string[] { "Folder", "CalendarFolder", "ContactsFolder", "TasksFolder" },
                new string[] { "SetFolderField", "SetFolderField", "SetFolderField", "SetFolderField" },
                folderIds);

            // Update the folders' properties.
            UpdateFolderResponseType updateFolderResponse = this.FOLDAdapter.UpdateFolder(updateFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(updateFolderResponse, 4, this.Site);

            for (int index = 0; index < updateFolderResponse.ResponseMessages.Items.Length; index++)
            {
                Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, updateFolderResponse.ResponseMessages.Items[index].ResponseClass, "Folder should be updated successfully!");
            }

            #endregion

            #region Copy the updated folders to "drafts" folder

            // Copy the folders into "drafts" folder
            CopyFolderType copyFolderRequest = this.GetCopyFolderRequest(DistinguishedFolderIdNameType.drafts.ToString(), folderIds);

            // Copy the folders.
            CopyFolderResponseType copyFolderResponse = this.FOLDAdapter.CopyFolder(copyFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(copyFolderResponse, 4, this.Site);

            // Copied Folders' id.
            FolderIdType[] copiedFolderIds = new FolderIdType[copyFolderResponse.ResponseMessages.Items.Length];

            for (int index = 0; index < copyFolderResponse.ResponseMessages.Items.Length; index++)
            {
                Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, copyFolderResponse.ResponseMessages.Items[index].ResponseClass, "Folder should be updated successfully!");

                // Variable to save the folders.
                copiedFolderIds[index] = ((FolderInfoResponseMessageType)copyFolderResponse.ResponseMessages.Items[index]).Folders[0].FolderId;

                // Save the copied folders' folder id.
                this.NewCreatedFolderIds.Add(copiedFolderIds[index]);
            }

            #endregion

            #region Move the updated folders to "deleteditems" folder

            // MoveFolder request.
            MoveFolderType moveFolderRequest = new MoveFolderType();

            // Set the request's folderId field.
            moveFolderRequest.FolderIds = folderIds;

            // Set the request's destFolderId field.
            DistinguishedFolderIdType toFolderId = new DistinguishedFolderIdType();
            toFolderId.Id = DistinguishedFolderIdNameType.deleteditems;
            moveFolderRequest.ToFolderId = new TargetFolderIdType();
            moveFolderRequest.ToFolderId.Item = toFolderId;

            // Move the specified folders.
            MoveFolderResponseType moveFolderResponse = this.FOLDAdapter.MoveFolder(moveFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(moveFolderResponse, 4, this.Site);

            for (int index = 0; index < moveFolderResponse.ResponseMessages.Items.Length; index++)
            {
                Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, moveFolderResponse.ResponseMessages.Items[index].ResponseClass, "Folder should be updated successfully!");
            }
            #endregion

            #region Delete all folders

            // All folder ids.
            FolderIdType[] allFolderIds = new FolderIdType[folderIds.Length + copiedFolderIds.Length];

            for (int index = 0; index < allFolderIds.Length / 2; index++)
            {
                allFolderIds[index] = folderIds[index];
                allFolderIds[index + folderIds.Length] = copiedFolderIds[index];
            }

            // DeleteFolder request.
            DeleteFolderType deleteFolderRequest = this.GetDeleteFolderRequest(DisposalType.HardDelete, allFolderIds);

            // Delete the specified folder.
            DeleteFolderResponseType deleteFolderResponse = this.FOLDAdapter.DeleteFolder(deleteFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(deleteFolderResponse, 8, this.Site);

            for (int index = 0; index < deleteFolderResponse.ResponseMessages.Items.Length; index++)
            {
                Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, deleteFolderResponse.ResponseMessages.Items[index].ResponseClass, "Folder should be updated successfully!");
            }

            #endregion
        }
        public void MSOXWSFOLD_S06_TC04_UpdateFolderWithDeleteFolderFieldType()
        {
            #region Create a new folder in the inbox folder

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].CanCreateSubFolders = true;
            permissionSet.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSet.Permissions[0].IsFolderOwner = true;
            permissionSet.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Update Folder Operation.

            // UpdateFolder request to delete folder permission value.
            UpdateFolderType updateFolderRequest = this.GetUpdateFolderRequest("Folder", "DeleteFolderField", newFolderId);

            // Update the specific folder's properties.
            UpdateFolderResponseType updateFolderResponse = this.FOLDAdapter.UpdateFolder(updateFolderRequest);

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

            #endregion

            #region Switch user

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a subfolder under the folder created in step 1 with User2's credential

            // CreateFolder request.
            CreateFolderType createFolderInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderInSharedMailboxRequest);

            // Check the length.
            Site.Assert.AreEqual<int>(
                1,
                createFolderInSharedMailboxResponse.ResponseMessages.Items.GetLength(0),
                "Expected Item Count: {0}, Actual Item Count: {1}",
                1,
                createFolderInSharedMailboxResponse.ResponseMessages.Items.GetLength(0));

            // Permission have been deleted so create operation should be failed.
            bool isPermissionDeleted = createFolderInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass.Equals(ResponseClassType.Error);

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R583
            // One permission set which set in CreateFolder is deleted when calling UpdateFolder.
            this.Site.CaptureRequirementIfIsTrue(
                isPermissionDeleted,
                583,
                @"[In t:DeleteFolderFieldType Complex Type]The DeleteFolderFieldType complex type represents an UpdateFolder operation to delete a property from a folder.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R5261
            this.Site.CaptureRequirementIfIsTrue(
                isPermissionDeleted,
                5261,
                @"[In t:NonEmptyArrayOfFolderChangeDescriptionsType Complex Type]DeleteFolderField represents an UpdateFolder operation to delete a property from a folder.");
        }
        public void MSOXWSFOLD_S07_TC01_FolderPermissionCustomLevelAllPermissionEnabled()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a folder in the User1's inbox folder, and enable all permission for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].ReadItems = new PermissionReadAccessType();
            permissionSet.Permissions[0].ReadItems = PermissionReadAccessType.FullDetails;
            permissionSet.Permissions[0].ReadItemsSpecified = true;
            permissionSet.Permissions[0].CanCreateItems = true;
            permissionSet.Permissions[0].CanCreateItemsSpecified = true;
            permissionSet.Permissions[0].CanCreateSubFolders = true;
            permissionSet.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSet.Permissions[0].IsFolderVisible = true;
            permissionSet.Permissions[0].IsFolderVisibleSpecified = true;
            permissionSet.Permissions[0].IsFolderContact = true;
            permissionSet.Permissions[0].IsFolderContactSpecified = true;
            permissionSet.Permissions[0].IsFolderOwner = true;
            permissionSet.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSet.Permissions[0].IsFolderContact = true;
            permissionSet.Permissions[0].IsFolderContactSpecified = true;
            permissionSet.Permissions[0].EditItems = new PermissionActionType();
            permissionSet.Permissions[0].EditItems = PermissionActionType.All;
            permissionSet.Permissions[0].EditItemsSpecified = true;
            permissionSet.Permissions[0].DeleteItems = new PermissionActionType();
            permissionSet.Permissions[0].DeleteItems = PermissionActionType.All;
            permissionSet.Permissions[0].DeleteItemsSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a subfolder under the folder created in step 1 with User2's credential

            // CreateFolder request.
            CreateFolderType createFolderInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderInSharedMailboxRequest);

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

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R4302
            // Successful Creating sub folder indicates that UserId specifies a user identifier
            this.Site.CaptureRequirementIfAreEqual<ResponseClassType>(
                ResponseClassType.Success,
                createFolderInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass,
                4302,
                @"[In t:BasePermissionType Complex Type]UserId specifies a user identifier.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R4702
            this.Site.CaptureRequirementIfAreEqual<ResponseClassType>(
                ResponseClassType.Success,
                createFolderInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass,
                4702,
                @"[In t:BasePermissionType Complex Type][CanCreateSubFolders]A value of true indicates that the client can create a sub folder. ");

            #region Edit items User2 doesn't own with User2's credential

            this.CanEditNotOwnedItem = this.UpdateItemSubject(itemIdNotOwned);
            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);
            this.CanDeleteNotOwnedItem = this.DeleteItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;
            if (this.CanCreateItem)
            {
                this.CanEditOwnedItem = this.UpdateItemSubject(itemIdOwned);
                this.CanReadOwnedItem = this.GetItem(itemIdOwned);
                this.CanDeleteOwnedItem = this.DeleteItem(itemIdOwned);
            }

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R46
            // CanCreateItems has been set to true in request and if item can be created this requirement can be captured.
            this.Site.CaptureRequirementIfIsTrue(
                this.CanCreateItem,
                46,
                @"[In t:BasePermissionType Complex Type][CanCreateItems]A value of ""true"" indicates that the client can create an item. ");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R51003
            // Value "All" has been set to EditItem, if items that user owns and doesn't own can be edited this requirement can be captured.
            bool isVerifiedR51003 = this.CanEditOwnedItem && this.CanEditNotOwnedItem;

            Site.Assert.IsTrue(
               isVerifiedR51003,
               "Can edit owned item expected to be \"true\" and actual is {0};\n" +
               "Can edit not owned item expected to be \"true\" and actual is {1};\n ",
               this.CanEditOwnedItem,
               this.CanEditNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR51003,
                51003,
                @"[In t:BasePermissionType Complex Type]The type of element EditItems is ""All"", which indicates that the user has permission to perform the action on all items in the folder.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R52003
            // Value "All" has been set to DeleteItem, if items that user owns and doesn't own can be deleted this requirement can be captured.
            bool isVerifiedR52003 = this.CanDeleteOwnedItem && this.CanDeleteNotOwnedItem;

            Site.Assert.IsTrue(
               isVerifiedR52003,
               "Can delete owned item expected to be \"true\" and actual is {0};\n" +
               "Can delete not owned item expected to be \"true\" and actual is {1};\n ",
               this.CanDeleteOwnedItem,
               this.CanDeleteNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR52003,
                52003,
                @"[In t:BasePermissionType Complex Type]The type of element DeleteItems is ""All"", which indicates that the user has permission to perform the action on all items in the folder.");

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

            // Permission is set and schema is verified in adapter so this requirement can be captured.
            this.Site.CaptureRequirement(
                98,
                @"[In t:FolderType Complex Type]The type of element PermissionSet is t:PermissionSetType (section 2.2.4.14).");

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

            // Permission is set and authorized user get related permissions so this requirement can be captured.
            this.Site.CaptureRequirement(
                9802,
                @"[In t:FolderType Complex Type]PermissionSet specifies all permissions that are configured for a folder.");

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

            // Permission is set and authorized user get related permissions so this requirement can be captured.
            this.Site.CaptureRequirement(
                1182,
                @"[In t:PermissionSetType Complex Type][Permissions] specifies a collection of permissions for a folder.");

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

            // Permission is set and authorized user get related permissions so this requirement can be captured.
            this.Site.CaptureRequirement(
                154,
                @"[In t:PermissionLevelType Simple Type]The value Custom means the user has custom access permissions on the folder.");
        }
        public void MSOXWSFOLD_S07_TC03_FolderPermissionOwnerLevel()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a folder in the User1's inbox folder, and enable Owner permission for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Owner;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);
            permissionSet.Permissions[0].UserId.DisplayName = Common.GetConfigurationPropertyValue("User2Name", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;

            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Create a sub folder in the folder created in step 1 with User1's credential

            // CreateFolder request.
            CreateFolderType createFolderNotOwnedInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderNotOwnedInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderNotOwnedInSharedMailboxRequest);

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

            // Save the new created folder's folder id.
            FolderIdType newFolderIdInSharedMailboxNotOwned = ((FolderInfoResponseMessageType)createFolderNotOwnedInSharedMailboxResponse.ResponseMessages.Items[0]).Folders[0].FolderId;

            #endregion

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Get the new created folder in step 1 with User2's credential

            // GetFolder request.
            GetFolderType getFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, newFolderId);
            getFolderRequest.FolderShape.AdditionalProperties = new BasePathToElementType[]
                    {
                        new PathToUnindexedFieldType()
                        {
                            FieldURI = UnindexedFieldURIType.folderPermissionSet
                        }
                    };

            // Get the new created folder.
            GetFolderResponseType getFolderResponse = this.FOLDAdapter.GetFolder(getFolderRequest);

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

            // Verify the folder is created successfully.
            FolderInfoResponseMessageType allFoldersInformation = (FolderInfoResponseMessageType)getFolderResponse.ResponseMessages.Items[0];

            #endregion

            #region Update Folder created in step 2 with User2's credential

            // UpdateFolder request.
            UpdateFolderType updateSubFolderNotOwnedRequest = this.GetUpdateFolderRequest("Folder", "SetFolderField", newFolderIdInSharedMailboxNotOwned);

            // Update the specific folder's properties.
            UpdateFolderResponseType updateSubFolderNotOwnedResponse = this.FOLDAdapter.UpdateFolder(updateSubFolderNotOwnedRequest);

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

            this.CanEditSubFolder = ResponseClassType.Success == updateSubFolderNotOwnedResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Get the new created Subfolder in step 2 with User2's credential

            // GetFolder request.
            GetFolderType getSubFolderNotOwnedRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, newFolderIdInSharedMailboxNotOwned);

            // Get the new created folder.
            GetFolderResponseType getSubFolderNotOwnedResopnse = this.FOLDAdapter.GetFolder(getSubFolderNotOwnedRequest);

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

            this.CanReadSubFolder = ResponseClassType.Success == getSubFolderNotOwnedResopnse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Delete the created folder in step 2 with User2's credential

            // DeleteFolder request.
            DeleteFolderType deleteFolderInSharedMailBoxRequest = this.GetDeleteFolderRequest(DisposalType.HardDelete, newFolderIdInSharedMailboxNotOwned);

            // Delete the specified folder.
            DeleteFolderResponseType deleteFolderInSharedMailBoxResponse = this.FOLDAdapter.DeleteFolder(deleteFolderInSharedMailBoxRequest);

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

            this.CanDeleteSubFolder = ResponseClassType.Success == deleteFolderInSharedMailBoxResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Create a subfolder under the folder created in step 1 with User2's credential

            // CreateFolder request.
            CreateFolderType createFolderInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderInSharedMailboxRequest);

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

            this.CanCreateSubFolder = ResponseClassType.Success == createFolderInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Edit items that User2 doesn't own with User2's credential

            this.CanEditNotOwnedItem = this.UpdateItemSubject(itemIdNotOwned);
            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);
            this.CanDeleteNotOwnedItem = this.DeleteItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;
            if (this.CanCreateItem)
            {
                this.CanEditOwnedItem = this.UpdateItemSubject(itemIdOwned);
                this.CanReadOwnedItem = this.GetItem(itemIdOwned);
                this.CanDeleteOwnedItem = this.DeleteItem(itemIdOwned);
            }

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R146
            bool isVerifiedR146 = this.CanCreateSubFolder && this.CanCreateItem && this.CanReadOwnedItem && this.CanEditOwnedItem && this.CanDeleteOwnedItem && this.CanReadNotOwnedItem && this.CanEditNotOwnedItem && this.CanDeleteNotOwnedItem;

            Site.Assert.IsTrue(
                isVerifiedR146,
                "Can create subfolder expected to be \"true\" and actual is {0};\n" +
                "Can create item expected to be \"true\" and actual is {1};\n" +
                "Can read owned item expected to be \"true\" and actual is {2};\n" +
                "Can edit owned item expected to be \"true\" and actual is {3};\n" +
                "Can delete owned item expected to be \"true\" and actual is {4};\n" +
                "Can read not owned item expected to be \"true\" and actual is {5};\n" +
                "Can edit not owned item expected to be \"true\" and actual is {6};\n" +
                "Can delete not owned item expected to be \"true\" and actual is {7};\n ",
                this.CanCreateSubFolder,
                this.CanCreateItem,
                this.CanReadOwnedItem,
                this.CanEditOwnedItem,
                this.CanDeleteOwnedItem,
                this.CanReadNotOwnedItem,
                this.CanEditNotOwnedItem,
                this.CanDeleteNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR146,
                146,
                @"[In t:PermissionLevelType Simple Type]The value Owner means the user can create, read, edit, and delete all items in the folder and create subfolders. The user is both folder owner and folder contact.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R810107
            bool isVerifiedR810107 = allFoldersInformation.Folders[0].EffectiveRights.Delete == true && this.CanDeleteOwnedItem && this.CanDeleteNotOwnedItem && this.CanDeleteSubFolder;

            Site.Assert.IsTrue(
                isVerifiedR810107,
                "Delete to be \"true\" and actual is {0};\n" +
                "Can delete owned item expected to be \"true\" and actual is {1};\n" +
                "Can delete not owned item expected to be \"true\" and actual is {2};\n" +
                "Can delete subfolder item expected to be \"true\" and actual is {3};\n ",
                allFoldersInformation.Folders[0].EffectiveRights.Delete,
                this.CanDeleteOwnedItem,
                this.CanDeleteNotOwnedItem,
                this.CanDeleteSubFolder);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR810107,
                810107,
                @"[In t:BaseFolderType Complex Type] Value ""true"" of the element Delete of EffectiveRights indicates a client can delete a folder or item.");
            
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSFOLD_R8101011");

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R8101011
            bool isVerifiedR8101011 = allFoldersInformation.Folders[0].EffectiveRights.Read == true && this.CanReadOwnedItem && this.CanReadNotOwnedItem && this.CanReadSubFolder;

            Site.Assert.IsTrue(
                isVerifiedR8101011,
                "Read to be \"true\" and actual is {0};\n" +
                "Can read owned item expected to be \"true\" and actual is {1};\n" +
                "Can read not owned item expected to be \"true\" and actual is {2};\n" +
                "Can read subfolder item expected to be \"true\" and actual is {3};\n ",
                allFoldersInformation.Folders[0].EffectiveRights.Read,
                this.CanReadOwnedItem,
                this.CanReadNotOwnedItem,
                this.CanReadSubFolder);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR8101011,
                8101011,
                @"[In t:BaseFolderType Complex Type] Value ""true"" of the element Read of EffectiveRights indicates a client can read a folder or item.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R810109
            bool isVerifiedR810109 = allFoldersInformation.Folders[0].EffectiveRights.Modify == true && this.CanEditOwnedItem && this.CanEditNotOwnedItem && this.CanEditSubFolder;

            Site.Assert.IsTrue(
                isVerifiedR810109,
                "Modify to be \"true\" and actual is {0};\n" +
                "Can edit owned item expected to be \"true\" and actual is {1};\n" +
                "Can edit not owned item expected to be \"true\" and actual is {2};\n" +
                "Can edit subfolder item expected to be \"true\" and actual is {3};\n ",
                allFoldersInformation.Folders[0].EffectiveRights.Modify,
                this.CanEditOwnedItem,
                this.CanEditNotOwnedItem,
                this.CanEditSubFolder);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR810109,
                810109,
                @"[In t:BaseFolderType Complex Type] Value ""true"" of the element Modify of EffectiveRights indicates a client can modify a folder or item.");

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

            // Permission is set in create folder request and permissions are successfully applied, this requirement can be captured.
            this.Site.CaptureRequirement(
                1182,
                @"[In t:PermissionSetType Complex Type][Permissions] specifies a collection of permissions for a folder.");

            UserIdType defaultUserId = ((BasePermissionType)((FolderType)allFoldersInformation.Folders[0]).PermissionSet.Permissions[0]).UserId;
            UserIdType anonymousUserId = ((BasePermissionType)((FolderType)allFoldersInformation.Folders[0]).PermissionSet.Permissions[1]).UserId;
            UserIdType authorizedUserId = ((BasePermissionType)((FolderType)allFoldersInformation.Folders[0]).PermissionSet.Permissions[2]).UserId;

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

            // Verify MS-OXWSCDATA requirement: MS-OXWSCDATA_R1298
            // SID is returned and schema is verified in adapter and the specified user has gotten specified permission, so this requirement can be captured.
            this.Site.CaptureRequirementIfIsNotNull(
                authorizedUserId.SID,
                "MS-OXWSCDATA",
                1298,
                @"[In t:UserIdType Complex Type] The element ""SID"" with type ""xs:string"" specifies the security descriptor definition language (SSDL) form of the security identifier (SID) for a user.");

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

            // Verify MS-OXWSCDATA requirement: MS-OXWSCDATA_R1299
            // PrimarySmtpAddress is returned and schema is verified in adapter and the specified user has gotten specified permission, so this requirement can be captured.
            this.Site.CaptureRequirementIfIsNotNull(
                authorizedUserId.PrimarySmtpAddress,
                "MS-OXWSCDATA",
                1299,
                @"[In t:UserIdType Complex Type] The element ""PrimarySmtpAddress"" with type ""xs:string"" specifies the primary SMTP address of an account.");

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

            // Verify MS-OXWSCDATA requirement: MS-OXWSCDATA_R1300
            // Display name is returned and schema is verified in adapter and the specified user has gotten specified permission, so this requirement can be captured.
            this.Site.CaptureRequirementIfIsNotNull(
                authorizedUserId.DisplayName,
                "MS-OXWSCDATA",
                1300,
                @"[In t:UserIdType Complex Type] The element ""DisplayName"" with type ""xs:string"" specifies the user name for display.");

            Site.Assert.AreEqual<DistinguishedUserType>(DistinguishedUserType.Default, defaultUserId.DistinguishedUser, "Default user's user id type should be default!");
            Site.Assert.AreEqual<DistinguishedUserType>(DistinguishedUserType.Anonymous, anonymousUserId.DistinguishedUser, "Anonymous user's user id type should be anonymous!");

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

            // The account is a default user and anonymous user.
            this.Site.CaptureRequirement(
                "MS-OXWSCDATA",
                1301,
                @"[In t:UserIdType Complex Type] [The element ""DistinguishedUser"" with type ""t:DistinguishedUserType"" specifies a value that identifies the Anonymous and Default user accounts for delegate access.");
        }
        public void MSOXWSFOLD_S07_TC16_FolderPermissionLevelContributor()
        {
            #region Switch to User1
            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));
            #endregion

            #region Create a folder in the User1's inbox folder, and enable Contributor permission for User2
            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Contributor;

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);
            #endregion

            #region Switch to User2
            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));
            #endregion

            #region Create an item in the folder created in step 1 with User2's credential
            string itemName = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemInFolder = this.CreateItem(Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemName);
            Site.Assert.IsNotNull(itemInFolder, "Item should be created successfully!");
            #endregion

            #region Read the new item
            bool canReadItem = this.GetItem(itemInFolder);
            #endregion

            if (Common.IsRequirementEnabled(1531, this.Site))
            {
                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSFOLD_R1531");

                // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R1531, if User2 can read the item, this capture can be verified.
                this.Site.CaptureRequirementIfIsTrue(
                    canReadItem,
                    1531,
                    @"[In Appendix C: Product Behavior] The implementation does support Contributor in PermissionLevelType specifies that the user can create items in the folder and read those items. (<9> Section 2.2.5.3:  In Microsoft Exchange Server 2013 Service Pack 1 (SP1) and Exchange 2016 the user can create items in the folder and read those items.)");
            }

            if (Common.IsRequirementEnabled(1532, this.Site))
            {
                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSFOLD_R1532");

                // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R1531, if User2 can not read the item, this capture can be verified.
                this.Site.CaptureRequirementIfIsFalse(
                    canReadItem,
                    1532,
                    @"[In Appendix C: Product Behavior] The implementation does support Contributor in PermissionLevelType specifies that the user can create items in the folder but cannot read any items in the folder. (Exchange 2007 and Exchange 2010 follow this behavior.)");
            }
        }
        public void MSOXWSFOLD_S07_TC02_FolderPermissionCustomLevelAllPermissionDisabled()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a folder in the User1's inbox folder, and disable all permission for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].CanCreateItems = false;
            permissionSet.Permissions[0].CanCreateItemsSpecified = true;
            permissionSet.Permissions[0].CanCreateSubFolders = false;
            permissionSet.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSet.Permissions[0].IsFolderVisible = false;
            permissionSet.Permissions[0].IsFolderVisibleSpecified = true;
            permissionSet.Permissions[0].IsFolderContact = false;
            permissionSet.Permissions[0].IsFolderContactSpecified = true;
            permissionSet.Permissions[0].IsFolderOwner = false;
            permissionSet.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSet.Permissions[0].IsFolderContact = false;
            permissionSet.Permissions[0].IsFolderContactSpecified = true;
            permissionSet.Permissions[0].EditItems = new PermissionActionType();
            permissionSet.Permissions[0].EditItems = PermissionActionType.None;
            permissionSet.Permissions[0].EditItemsSpecified = true;
            permissionSet.Permissions[0].DeleteItems = new PermissionActionType();
            permissionSet.Permissions[0].DeleteItems = PermissionActionType.None;
            permissionSet.Permissions[0].DeleteItemsSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R7802
            // Extended property is not set in "CreateFolder" operation.
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.NoError,
                createFolderResponse.ResponseMessages.Items[0].ResponseCode,
                7802,
                @"[In t:BaseFolderType Complex Type]This element [ExtendedProperty] is not present, server responses NO_ERROR.");

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a subfolder under the folder created in step 1 with User2's credential

            // CreateFolder request.
            CreateFolderType createFolderInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderInSharedMailboxRequest);

            // Check the length.
            Site.Assert.AreEqual<int>(
                1,
                createFolderInSharedMailboxResponse.ResponseMessages.Items.GetLength(0),
                "Expected Item Count: {0}, Actual Item Count: {1}",
                1,
                createFolderInSharedMailboxResponse.ResponseMessages.Items.GetLength(0));

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R47001
            this.Site.CaptureRequirementIfAreEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass,
                47001,
                @"[In t:BasePermissionType Complex Type][CanCreateSubFolders]A value of ""false"" indicates that the client cannot create a sub folder. ");

            #region Edit items that User2 doesn't own with User2's credential

            this.CanEditNotOwnedItem = this.UpdateItemSubject(itemIdNotOwned);
            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);
            this.CanDeleteNotOwnedItem = this.DeleteItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;
            if (this.CanCreateItem)
            {
                this.CanEditOwnedItem = this.UpdateItemSubject(itemIdOwned);
                this.CanReadOwnedItem = this.GetItem(itemIdOwned);
                this.CanDeleteOwnedItem = this.DeleteItem(itemIdOwned);
            }
            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R4502
            this.Site.CaptureRequirementIfIsFalse(
                this.CanCreateItem,
                4502,
                @"[In t:BasePermissionType Complex Type][CanCreateItems]A value of ""false"" indicates that the client cannot create an item.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R51001
            // Value "None" has been set to EidtItem, if items that user owns and doesn't own can be edited this requirement can be captured.
            bool isVerifiedR51001 = !this.CanEditOwnedItem && !this.CanEditNotOwnedItem;

            Site.Assert.IsTrue(
               isVerifiedR51001,
               "Can edit owned item expected to be \"false\" and actual is {0};\n" +
               "Can edit not owned item expected to be \"false\" and actual is {1};\n ",
               this.CanEditOwnedItem,
               this.CanEditNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR51001,
                51001,
                @"[In t:BasePermissionType Complex Type] The type of element EditItems is ""None"", which indicates that the user does not have permission to perform the action on any items in the folder.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R52001
            bool isVerifyR52001 = !this.CanDeleteOwnedItem && !this.CanDeleteNotOwnedItem;

            Site.Assert.IsTrue(
                isVerifyR52001,
                "Can delete owned item expected to be \"false\" and actual is {0};\n" +
                "Can delete not owned item expected to be \"false\" and actual is {1};\n ",
                this.CanDeleteOwnedItem,
                this.CanDeleteNotOwnedItem);

            // Value "None" has been set to DeleteItem, if items that user owns and doesn't own can be deleted this requirement can be captured.
            this.Site.CaptureRequirementIfIsTrue(
                isVerifyR52001,
                52001,
                @"[In t:BasePermissionType Complex Type] The type of element DeleteItems is ""None"", which indicates that the user does not have permission to perform the action on any items in the folder.");
        }
        public void MSOXWSFOLD_S07_TC14_FolderPermissionReadItemNone()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a folder in the User1's inbox folder, and enable ReadItem with none permission for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].ReadItems = new PermissionReadAccessType();
            permissionSet.Permissions[0].ReadItems = PermissionReadAccessType.None;
            permissionSet.Permissions[0].ReadItemsSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Read items that User2 doesn't own with User2's credential

            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", Site) + "@" + Common.GetConfigurationPropertyValue("Domain", Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;

            if (this.CanCreateItem)
            {
                this.CanReadOwnedItem = this.GetItem(itemIdOwned);
            }
            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R157
            // If all items can't be read, this requirement can be captured.
            bool isVerifiedR157 = !this.CanReadOwnedItem && !this.CanReadNotOwnedItem;

            Site.Assert.IsTrue(
               isVerifiedR157,
               "Can read owned item expected to be \"false\" and actual is {0};\n" +
               "Can read not owned item expected to be \"false\" and actual is {1};\n ",
               this.CanReadOwnedItem,
               this.CanReadNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR157,
                157,
                @"[In t:PermissionReadAccessType Simple Type]The value None means the user does not have permission to read items in the folder.");
        }
        public void MSOXWSFOLD_S07_TC15_FolderPermissionLevelNotCustom()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(54911, this.Site), @"Exchange 2007 and Exchange 2010 will return an ErrorInvalidPermissionSettings ([MS-OXWSCDATA] section 2.2.5.24) response code if any field of BasePermissionType other than UserId field is set, and the PermissionLevel field is not set to ""Custom"".");

            #region Switch to User1
            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));
            #endregion

            #region Create a folder in the User1's inbox folder, and enable Contributor permission for User2
            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // Set the field CanCreateSubFolders to 'true', and the PermissionLevel field is not set to 'Custom'
            permissionSet.Permissions[0].CanCreateSubFolders = true;
            permissionSet.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Contributor;

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

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

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

            // CanCreateSubFolders is set and the PermissionLevel field is not set to 'Custom', the expected ResponseCode is ErrorInvalidPermissionSettings
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.ErrorInvalidPermissionSettings,
                createFolderResponse.ResponseMessages.Items[0].ResponseCode,
                54911,
                @"[In Appendix C: Product Behavior] Implementation does return an ErrorInvalidPermissionSettings response code if any field of BasePermissionType other than UserId field is set, and the PermissionLevel field is not set to ""Custom"". (<7> Section 2.2.4.15:  Exchange 2007 and Exchange 2010 will return an ErrorInvalidPermissionSettings ([MS-OXWSCDATA] section 2.2.5.24) response code if any field of BasePermissionType other than UserId field is set, and the PermissionLevel field is not set to ""Custom"".)");
        }
        public void MSOXWSFOLD_S07_TC12_FolderPermissionWithOrWithoutAllSet()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a new folder without any permissions in the inbox folder

            // Configure permission set.
            PermissionSetType permissionSetFirst = new PermissionSetType();
            permissionSetFirst.Permissions = new PermissionType[1];
            permissionSetFirst.Permissions[0] = new PermissionType();
            permissionSetFirst.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSetFirst.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSetFirst.Permissions[0].UserId = new UserIdType();
            permissionSetFirst.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequestFirst = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSetFirst });

            // Create a new folder.
            CreateFolderResponseType createFolderResponseFirst = this.FOLDAdapter.CreateFolder(createFolderRequestFirst);

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

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R122302
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                122302,
                @"[In t:PermissionType Complex Type]This element [ReadItems] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R460102
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                460102,
                @"[In t:BasePermissionType Complex Type]This element [CanCreateItems] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R470302
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                470302,
                @"[In t:BasePermissionType Complex Type]This element [CanCreateSubFolders] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R480302
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                480302,
                @"[In t:BasePermissionType Complex Type]This element [IsFolderOwner] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R490302
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                490302,
                @"[In t:BasePermissionType Complex Type]This element [IsFolderVisible] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R500302
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                500302,
                @"[In t:BasePermissionType Complex Type]This element [IsFolderContact] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R510202
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                510202,
                @"[In t:BasePermissionType Complex Type]This element [EditItems] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R520202
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                520202,
                @"[In t:BasePermissionType Complex Type]This element [DeleteItems] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R120302
            // Since the UnknownEntries is not set and server responds NoError, this requirement can be captured.
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.NoError,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseCode,
                120302,
                @"[In t:PermissionSetType Complex Type]This element [UnknownEntries] is not present, server responses NO_ERROR.");

            // Save the new created folder's folder id.
            FolderIdType firstFolderId = ((FolderInfoResponseMessageType)createFolderResponseFirst.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(firstFolderId);

            #endregion

            #region Create a new folder with all permissions in the inbox folder

            // Configure permission set.
            PermissionSetType permissionSetSecond = new PermissionSetType();
            permissionSetSecond.Permissions = new PermissionType[1];
            permissionSetSecond.Permissions[0] = new PermissionType();
            permissionSetSecond.Permissions[0].ReadItems = new PermissionReadAccessType();
            permissionSetSecond.Permissions[0].ReadItems = PermissionReadAccessType.FullDetails;
            permissionSetSecond.Permissions[0].CanCreateItemsSpecified = true;
            permissionSetSecond.Permissions[0].CanCreateItems = false;
            permissionSetSecond.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSetSecond.Permissions[0].CanCreateSubFolders = false;
            permissionSetSecond.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSetSecond.Permissions[0].IsFolderOwner = false;
            permissionSetSecond.Permissions[0].IsFolderVisibleSpecified = true;
            permissionSetSecond.Permissions[0].IsFolderVisible = false;
            permissionSetSecond.Permissions[0].IsFolderContactSpecified = true;
            permissionSetSecond.Permissions[0].IsFolderContact = false;
            permissionSetSecond.Permissions[0].EditItemsSpecified = true;
            permissionSetSecond.Permissions[0].EditItems = PermissionActionType.All;
            permissionSetSecond.Permissions[0].DeleteItemsSpecified = true;
            permissionSetSecond.Permissions[0].DeleteItems = PermissionActionType.All;
            permissionSetSecond.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSetSecond.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSetSecond.Permissions[0].UserId = new UserIdType();
            permissionSetSecond.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequestSecond = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSetSecond });

            // Create a new folder.
            CreateFolderResponseType createFolderResponseSecond = this.FOLDAdapter.CreateFolder(createFolderRequestSecond);

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

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R980301
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                ResponseCodeType.NoError,
                createFolderResponseSecond.ResponseMessages.Items[0].ResponseCode,
                980301,
                @"[In t:FolderType Complex Type]This element [PermissionSet] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R123202
            this.Site.CaptureRequirementIfAreEqual<ResponseCodeType>(
                 ResponseCodeType.NoError,
                createFolderResponseSecond.ResponseMessages.Items[0].ResponseCode,
                123202,
                @"[In t:PermissionType Complex Type]This element [PermissionLevel] is not present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R123201
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseSecond.ResponseMessages.Items[0].ResponseClass,
                123201,
                @"[In t:PermissionType Complex Type]This element [PermissionLevel] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R122301
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseSecond.ResponseMessages.Items[0].ResponseClass,
                122301,
                @"[In t:PermissionType Complex Type]This element [ReadItems] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R460101
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                460101,
                @"[In t:BasePermissionType Complex Type]This element [CanCreateItems] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R470301
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                470301,
                @"[In t:BasePermissionType Complex Type]This element [CanCreateSubFolders] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R480301
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                480301,
                @"[In t:BasePermissionType Complex Type]This element [IsFolderOwner] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R490301
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                490301,
                @"[In t:BasePermissionType Complex Type]This element [IsFolderVisible] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R500301
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                500301,
                @"[In t:BasePermissionType Complex Type]This element [IsFolderContact] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R510201
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                510201,
                @"[In t:BasePermissionType Complex Type]This element [EditItems] is present, server responses NO_ERROR.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R520201
            this.Site.CaptureRequirementIfAreNotEqual<ResponseClassType>(
                ResponseClassType.Error,
                createFolderResponseFirst.ResponseMessages.Items[0].ResponseClass,
                520201,
                @"[In t:BasePermissionType Complex Type]This element [DeleteItems] is present, server responses NO_ERROR.");

            // Save the new created folder's folder id.
            FolderIdType secondFolderId = ((FolderInfoResponseMessageType)createFolderResponseSecond.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(secondFolderId);

            #endregion

            #region Get the new created folder

            // GetFolder request.
            GetFolderType getFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, secondFolderId);
            getFolderRequest.FolderShape.AdditionalProperties = new BasePathToElementType[]
                    {
                        new PathToUnindexedFieldType()
                        {
                            FieldURI = UnindexedFieldURIType.folderPermissionSet
                        }
                    };

            // Get the new created folder.
            GetFolderResponseType getFolderResponse = this.FOLDAdapter.GetFolder(getFolderRequest);

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

            #endregion

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

            // Since got folder successfully and schema is validated, so this requirement can be directly captured.
            this.Site.CaptureRequirement(
                45,
                @"[In t:BasePermissionType Complex Type]The type of element CanCreateItems is xs:boolean [XMLSCHEMA2].");

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

            // Since got folder successfully and schema is validated, so this requirement can be directly captured.
            this.Site.CaptureRequirement(
                47,
                @"[In t:BasePermissionType Complex Type]The type of element CanCreateSubFolders is xs:boolean.");

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

            // Since got folder successfully and schema is validated, so this requirement can be directly captured.
            this.Site.CaptureRequirement(
                48,
                @"[In t:BasePermissionType Complex Type]The type of element IsFolderOwner is xs:boolean.");

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

            // Since got folder successfully and schema is validated, so this requirement can be directly captured.
            this.Site.CaptureRequirement(
                49,
                @"[In t:BasePermissionType Complex Type]The type of element IsFolderVisible is xs:boolean.");

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

            // Since got folder successfully and schema is validated, so this requirement can be directly captured.
            this.Site.CaptureRequirement(
                50,
                @"[In t:BasePermissionType Complex Type]The type of element IsFolderContact is xs:boolean.");
        }
        public void MSOXWSFOLD_S07_TC13_FolderPermissionReadItemFullDetail()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a folder in the User1's inbox folder, and enable ReadItem with full detail permission for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].ReadItems = new PermissionReadAccessType();
            permissionSet.Permissions[0].ReadItems = PermissionReadAccessType.FullDetails;
            permissionSet.Permissions[0].ReadItemsSpecified = true;
            permissionSet.Permissions[0].CanCreateItems = true;
            permissionSet.Permissions[0].CanCreateItemsSpecified = true;
            permissionSet.Permissions[0].IsFolderOwner = true;
            permissionSet.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSet.Permissions[0].EditItems = new PermissionActionType();
            permissionSet.Permissions[0].EditItems = PermissionActionType.Owned;
            permissionSet.Permissions[0].EditItemsSpecified = true;
            permissionSet.Permissions[0].DeleteItems = new PermissionActionType();
            permissionSet.Permissions[0].DeleteItems = PermissionActionType.Owned;
            permissionSet.Permissions[0].DeleteItemsSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Edit items that User2 doesn't own with User2's credential

            this.CanEditNotOwnedItem = this.UpdateItemSubject(itemIdNotOwned);
            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);
            this.CanDeleteNotOwnedItem = this.DeleteItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;

            if (this.CanCreateItem)
            {
                this.CanEditOwnedItem = this.UpdateItemSubject(itemIdOwned);
                this.CanReadOwnedItem = this.GetItem(itemIdOwned);
                this.CanDeleteOwnedItem = this.DeleteItem(itemIdOwned);
            }
            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R158
            // If items that user owns and doesn't can both be read this requirement can be captured.
            bool isVerifiedR158 = this.CanReadOwnedItem && this.CanReadNotOwnedItem;

            Site.Assert.IsTrue(
                isVerifiedR158,
                "Can read owned item expected to be \"true\" and actual is {0};\n" +
                "Can read not owned item expected to be \"true\" and actual is {1};\n ",
                this.CanReadOwnedItem,
                this.CanReadNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR158,
                158,
                @"[In t:PermissionReadAccessType Simple Type]The value FullDetails means the user has permission to read all items in the folder.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R51002
            // If only items that user created can be edited, this requirement can be captured.
            bool isVerifiedR51002 = this.CanEditOwnedItem && !this.CanEditNotOwnedItem;

            Site.Assert.IsTrue(
               isVerifiedR51002,
               "Can edit owned item expected to be \"true\" and actual is {0};\n" +
               "Can edit not owned item expected to be \"false\" and actual is {1};\n ",
               this.CanEditOwnedItem,
               this.CanEditNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR51002,
                51002,
                @"[In t:BasePermissionType Complex Type]The type of element EditItems is ""Owned"", which indicates that the user has permission to perform the action on the items in the folder that the user owns.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R52002
            // If only items that user created can be deleted, this requirement can be captured.
            bool isVerifiedR52002 = this.CanDeleteOwnedItem && !this.CanDeleteNotOwnedItem;

            Site.Assert.IsTrue(
               isVerifiedR52002,
               "Can delete owned item expected to be \"true\" and actual is {0};\n" +
               "Can delete not owned item expected to be \"false\" and actual is {1};\n ",
               this.CanDeleteOwnedItem,
               this.CanDeleteNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR52002,
                52002,
                @"[In t:BasePermissionType Complex Type]The type of element DeleteItems is ""Owned"", which indicates that the user has permission to perform the action on the items in the folder that the user owns.");

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

            // Read items is set in permission and schema is validated in adapter, so this requirement can be captured.
            this.Site.CaptureRequirement(
                122,
                @"[In t:PermissionType Complex Type]The type of element ReadItems is t:PermissionReadAccessType (section 2.2.5.4).");
        }
        public void MSOXWSFOLD_S07_TC10_FolderPermissionContributorLevel()
        {
            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a folder in the User1's inbox folder, and enable Contributor permission for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Contributor;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Create a subfolder

            // CreateFolder request.
            CreateFolderType createFolderNotOwnedInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderNotOwnedInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderNotOwnedInSharedMailboxRequest);

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

            // Save the new created folder's folder id.
            FolderIdType newFolderIdNotOwnedInSharedMailbox = ((FolderInfoResponseMessageType)createFolderNotOwnedInSharedMailboxResponse.ResponseMessages.Items[0]).Folders[0].FolderId;

            #endregion

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Get the new created folder in step 1 with User2's credential

            // GetFolder request.
            GetFolderType getFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, newFolderId);

            // Get the new created folder.
            GetFolderResponseType getFolderResponse = this.FOLDAdapter.GetFolder(getFolderRequest);

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

            // Verify the folder is created successfully.
            FolderInfoResponseMessageType allFoldersInformation = (FolderInfoResponseMessageType)getFolderResponse.ResponseMessages.Items[0];

            #endregion

            #region Update Folder created in step 2 with User2's credential

            // UpdateFolder request.
            UpdateFolderType updateSubFolderNotOwnedRequest = this.GetUpdateFolderRequest("Folder", "SetFolderField", newFolderIdNotOwnedInSharedMailbox);

            // Update the specific folder's properties.
            UpdateFolderResponseType updateSubFolderNotOwnedResponse = this.FOLDAdapter.UpdateFolder(updateSubFolderNotOwnedRequest);

            // Check the length.
            Site.Assert.AreEqual<int>(
                1,
                updateSubFolderNotOwnedResponse.ResponseMessages.Items.GetLength(0),
                "Expected Item Count: {0}, Actual Item Count: {1}",
                1,
                updateSubFolderNotOwnedResponse.ResponseMessages.Items.GetLength(0));

            this.CanEditSubFolder = ResponseClassType.Success == updateSubFolderNotOwnedResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Get the new created Subfolder in step 2 with User2's credential

            // GetFolder request.
            GetFolderType getSubFolderNotOwnedRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, newFolderIdNotOwnedInSharedMailbox);

            // Get the new created folder.
            GetFolderResponseType getSubFolderNotOwnedResopnse = this.FOLDAdapter.GetFolder(getSubFolderNotOwnedRequest);

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

            this.CanReadSubFolder = ResponseClassType.Success == getSubFolderNotOwnedResopnse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Delete the subfolder created in step 2 with User2's credential

            // DeleteFolder request.
            DeleteFolderType deleteFolderInSharedMailBoxRequest = this.GetDeleteFolderRequest(DisposalType.HardDelete, newFolderIdNotOwnedInSharedMailbox);

            // Delete the specified folder.
            DeleteFolderResponseType deleteFolderInSharedMailBoxResponse = this.FOLDAdapter.DeleteFolder(deleteFolderInSharedMailBoxRequest);

            // Check the length.
            Site.Assert.AreEqual<int>(
                1,
                deleteFolderInSharedMailBoxResponse.ResponseMessages.Items.GetLength(0),
                "Expected Item Count: {0}, Actual Item Count: {1}",
                1,
                deleteFolderInSharedMailBoxResponse.ResponseMessages.Items.GetLength(0));

            this.CanDeleteSubFolder = ResponseClassType.Success == deleteFolderInSharedMailBoxResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Create a subfolder under the folder created in step 1 with User2's credential

            // CreateFolder request.
            CreateFolderType createFolderInSharedMailboxAfteSwitchRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderOwnedInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderInSharedMailboxAfteSwitchRequest);

            // Check the length.
            Site.Assert.AreEqual<int>(
                1,
                createFolderOwnedInSharedMailboxResponse.ResponseMessages.Items.GetLength(0),
                "Expected Item Count: {0}, Actual Item Count: {1}",
                1,
                createFolderOwnedInSharedMailboxResponse.ResponseMessages.Items.GetLength(0));

            this.CanCreateSubFolder = ResponseClassType.Success == createFolderOwnedInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Edit items that User2 doesn't own with User2's credential

            this.CanEditNotOwnedItem = this.UpdateItemSubject(itemIdNotOwned);
            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);
            this.CanDeleteNotOwnedItem = this.DeleteItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;

            if (this.CanCreateItem)
            {
                this.CanEditOwnedItem = this.UpdateItemSubject(itemIdOwned);
                this.CanDeleteOwnedItem = this.DeleteItem(itemIdOwned);
            }

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R810108
            bool isVerifiedR810108 = allFoldersInformation.Folders[0].EffectiveRights.Delete == false && !this.CanDeleteOwnedItem && !this.CanDeleteNotOwnedItem && !this.CanDeleteSubFolder;

            Site.Assert.IsTrue(
                isVerifiedR810108,
                "Delete expected to be \"false\" and actual is {0};\n" +
                "Can delete owned item expected to be \"false\" and actual is {1};\n" +
                "Can delete not owned item expected to be \"false\" and actual is {2};\n" +
                "Can delete subfolder expected to be \"false\" and actual is {3};\n ",
                allFoldersInformation.Folders[0].EffectiveRights.Delete,
                this.CanDeleteOwnedItem,
                this.CanDeleteNotOwnedItem,
                this.CanDeleteSubFolder);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR810108,
                810108,
                @"[In t:BaseFolderType Complex Type] Value ""false"" of the element Delete of EffectiveRights indicates a client cannot delete a folder or item.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R8101010
            bool isVerifiedR8101010 = allFoldersInformation.Folders[0].EffectiveRights.Modify == false && !this.CanEditSubFolder && !this.CanEditOwnedItem && !this.CanEditNotOwnedItem;

            Site.Assert.IsTrue(
                isVerifiedR8101010,
                "Modify expected to be \"false\" and actual is {0};\n" +
                "Can edit subfolder expected to be \"false\" and actual is {1};\n" +
                "Can edit owned item expected to be \"false\" and actual is {2};\n" +
                "Can edit not owned item expected to be \"false\" and actual is {3};\n ",
                allFoldersInformation.Folders[0].EffectiveRights.Modify,
                this.CanEditSubFolder,
                this.CanEditOwnedItem,
                this.CanEditNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR8101010,
                8101010,
                @"[In t:BaseFolderType Complex Type] Value ""false"" of the element Modify of EffectiveRights indicates a client can not modify a folder or item.");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R8101010
            bool isVerifiedR8101012 = allFoldersInformation.Folders[0].EffectiveRights.Read == false && !this.CanReadOwnedItem && !this.CanReadNotOwnedItem;

            Site.Assert.IsTrue(
                isVerifiedR8101012,
                "Modify expected to be \"false\" and actual is {0};\n" +
                "Can read owned item expected to be \"false\" and actual is {1};\n" +
                "Can read not owned item expected to be \"false\" and actual is {2};\n ",
                allFoldersInformation.Folders[0].EffectiveRights.Read,
                this.CanReadOwnedItem,
                this.CanReadNotOwnedItem);

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR8101012,
                8101012,
                @"[In t:BaseFolderType Complex Type] Value ""false"" of the element Read of EffectiveRights indicates a client can not read a folder or item.");
        }
        /// <summary>
        /// Generate the request message for operation "CreateFolder".
        /// </summary>
        /// <param name="parentFolderId">The folder identifier for the parent folder.</param>
        /// <param name="folderNames">An array of display name of the folders to be created.</param>
        /// <param name="folderClasses">An array of folder class value of the folders to be created.</param>
        /// <param name="permissionSet">An array of permission set value of the folder.</param>
        /// <returns>Create folder request instance that will send to server.</returns>
        protected CreateFolderType GetCreateFolderRequest(string parentFolderId, string[] folderNames, string[] folderClasses, PermissionSetType[] permissionSet)
        {
            CreateFolderType createFolderRequest = new CreateFolderType();
            createFolderRequest.ParentFolderId = new TargetFolderIdType();

            DistinguishedFolderIdType distinguishedFolderId = new DistinguishedFolderIdType();
            DistinguishedFolderIdNameType distinguishedFolderIdName = new DistinguishedFolderIdNameType();
            bool isSuccess = Enum.TryParse<DistinguishedFolderIdNameType>(parentFolderId, true, out distinguishedFolderIdName);

            if (isSuccess)
            {
                distinguishedFolderId.Id = distinguishedFolderIdName;
                createFolderRequest.ParentFolderId.Item = distinguishedFolderId;
            }
            else
            {
                FolderIdType id = new FolderIdType();
                id.Id = parentFolderId;
                createFolderRequest.ParentFolderId.Item = id;
            }

            createFolderRequest = this.ConfigureFolderProperty(folderNames, folderClasses, permissionSet, createFolderRequest);

            return createFolderRequest;
        }
        /// <summary>
        /// Set related folder properties of create folder request
        /// </summary>
        /// <param name="displayNames">Display names of folders that will be set into create folder request.</param>
        /// <param name="folderClasses">Folder class values of folders that will be set into create folder request.</param>
        /// <param name="folderPermissions">Folder permission values of folders that will be set into create folder request. </param>
        /// <param name="createFolderRequest">Create folder request instance that needs to set property values.</param>
        /// <returns>Create folder request instance that have folder property value configured.</returns>
        protected CreateFolderType ConfigureFolderProperty(string[] displayNames, string[] folderClasses, PermissionSetType[] folderPermissions, CreateFolderType createFolderRequest)
        {
            Site.Assert.IsNotNull(displayNames, "Display names should not be null!");
            Site.Assert.IsNotNull(folderClasses, "Folder classes should not be null!");
            Site.Assert.AreEqual<int>(displayNames.Length, folderClasses.Length, "Folder names count should equals to folder class value count!");
            if (folderPermissions != null)
            {
                Site.Assert.AreEqual<int>(displayNames.Length, folderPermissions.Length, "Folder names count should equals to folder permission value count!");
            }

            int folderCount = displayNames.Length;
            createFolderRequest.Folders = new BaseFolderType[folderCount];
            for (int folderPropertyIndex = 0; folderPropertyIndex < folderCount; folderPropertyIndex++)
            {
                string folderResourceName = Common.GenerateResourceName(this.Site, displayNames[folderPropertyIndex]);

                if (folderClasses[folderPropertyIndex] == "IPF.Appointment")
                {
                    CalendarFolderType calendarFolder = new CalendarFolderType();
                    calendarFolder.DisplayName = folderResourceName;
                    createFolderRequest.Folders[folderPropertyIndex] = calendarFolder;
                }
                else if (folderClasses[folderPropertyIndex] == "IPF.Contact")
                {
                    ContactsFolderType contactFolder = new ContactsFolderType();
                    contactFolder.DisplayName = folderResourceName;
                    if (folderPermissions != null)
                    {
                        contactFolder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = contactFolder;
                }
                else if (folderClasses[folderPropertyIndex] == "IPF.Task")
                {
                    TasksFolderType taskFolder = new TasksFolderType();
                    taskFolder.DisplayName = folderResourceName;
                    if (folderPermissions != null)
                    {
                        taskFolder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = taskFolder;
                }
                else if (folderClasses[folderPropertyIndex] == "IPF.Search")
                {
                    SearchFolderType searchFolder = new SearchFolderType();
                    searchFolder.DisplayName = folderResourceName;

                    // Set search parameters.
                    searchFolder.SearchParameters = new SearchParametersType();
                    searchFolder.SearchParameters.Traversal = SearchFolderTraversalType.Deep;
                    searchFolder.SearchParameters.TraversalSpecified = true;
                    searchFolder.SearchParameters.BaseFolderIds = new DistinguishedFolderIdType[1];
                    DistinguishedFolderIdType inboxType = new DistinguishedFolderIdType();
                    inboxType.Id = new DistinguishedFolderIdNameType();
                    inboxType.Id = DistinguishedFolderIdNameType.inbox;
                    searchFolder.SearchParameters.BaseFolderIds[0] = inboxType;

                    // Use the following search filter 
                    searchFolder.SearchParameters.Restriction = new RestrictionType();
                    PathToUnindexedFieldType path = new PathToUnindexedFieldType();
                    path.FieldURI = UnindexedFieldURIType.itemSubject;
                    RestrictionType restriction = new RestrictionType();
                    ExistsType isEqual = new ExistsType();
                    isEqual.Item = path;
                    restriction.Item = isEqual;
                    searchFolder.SearchParameters.Restriction = restriction;

                    if (folderPermissions != null)
                    {
                        searchFolder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = searchFolder;
                }
                else
                {
                    // Set Display Name and Folder Class for the folder to be created.
                    FolderType folder = new FolderType();
                    folder.DisplayName = folderResourceName;
                    folder.FolderClass = folderClasses[folderPropertyIndex];

                    if (folderPermissions != null)
                    {
                        folder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = folder;
                }
            }

            return createFolderRequest;
        }
        /// <summary>
        /// Validate if User has related permissions according to the permission level set on folder.
        /// </summary>
        /// <param name="permissionLevel">Permission level value.</param>
        protected void ValidateFolderPermissionLevel(PermissionLevelType permissionLevel)
        {
            #region Create a folder in the User1's inbox folder, and set permission level value for User2

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].PermissionLevel = permissionLevel;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, new PermissionSetType[] { permissionSet });

            // Create a new folder.
            CreateFolderResponseType createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);
            Site.Assert.AreEqual<ResponseClassType>(ResponseClassType.Success, createFolderResponse.ResponseMessages.Items[0].ResponseClass, "Fold should be created successfully!");

            // Save the new created folder's folder id.
            FolderIdType newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Create an item in the folder created in step 1 with User1's credential

            string itemNameNotOwned = Common.GenerateResourceName(this.Site, "Test Mail");

            // Create an item in the new created folder.
            ItemIdType itemIdNotOwned = this.CreateItem(Common.GetConfigurationPropertyValue("User1Name", Site) + "@" + Common.GetConfigurationPropertyValue("Domain", Site), newFolderId.Id, itemNameNotOwned);
            Site.Assert.IsNotNull(itemIdNotOwned, "Item should be created successfully!");

            #endregion

            #region Switch to User2

            this.SwitchUser(Common.GetConfigurationPropertyValue("User2Name", this.Site), Common.GetConfigurationPropertyValue("User2Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            #region Create a subfolder under the folder created in step 1 with User2's credential

            // CreateFolder request.
            CreateFolderType createFolderInSharedMailboxRequest = this.GetCreateFolderRequest(newFolderId.Id, new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderInSharedMailboxResponse = this.FOLDAdapter.CreateFolder(createFolderInSharedMailboxRequest);

            this.CanCreateSubFolder = ResponseClassType.Success == createFolderInSharedMailboxResponse.ResponseMessages.Items[0].ResponseClass;

            #endregion

            #region Edit items that User2 doesn't own with User2's credential

            this.CanEditNotOwnedItem = this.UpdateItemSubject(itemIdNotOwned);
            this.CanReadNotOwnedItem = this.GetItem(itemIdNotOwned);
            this.CanDeleteNotOwnedItem = this.DeleteItem(itemIdNotOwned);

            #endregion

            #region Edit items that User2 owns with User2's credential

            string itemNameOwned = Common.GenerateResourceName(this.Site, "Test Mail");
            string user1MailBox = Common.GetConfigurationPropertyValue("User1Name", Site) + "@" + Common.GetConfigurationPropertyValue("Domain", Site);

            ItemIdType itemIdOwned = this.CreateItem(user1MailBox, newFolderId.Id, itemNameOwned);

            // If user can create items.
            this.CanCreateItem = itemIdOwned != null;
            if (this.CanCreateItem)
            {
                this.CanEditOwnedItem = this.UpdateItemSubject(itemIdOwned);
                this.CanReadOwnedItem = this.GetItem(itemIdOwned);
                this.CanDeleteOwnedItem = this.DeleteItem(itemIdOwned);
            }

            #endregion

            #region Switch to User1

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion
        }
        public void MSOXWSFOLD_S01_TC13_CreateDeleteContactsFolder()
        {
            #region Create a contacts folder in the inbox folder

            // Configure permission set.
            PermissionSetType permissionSet = new PermissionSetType();
            permissionSet.Permissions = new PermissionType[1];
            permissionSet.Permissions[0] = new PermissionType();
            permissionSet.Permissions[0].CanCreateSubFolders = true;
            permissionSet.Permissions[0].CanCreateSubFoldersSpecified = true;
            permissionSet.Permissions[0].IsFolderOwner = true;
            permissionSet.Permissions[0].IsFolderOwnerSpecified = true;
            permissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Custom;
            permissionSet.Permissions[0].UserId = new UserIdType();
            permissionSet.Permissions[0].UserId.PrimarySmtpAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Contacts Folder" }, new string[] { "IPF.Contact" }, new PermissionSetType[] { permissionSet });

            // 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 newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Get the new created folder

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

            // 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 allFolders = (FolderInfoResponseMessageType)getInboxFolderResponse.ResponseMessages.Items[0];
            Site.Assert.AreEqual<string>(newFolderId.Id, allFolders.Folders[0].FolderId.Id, "The contacts folder should be created successfully in inbox.");

            #endregion

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

            // PermissionSet value is set in create folder operation and schema is verified in adapter, so this requirement can be captured.
            this.Site.CaptureRequirement(
                "MS-OXWSCONT",
                217,
                @"[In t:ContactsFolderType Complex Type] The type of the element of PermissionSet is t:PermissionSetType ([MS-OXWSFOLD] section 2.2.4.12)");

            #region Delete the created folder

            // DeleteFolder request.
            DeleteFolderType deleteFolderRequest = this.GetDeleteFolderRequest(DisposalType.HardDelete, newFolderId);

            // Delete the specified folder.
            DeleteFolderResponseType deleteFolderResponse = this.FOLDAdapter.DeleteFolder(deleteFolderRequest);

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

            // The folder has been deleted, so its folder id has disappeared.
            this.NewCreatedFolderIds.Remove(newFolderId);

            #endregion
        }