Microsoft.Protocols.TestSuites.MS_OXCROPS.S01_LogonROPs.MSOXCROPS_S01_TC05_TestRopPublicFolderIsGhosted C# (CSharp) Method

MSOXCROPS_S01_TC05_TestRopPublicFolderIsGhosted() private method

private MSOXCROPS_S01_TC05_TestRopPublicFolderIsGhosted ( ) : void
return void
        public void MSOXCROPS_S01_TC05_TestRopPublicFolderIsGhosted()
        {
            this.CheckTransportIsSupported();

            // Check whether the environment supported public folder.
            if (bool.Parse(Common.GetConfigurationPropertyValue("IsPublicFolderSupported", this.Site)))
            {
                this.cropsAdapter.RpcConnect(
                    Common.GetConfigurationPropertyValue("SutComputerName", this.Site),
                    ConnectionType.PublicFolderServer,
                    Common.GetConfigurationPropertyValue("UserEssdn", this.Site),
                    Common.GetConfigurationPropertyValue("Domain", this.Site),
                    Common.GetConfigurationPropertyValue("AdminUserName", this.Site),
                    Common.GetConfigurationPropertyValue("PassWord", this.Site));

                // Step 1: Open the second folder, in which a public folder will be created under root folder in the following code.
                #region Open the second folder
                RopLogonResponse logonResponse = Logon(LogonType.PublicFolder, this.userDN, out inputObjHandle);
                RopOpenFolderRequest openFolderRequest;
                RopOpenFolderResponse openFolderResponse;

                openFolderRequest.RopId = (byte)RopId.RopOpenFolder;

                openFolderRequest.LogonId = TestSuiteBase.LogonId;

                // Set InputHandleIndex to 0x0, which specifies the location in the Server object handle table
                // where the handle for the input Server object is stored.
                openFolderRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

                // Set OutputHandleIndex to 0x1, which specifies the location in the Server object handle table
                // where the handle for the output Server object will be stored.
                openFolderRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

                // Set FolderId to the second folder.
                openFolderRequest.FolderId = logonResponse.FolderIds[1];

                openFolderRequest.OpenModeFlags = (byte)FolderOpenModeFlags.None;

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 1: Begin to send the RopOpenFolder request.");

                // Send the RopOpenFolder request to the server and verify the success response.
                this.responseSOHs = cropsAdapter.ProcessSingleRop(
                    openFolderRequest,
                    this.inputObjHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.SuccessResponse);
                openFolderResponse = (RopOpenFolderResponse)response;

                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    openFolderResponse.ReturnValue,
                    "if ROP succeeds, the ReturnValue of its response is 0(success)");

                // Get the folder handle which is opened.
                uint openedFolderHandle = responseSOHs[0][openFolderResponse.OutputHandleIndex];

                #endregion

                // Step 2: Create a none-ghosted public folder under the root folder.
                #region Create folder

                RopCreateFolderRequest createFolderRequest;
                RopCreateFolderResponse createFolderResponse;

                createFolderRequest.RopId = (byte)RopId.RopCreateFolder;
                createFolderRequest.LogonId = TestSuiteBase.LogonId;

                // Set InputHandleIndex to 0x0, which specifies the location in the Server object handle table
                // where the handle for the input Server object is stored.
                createFolderRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

                // Set OutputHandleIndex to 0x1, which specifies the location in the Server object handle table
                // where the handle for the output Server object will be stored.
                createFolderRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

                createFolderRequest.FolderType = (byte)FolderType.Genericfolder;

                // Set UseUnicodeStrings to 0x0, which specifies the DisplayName and Comment are not specified in Unicode.
                createFolderRequest.UseUnicodeStrings = Convert.ToByte(TestSuiteBase.Zero);

                // Set OpenExisting to 0xFF, which means the folder being created will be opened when it is already existed.
                createFolderRequest.OpenExisting = TestSuiteBase.NonZero;

                // Set Reserved to 0x0, this field is reserved and MUST be set to 0.
                createFolderRequest.Reserved = TestSuiteBase.Reserved;

                // Set DisplayName, which specifies the name of the created folder.
                createFolderRequest.DisplayName = Encoding.ASCII.GetBytes(Common.GenerateResourceName(this.Site, "PublicFolderNoneGhosted") + "\0");

                // Set Comment, which specifies the folder comment that is associated with the created folder.
                createFolderRequest.Comment = Encoding.ASCII.GetBytes(Common.GenerateResourceName(this.Site, "PublicFolderNoneGhosted") + "\0");

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 2: Begin to send the RopCreateFolder request.");

                // Send the RopCreateFolder request to the server and verify the success response.
                this.responseSOHs = cropsAdapter.ProcessSingleRop(
                    createFolderRequest,
                    openedFolderHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.SuccessResponse);
                createFolderResponse = (RopCreateFolderResponse)response;

                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    createFolderResponse.ReturnValue,
                    "if ROP succeeds, the ReturnValue of its response is 0(success)");

                // Get the folder id of the created folder.
                ulong folderId = createFolderResponse.FolderId;

                #endregion

                // Step 3: Send RopPublicFolderIsGhosted request to the server and verify RopPublicFolderIsGhosted success response with none-Ghosted folder.
                #region RopPublicFolderIsGhosted success response with none-Ghosted folder

                RopPublicFolderIsGhostedRequest publicFolderIsGhostedRequest;
                RopPublicFolderIsGhostedResponse publicFolderIsGhostedResponse;

                publicFolderIsGhostedRequest.RopId = (byte)RopId.RopPublicFolderIsGhosted;
                publicFolderIsGhostedRequest.LogonId = TestSuiteBase.LogonId;

                // Set InputHandleIndex to 0x0, which specifies the location in the Server object handle table
                // where the handle for the input Server object is stored.
                publicFolderIsGhostedRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

                // Set the FolderId to that got in Step 2.
                publicFolderIsGhostedRequest.FolderId = folderId;

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 3: Begin to send the RopPublicFolderIsGhosted request.");

                // Send the RopPublicFolderIsGhosted request to the server and verify the success response.
                this.responseSOHs = cropsAdapter.ProcessSingleRop(
                    publicFolderIsGhostedRequest,
                    this.inputObjHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.SuccessResponse);
                publicFolderIsGhostedResponse = (RopPublicFolderIsGhostedResponse)response;

                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    publicFolderIsGhostedResponse.ReturnValue,
                    "If ROP succeeds, the ReturnValue of its response is 0 (success)");

                #endregion

                #region Verify R4630, R313 and R4631
                Site.Assert.AreEqual<uint>(
                    0x0,
                    publicFolderIsGhostedResponse.IsGhosted,
                    "If the test case is opening a non-ghosted public folder, IsGhosted should be 0");

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

                // Verify MS-OXCROPS requirement: MS-OXCROPS_R4630
                // This ServersCount is not present when ServersCount is null.
                Site.CaptureRequirementIfAreEqual<ushort?>(
                    null,
                    publicFolderIsGhostedResponse.ServersCount,
                    4630,
                    @"[In RopPublicFolderIsGhosted ROP Success Response Buffer] ServersCount (2 bytes): This field[ServersCount (2 bytes)] is not present if IsGhosted is zero.");

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

                // Verify MS-OXCROPS requirement: MS-OXCROPS_R313
                // This CheapServersCount is not present when CheapServersCount is null.
                Site.CaptureRequirementIfAreEqual<ushort?>(
                    null,
                    publicFolderIsGhostedResponse.CheapServersCount,
                    313,
                    @"[In RopPublicFolderIsGhosted ROP Success Response Buffer] CheapServersCount (2 bytes): This field is not present if the value of the IsGhosted is zero.");

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

                // Verify MS-OXCROPS requirement: MS-OXCROPS_R4631
                // This Servers is not  present when Servers is null.
                Site.CaptureRequirementIfIsNull(
                    publicFolderIsGhostedResponse.Servers,
                    4631,
                    @"[In RopPublicFolderIsGhosted ROP Success Response Buffer] Servers (optional) (variable): This field is not present if IsGhosted is zero.");

                #endregion

                // Step 4: Send a RopDeleteFolder request to the server.
                #region RopDeleteFolder Response
                RopDeleteFolderRequest deleteFolderRequest;

                deleteFolderRequest.RopId = (byte)RopId.RopDeleteFolder;
                deleteFolderRequest.LogonId = TestSuiteBase.LogonId;

                // Set InputHandleIndex to 0x0, which specifies the location in the Server object handle table
                // where the handle for the input Server object is stored.
                deleteFolderRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

                deleteFolderRequest.DeleteFolderFlags = (byte)DeleteFolderFlags.DeleteHardDelete;

                // Set FolderId to targetFolderId, this folder is to be deleted.
                deleteFolderRequest.FolderId = folderId;

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 4: Begin to send the RopDeleteFolder request.");

                // Send a RopDeleteFolder request to the server and verify the success response.
                this.responseSOHs = cropsAdapter.ProcessSingleRop(
                    deleteFolderRequest,
                    openedFolderHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.SuccessResponse);
                RopDeleteFolderResponse deleteFolderResponse = (RopDeleteFolderResponse)response;

                Site.Assert.AreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    deleteFolderResponse.ReturnValue,
                    "If ROP succeeds, the ReturnValue of its response is 0 (success)");

                #endregion

                // The ghosted folder is only supported when the second SUT exists.
                if (!string.IsNullOrEmpty(Common.GetConfigurationPropertyValue("Sut2ComputerName", this.Site)))
                {
                    // Step 5: Get the existed ghosted public folder ID.
                    folderId = this.GetSubfolderIDByName(openedFolderHandle, Common.GetConfigurationPropertyValue("GhostedPublicFolderDisplayName", this.Site) + "\0");

                    // Step 6: Open the existed ghosted public folder.
                    #region Open folder

                    // Set FolderId to that of existed ghosted public folder.
                    openFolderRequest.FolderId = folderId;

                    // Add the debug information
                    Site.Log.Add(LogEntryKind.Debug, "Step 6: Begin to send the RopOpenFolder request.");

                    // Send the RopOpenFolder request to the server and verify the success response.
                    this.responseSOHs = cropsAdapter.ProcessSingleRop(
                        openFolderRequest,
                        this.inputObjHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse);
                    openFolderResponse = (RopOpenFolderResponse)response;

                    Site.Assert.AreEqual<uint>(
                        TestSuiteBase.SuccessReturnValue,
                        openFolderResponse.ReturnValue,
                        "if ROP succeeds, the ReturnValue of its response is 0(success)");

                    #endregion

                    #region Verify R560, R564 and R568

                    if (openFolderResponse.IsGhosted > 0x0)
                    {
                        // Add the debug information
                        Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R560");

                        // Verify MS-OXCROPS requirement: MS-OXCROPS_R560
                        // If ServerCount is not null mean present
                        Site.CaptureRequirementIfIsNotNull(
                            openFolderResponse.ServerCount,
                            560,
                            @"[In RopOpenFolder ROP Success Response Buffer] ServerCount (2 bytes): This field is present if IsGhosted is nonzero.");

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

                        // Verify MS-OXCROPS requirement: MS-OXCROPS_R564
                        // If CheapServerCount is not null mean present
                        Site.CaptureRequirementIfIsNotNull(
                            openFolderResponse.CheapServerCount,
                            564,
                            @"[In RopOpenFolder ROP Success Response Buffer] CheapServerCount (2 bytes): This field is present if IsGhosted is nonzero.");

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

                        // Verify MS-OXCROPS requirement: MS-OXCROPS_R568
                        // If the Servers field in openFolderResponse is not null, it means the field is present.
                        Site.CaptureRequirementIfIsNotNull(
                            openFolderResponse.Servers,
                            568,
                            @"[In RopOpenFolder ROP Success Response Buffer] Servers (variable): This field is present if IsGhosted is nonzero.");
                    }

                    #endregion

                    // Step 7: Send RopPublicFolderIsGhosted request to the server and verify RopPublicFolderIsGhosted success response with Ghosted folder.
                    #region RopPublicFolderIsGhosted success response with Ghosted folder

                    // Set FolderId to that of existed ghosted public folder.
                    publicFolderIsGhostedRequest.FolderId = folderId;

                    // Add the debug information
                    Site.Log.Add(LogEntryKind.Debug, "Step 7: Begin to send the RopPublicFolderIsGhosted request.");

                    this.responseSOHs = cropsAdapter.ProcessSingleRop(
                        publicFolderIsGhostedRequest,
                        this.inputObjHandle,
                        ref this.response,
                        ref this.rawData,
                        RopResponseType.SuccessResponse);
                    publicFolderIsGhostedResponse = (RopPublicFolderIsGhostedResponse)response;

                    Site.Assert.AreEqual<uint>(
                        TestSuiteBase.SuccessReturnValue,
                        publicFolderIsGhostedResponse.ReturnValue,
                        "If ROP succeeds, the ReturnValue of its response is 0 (success)");

                    #endregion

                    #region Verify R307,R312 and R316

                    Site.Assert.IsTrue(publicFolderIsGhostedResponse.IsGhosted > 0x0, "If the test case is opening a ghosted public folder, IsGhosted should be greater than 0");

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

                    // Verify MS-OXCROPS requirement: MS-OXCROPS_R307
                    // This ServersCount is present when ServersCount is not null.
                    Site.CaptureRequirementIfIsNotNull(
                        publicFolderIsGhostedResponse.ServersCount,
                        307,
                        @"[In RopPublicFolderIsGhosted ROP Success Response Buffer] ServersCount (2 bytes): This field[ServersCount (2 bytes)] is present if IsGhosted is nonzero.");

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

                    // Verify MS-OXCROPS requirement: MS-OXCROPS_R312
                    // This CheapServersCount is present when CheapServersCount is not null.
                    Site.CaptureRequirementIfIsNotNull(
                        publicFolderIsGhostedResponse.CheapServersCount,
                        312,
                        @"[In RopPublicFolderIsGhosted ROP Success Response Buffer] CheapServersCount (2 bytes): This field is present if the value of the IsGhosted field is nonzero.");

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

                    // Verify MS-OXCROPS requirement: MS-OXCROPS_R316
                    // This Servers is present when Servers is not null.
                    Site.CaptureRequirementIfIsNotNull(
                        publicFolderIsGhostedResponse.Servers,
                        316,
                        @"[In RopPublicFolderIsGhosted ROP Success Response Buffer] Servers (optional) (variable):This field is present if IsGhosted is nonzero.");

                    #endregion

                    if (Common.IsRequirementEnabled(6000101, this.Site))
                    {
                        // Step 8: Create an ghosted public folder of one existed folder.
                        #region Create folder

                        // Set DisplayName to same as that existed folder.
                        createFolderRequest.DisplayName = Encoding.ASCII.GetBytes(Common.GetConfigurationPropertyValue("GhostedPublicFolderDisplayName", this.Site) + "\0");

                        // Set Comment to same as that existed folder.
                        createFolderRequest.Comment = Encoding.ASCII.GetBytes(Common.GetConfigurationPropertyValue("GhostedPublicFolderComment", this.Site) + "\0");

                        // Add the debug information
                        Site.Log.Add(LogEntryKind.Debug, "Step 8: Begin to send the RopCreateFolder request.");

                        // Send the RopCreateFolder request to the server and verify the success response.
                        this.responseSOHs = cropsAdapter.ProcessSingleRop(
                            createFolderRequest,
                            openedFolderHandle,
                            ref this.response,
                            ref this.rawData,
                            RopResponseType.SuccessResponse);
                        createFolderResponse = (RopCreateFolderResponse)response;

                        Site.Assert.AreEqual<uint>(
                            TestSuiteBase.SuccessReturnValue,
                            createFolderResponse.ReturnValue,
                            "if ROP succeeds, the ReturnValue of its response is 0(success)");

                        #endregion

                        #region Verify R6000101, R626, R622, R630, R634 and R638

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

                        // Verify MS-OXCROPS requirement: MS-OXCROPS_R6000101
                        Site.CaptureRequirementIfAreNotEqual<int>(
                            0,
                            createFolderResponse.IsExistingFolder,
                            6000101,
                            @"[In Appendix A: Product Behavior] If a folder with the name given by the DisplayName field of the request buffer (RopCreateFolder) already exists, implementation does set a nonzero value to IsExistingFolder field. (Exchange 2007 follows this behavior.)");

                        if (createFolderResponse.IsExistingFolder != 0)
                        {
                            // Add the debug information
                            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R626");

                            // Verify MS-OXCROPS requirement: MS-OXCROPS_R626
                            // IsGhosted not null means present.
                            Site.CaptureRequirementIfIsNotNull(
                                createFolderResponse.IsGhosted,
                                626,
                                @"[In RopCreateFolder ROP Success Response Buffer] IsGhosted (1 byte): This field is present if the value of the IsExistingFolder field is nonzero.");

                            // Refer to MS-OXCSTOR LogonFlags.Private. This bit is set for logon to a private mailbox and is not set for logon to public folders.
                            if (0x00 == (logonResponse.LogonFlags & (byte)LogonFlags.Private))
                            {
                                // Add the debug information
                                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R622");

                                // Verify MS-OXCROPS requirement: MS-OXCROPS_R622
                                // HasRules is not null means present.
                                Site.CaptureRequirementIfIsNotNull(
                                    createFolderResponse.HasRules,
                                    622,
                                    @"[In RopCreateFolder ROP Success Response Buffer] HasRules (1 byte): This field is present if the IsExistingFolder field is nonzero.");
                            }

                            if (createFolderResponse.IsGhosted != null && createFolderResponse.IsGhosted != 0)
                            {
                                // Add the debug information
                                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R630");

                                // Verify MS-OXCROPS requirement: MS-OXCROPS_R630
                                // ServerCount is not null means present.
                                Site.CaptureRequirementIfIsNotNull(
                                    createFolderResponse.ServerCount,
                                    630,
                                    @"[In RopCreateFolder ROP Success Response Buffer] ServerCount (2 bytes): This field is present if the values of both the IsExistingFolder and the IsGhosted fields are nonzero.");

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

                                // Verify MS-OXCROPS requirement: MS-OXCROPS_R634
                                // CheapServerCount is not null means present.
                                Site.CaptureRequirementIfIsNotNull(
                                    createFolderResponse.CheapServerCount,
                                    634,
                                    @"[In RopCreateFolder ROP Success Response Buffer] CheapServerCount (2 bytes): This field is present if the values of both the IsExistingFolder and the IsGhosted fields are nonzero.");

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

                                // Verify MS-OXCROPS requirement: MS-OXCROPS_R638
                                // Servers is not null means present.
                                Site.CaptureRequirementIfIsNotNull(
                                    createFolderResponse.Servers,
                                    638,
                                    @"[In RopCreateFolder ROP Success Response Buffer] Servers (variable): This field is present if  the values of both the IsExistingFolder and the IsGhosted fields are nonzero.");
                            }
                        }

                        #endregion
                    }
                }

                // Step 9: Send RopPublicFolderIsGhosted request to the server and verify RopPublicFolderIsGhosted failure response.
                #region RopPublicFolderIsGhosted failure response

                // Set FolderId to 0x1, which does not exist in public folder database and will lead to a failure response.
                publicFolderIsGhostedRequest.FolderId = TestSuiteBase.WrongFolderId;

                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Step 9: Begin to send the RopPublicFolderIsGhosted request.");

                // Send the RopPublicFolderIsGhosted request to the server and verify the failure response.
                this.responseSOHs = cropsAdapter.ProcessSingleRop(
                    publicFolderIsGhostedRequest,
                    this.inputObjHandle,
                    ref this.response,
                    ref this.rawData,
                    RopResponseType.FailureResponse);
                publicFolderIsGhostedResponse = (RopPublicFolderIsGhostedResponse)response;

                Site.Assert.AreNotEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    publicFolderIsGhostedResponse.ReturnValue,
                    "If ROP fails, the ReturnValue of its response is set to a value other than 0x00000000(failure)");

                #endregion
            }
            else
            {
                Site.Assert.Inconclusive("This case runs only when the first system supports public folder logon.");
            }
        }