Microsoft.Protocols.TestSuites.MS_OXCMSG.S01_CreateAndSaveMessage.MSOXCMSG_S01_TC09_RopSaveChangeMessageFailure C# (CSharp) Method

MSOXCMSG_S01_TC09_RopSaveChangeMessageFailure() private method

private MSOXCMSG_S01_TC09_RopSaveChangeMessageFailure ( ) : void
return void
        public void MSOXCMSG_S01_TC09_RopSaveChangeMessageFailure()
        {
            if (Common.IsRequirementEnabled(1916, this.Site))
            {
                this.CheckMapiHttpIsSupported();
                this.ConnectToServer(ConnectionType.PrivateMailboxServer);

                List<PropertyTag> propertyTags = new List<PropertyTag>
                {
                    PropertyHelper.PropertyTagDic[PropertyNames.PidTagAccessLevel]
                };
                List<PropertyObj> propertyValues;
                RopSaveChangesMessageResponse saveChangesMessageResponse;

                #region Call RopLogon to log on a private mailbox.
                RopLogonResponse logonResponse = this.Logon(LogonType.Mailbox, out this.insideObjHandle);
                #endregion

                #region Call RopCreateMessage to create new Message object.
                uint targetMessageHandle = this.CreatedMessage(logonResponse.FolderIds[4], this.insideObjHandle);
                saveChangesMessageResponse = this.SaveMessage(targetMessageHandle, (byte)SaveFlags.ForceSave);
                ulong messageID = saveChangesMessageResponse.MessageId;
                this.ReleaseRop(targetMessageHandle);
                #endregion

                #region Call RopOpenMessage to open the message object created by step above.
                targetMessageHandle = this.OpenSpecificMessage(logonResponse.FolderIds[4], messageID, this.insideObjHandle, MessageOpenModeFlags.ReadWrite);
                #endregion

                #region Call RopGetPropertiesSpecific to get PidTagAccessLevel property for created message before save message.
                // Prepare property Tag 
                PropertyTag[] tagArray = new PropertyTag[1];
                tagArray[0] = PropertyHelper.PropertyTagDic[PropertyNames.PidTagAccessLevel];

                // Get properties for Created Message
                RopGetPropertiesSpecificRequest getPropertiesSpecificRequest = new RopGetPropertiesSpecificRequest()
                {
                    RopId = (byte)RopId.RopGetPropertiesSpecific,
                    LogonId = CommonLogonId, // The logonId 0x00 is associated with this operation.
                    InputHandleIndex = CommonInputHandleIndex, // This index specifies the location 0x00 in the Server Object Handle Table where the handle for the input Server Object is stored. 
                    PropertySizeLimit = 0xFFFF, // This value specifies the maximum number of the property
                    PropertyTagCount = (ushort)tagArray.Length,
                    PropertyTags = tagArray
                };
                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(getPropertiesSpecificRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                RopGetPropertiesSpecificResponse getPropertiesSpecificResponse = (RopGetPropertiesSpecificResponse)this.response;
                Site.Assert.AreEqual<uint>(TestSuiteBase.Success, getPropertiesSpecificResponse.ReturnValue, "Call RopGetPropertiesSpecific should success.");

                propertyValues = PropertyHelper.GetPropertyObjFromBuffer(tagArray, getPropertiesSpecificResponse);
                PropertyObj accesssLevelBeforeSave = PropertyHelper.GetPropertyByName(propertyValues, PropertyNames.PidTagAccessLevel);
                #endregion

                #region Call RopSaveChangesMessage to save the created Message object on one transaction.
                // Call RopSaveChangesMessage to save the created message on one transaction.
                // The server will return an error when call RopSaveChangesMessage if property R1916Enabled is true in SHOULD/MAY ptfconfig file.
                uint messageHandleSecond = this.OpenSpecificMessage(logonResponse.FolderIds[4], messageID, this.insideObjHandle, MessageOpenModeFlags.ReadWrite);
                saveChangesMessageResponse = this.SaveMessage(messageHandleSecond, (byte)SaveFlags.ForceSave);
                this.ReleaseRop(messageHandleSecond);
                #endregion

                #region Call RopSaveChangesMessage and Saveflag field is KeepOpenReadOnly.
                RopSaveChangesMessageRequest saveChangesMessageRequest = new RopSaveChangesMessageRequest()
                {
                    RopId = (byte)RopId.RopSaveChangesMessage,
                    LogonId = CommonLogonId,
                    InputHandleIndex = CommonInputHandleIndex,
                    ResponseHandleIndex = CommonOutputHandleIndex, // This index specifies the location in the Server object handle table that is referenced in the response.
                    SaveFlags = (byte)SaveFlags.KeepOpenReadOnly
                };

                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(saveChangesMessageRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                saveChangesMessageResponse = (RopSaveChangesMessageResponse)this.response;

                Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, "Call RopSaveChangesMessage should failed.");

                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(getPropertiesSpecificRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                getPropertiesSpecificResponse = (RopGetPropertiesSpecificResponse)this.response;
                Site.Assert.AreEqual<uint>(TestSuiteBase.Success, getPropertiesSpecificResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);

                propertyValues = PropertyHelper.GetPropertyObjFromBuffer(tagArray, getPropertiesSpecificResponse);

                PropertyObj accesssLevelAfterReadOnlyFail = PropertyHelper.GetPropertyByName(propertyValues, PropertyNames.PidTagAccessLevel);

                Site.Assert.AreEqual<int>(Convert.ToInt32(accesssLevelBeforeSave.Value), Convert.ToInt32(accesssLevelAfterReadOnlyFail.Value), "The Message object access level should be unchanged.");

                // Because server return error code when call RopSaveChangesMessage and 
                // the access level has not been changed between call RopSaveChangesMessage before and after.
                // So R1670 will be verified.
                this.Site.CaptureRequirement(
                    1670,
                    @"[In RopSaveChangesMessage ROP Request Buffer] [SaveFlags] [KeepOpenReadOnly (0x01)] [If the RopSaveChangesMessage ROP failed] The server returns an error and leaves the Message object open with unchanged access level.");
                #endregion

                #region Call RopSaveChangesMessage and SaveFlag field is KeepOpenReadWrite.
                saveChangesMessageRequest = new RopSaveChangesMessageRequest()
                {
                    RopId = (byte)RopId.RopSaveChangesMessage,
                    LogonId = CommonLogonId,
                    InputHandleIndex = CommonInputHandleIndex,
                    ResponseHandleIndex = CommonOutputHandleIndex, // This index specifies the location in the Server object handle table that is referenced in the response.
                    SaveFlags = (byte)SaveFlags.KeepOpenReadWrite
                };

                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(saveChangesMessageRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                saveChangesMessageResponse = (RopSaveChangesMessageResponse)this.response;

                Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, "Call RopSaveChangesMessage should failed.");

                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(getPropertiesSpecificRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                getPropertiesSpecificResponse = (RopGetPropertiesSpecificResponse)this.response;
                Site.Assert.AreEqual<uint>(TestSuiteBase.Success, getPropertiesSpecificResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);

                propertyValues = PropertyHelper.GetPropertyObjFromBuffer(tagArray, getPropertiesSpecificResponse);

                PropertyObj accesssLevelAfterReadWriteFail = PropertyHelper.GetPropertyByName(propertyValues, PropertyNames.PidTagAccessLevel);

                Site.Assert.AreEqual<int>(Convert.ToInt32(accesssLevelBeforeSave.Value), Convert.ToInt32(accesssLevelAfterReadWriteFail.Value), "The Message object access level should be unchanged.");

                // Because server return error code when call RopSaveChangesMessage and 
                // the access level has not been changed between call RopSaveChangesMessage before and after.
                // So R718 will be verified.
                this.Site.CaptureRequirement(
                    718,
                    @"[In RopSaveChangesMessage ROP Request Buffer] [SaveFlags] [KeepOpenReadWrite (0x02)] [If the RopSaveChangesMessage ROP failed] The server returns an error and leaves the Message object open with unchanged access level.");
                #endregion

                #region Call RopSaveChangesMessage and SaveFlag field is ForceSave.
                saveChangesMessageRequest = new RopSaveChangesMessageRequest()
                {
                    RopId = (byte)RopId.RopSaveChangesMessage,
                    LogonId = CommonLogonId,
                    InputHandleIndex = InvalidInputHandleIndex,
                    ResponseHandleIndex = CommonOutputHandleIndex, // This index specifies the location in the Server object handle table that is referenced in the response.
                    SaveFlags = (byte)SaveFlags.ForceSave
                };
                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(saveChangesMessageRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                saveChangesMessageResponse = (RopSaveChangesMessageResponse)this.response;

                Site.Assert.AreNotEqual<uint>(TestSuiteBase.Success, saveChangesMessageResponse.ReturnValue, "Call RopSaveChangesMessage should failed.");

                this.ResponseSOHs = this.MSOXCMSGAdapter.DoRopCall(getPropertiesSpecificRequest, targetMessageHandle, ref this.response, ref this.rawData, GetPropertiesFlags.None);
                getPropertiesSpecificResponse = (RopGetPropertiesSpecificResponse)this.response;
                Site.Assert.AreEqual<uint>(TestSuiteBase.Success, getPropertiesSpecificResponse.ReturnValue, TestSuiteBase.ROPSucceedMsg);

                propertyValues = PropertyHelper.GetPropertyObjFromBuffer(tagArray, getPropertiesSpecificResponse);
                PropertyObj accesssLevelAfterForceSaveFail = PropertyHelper.GetPropertyByName(propertyValues, PropertyNames.PidTagAccessLevel);

                Site.Assert.AreEqual<int>(Convert.ToInt32(accesssLevelBeforeSave.Value), Convert.ToInt32(accesssLevelAfterForceSaveFail.Value), "The Message object access level should be unchanged.");

                // Because server return error code when call RopSaveChangesMessage and 
                // the access level has not been changed between call RopSaveChangesMessage before and after.
                // So R722 will be verified.
                this.Site.CaptureRequirement(
                    722,
                    @"[In RopSaveChangesMessage ROP Request Buffer] [SaveFlags] [ForceSave (0x04)] [If the RopSaveChangesMessage ROP failed] The server returns an error and leaves the Message object open with unchanged access level.");
                #endregion

                #region Call RopRelease to release created message.
                this.ReleaseRop(targetMessageHandle);
                #endregion
            }
            else
            {
                this.isNotNeedCleanupPrivateMailbox = true;
                Site.Assume.Inconclusive("This case runs only if the implementation does not return Success for RopSaveChangesMessage ROP requests when a previous request has already been committed against the Message object, even though the changes to the object are not actually committed to the server store.");
            }
        }