GetPreviousVersion() public static method

Get the latest version that is less than the current version.
public static GetPreviousVersion ( VersionData versions ) : string
versions VersionData The versions of specified file.
return string
        /// <summary>
        /// A common method used to verify that the client uses the RestoreVersion operation to successfully restore
        /// the file specified by a URL to a specific version when check out is enforced.
        /// </summary>
        /// <param name="url">The URL of a file.</param>
        private void RestoreVersionVerification(string url)
        {
            // Enable the versioning of the list.
            bool setVersioning = this.sutControlAdapterInstance.SetVersioning(this.documentLibrary, true, true);

            Site.Assert.IsTrue(
                setVersioning,
                "SetVersioning operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                setVersioning);

            // Upload the file into specific list.
            bool isAddFileSuccessful = this.sutControlAdapterInstance.AddFile(this.documentLibrary, this.fileName, TestSuiteHelper.UploadFileName);

            Site.Assert.IsTrue(
                isAddFileSuccessful,
                "AddFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isAddFileSuccessful);

            // Check out and check in file one time to create a new version of the file.
            this.testSuiteHelper.AddOneFileVersion(this.fileName);

            // Enforce the file to be checked out.
            bool setServerEnforceCheckOut = this.sutControlAdapterInstance.SetEnforceCheckout(this.documentLibrary, true);

            Site.Assert.IsTrue(
                setServerEnforceCheckOut,
                "SetServerEnforceCheckOut operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                setServerEnforceCheckOut);

            // Call GetVersions operation using relative fileName.
            GetVersionsResponseGetVersionsResult getVersionsResponse = this.protocolAdapterInstance.GetVersions(
                url);

            // Verify the GetVersions results.
            this.testSuiteHelper.VerifyResultsInformation(getVersionsResponse.results, OperationName.GetVersions, true);

            // Check out the specified file.
            bool isCheckOutFile = this.listsSutControlAdaterInstance.CheckoutFile(this.fileAbsoluteUrl);

            Site.Assert.IsTrue(
                isCheckOutFile,
                "CheckOutFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isCheckOutFile);

            // Get the current version of the file.
            string currentVersionBeforeRestore = AdapterHelper.GetCurrentVersion(getVersionsResponse.results.result);

            // Get the previous version which is specific to be restored.
            string restoreVersion = AdapterHelper.GetPreviousVersion(getVersionsResponse.results.result);

            // Call RestoreVersion operation using relative fileName and restore a specified file to a specific version.
            RestoreVersionResponseRestoreVersionResult restoreVersionReponse = this.protocolAdapterInstance.RestoreVersion(
                url, restoreVersion);

            // Check in the specified file.
            bool isCheckInFile = this.listsSutControlAdaterInstance.CheckInFile(
                this.fileAbsoluteUrl,
                TestSuiteHelper.FileComments,
                ((int)VersionType.MinorCheckIn).ToString());

            Site.Assert.IsTrue(
                isCheckInFile,
                "CheckInFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isCheckInFile);

            // Verify the RestoreVersion results.
            this.testSuiteHelper.VerifyResultsInformation(restoreVersionReponse.results, OperationName.RestoreVersion, true);

            // Get the current version in RestoreVersion response.
            string currentVersionAfterRestore = AdapterHelper.GetCurrentVersion(restoreVersionReponse.results.result);

            // Verify whether the current version was increased by RestoreVersion.
            bool isCurrentVersionIncreased = AdapterHelper.IsCurrentVersionIncreased(
                currentVersionBeforeRestore,
                currentVersionAfterRestore);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-VERSS_R182, the current version before RestoreVersion is {0}, and after RestoreVersion is {1}",
                currentVersionBeforeRestore,
                currentVersionAfterRestore);

            // Verify MS-VERSS requirement: MS-VERSS_R182
            Site.CaptureRequirementIfIsTrue(
                isCurrentVersionIncreased,
                182,
                @"[In RestoreVersion] After the restoration, the current version number of the file MUST still be increased, as with any other change.");
        }
        /// <summary>
        /// A common method used to verify that the client can get expected DeleteAllVersionsSoapOut and
        /// GetVersionsSoapOut messages by calling DeleteAllVersions and GetVersions operations with the URL of a file.
        /// </summary>
        /// <param name="url">The URL of a file.</param>
        private void DeleteAllVersionsVerification(string url)
        {
            // Enable the versioning of the list.
            bool setVersioning = this.sutControlAdapterInstance.SetVersioning(this.documentLibrary, true, true);

            Site.Assert.IsTrue(
                setVersioning,
                "SetVersioning operation returns {0}, TRUE means the operation was executed successfully, " +
                "FALSE means the operation failed",
                setVersioning);

            // Upload the file into specific list.
            bool isAddFileSuccessful = this.sutControlAdapterInstance.AddFile(this.documentLibrary, this.fileName, TestSuiteHelper.UploadFileName);

            Site.Assert.IsTrue(
                isAddFileSuccessful,
                "AddFile operation returns {0}, TRUE means the operation was executed successfully, " +
                " FALSE means the operation failed",
                isAddFileSuccessful);

            // Check out and check in file one time to create a new version of the file.
            this.testSuiteHelper.AddOneFileVersion(this.fileName);

            // Call SUT Control Adapter method SetFilePublish to publish the current version of the file.
            bool isFilePublished = this.sutControlAdapterInstance.SetFilePublish(this.documentLibrary, this.fileName, true);

            Site.Assert.IsTrue(
                isFilePublished,
                "SetFilePublish operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isFilePublished);

            // Call GetVersions with the relative filename to get details about all versions of the file.
            GetVersionsResponseGetVersionsResult getVersionsResponse = this.protocolAdapterInstance.GetVersions(url);

            // Verify the GetVersions response results.
            this.testSuiteHelper.VerifyResultsInformation(getVersionsResponse.results, OperationName.GetVersions, true);

            // Get previous version before DeleteAllVersions operation by using the results element in the response of GetVersions.
            string previousVersion = AdapterHelper.GetPreviousVersion(getVersionsResponse.results.result);

            // Get the published version information by using the results element in the response of GetVersions.
            string publishedVersion = AdapterHelper.GetCurrentVersion(getVersionsResponse.results.result);

            // Check out and check in file one time to create a new version of the file.
            this.testSuiteHelper.AddOneFileVersion(this.fileName);

            // Call GetVersions with the relative filename to get details about all versions of the file.
            getVersionsResponse = this.protocolAdapterInstance.GetVersions(url);

            // Get the current version information by using the results element in the response of GetVersions.
            string currentVersion = AdapterHelper.GetCurrentVersion(getVersionsResponse.results.result);

            // Enable the Recycle Bin.
            bool isRecycleBinEnable = this.sutControlAdapterInstance.SetRecycleBinEnable(true);

            Site.Assert.IsTrue(
                isRecycleBinEnable,
                "SetRecycleBinEnable operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isRecycleBinEnable);

            // Call DeleteAllVersions operation with the relative filename to delete all the previous versions except
            // the published version and the current version.
            DeleteAllVersionsResponseDeleteAllVersionsResult deleteAllVersionsResponse =
                this.protocolAdapterInstance.DeleteAllVersions(url);

            // Verify DeleteAllVersions response results.
            this.testSuiteHelper.VerifyResultsInformation(deleteAllVersionsResponse.results, OperationName.DeleteAllVersions, true);

            // Verify whether the published version and the current version exist in the results element in the response
            // of DeleteAllVersions.
            bool isCurrentVersionExist =
                AdapterHelper.IsVersionExist(deleteAllVersionsResponse.results.result, currentVersion);
            bool isPublishedVersionExist = AdapterHelper.IsVersionExist(
                deleteAllVersionsResponse.results.result,
                publishedVersion);

            Site.Assert.IsTrue(
                isCurrentVersionExist,
                "The DeleteAllVersions operation should not delete the current version {0}",
                currentVersion);

            Site.Assert.IsTrue(
                isPublishedVersionExist,
                "The DeleteAllVersions operation should not delete the published version {0}",
                publishedVersion);

            // Verify whether the previous version exists in the results element in the response of DeleteAllVersions.
            bool isPreviousVersionExist = AdapterHelper.IsVersionExist(deleteAllVersionsResponse.results.result, previousVersion);

            Site.Assert.IsFalse(
                isPreviousVersionExist,
                "The DeleteAllVersions operation should delete the previous version {0}",
                previousVersion);

            // Since all the previous versions of the specified file do not exist, except for the published version and the current version, capture requirement MS-VERSS_R79.
            Site.CaptureRequirement(
                79,
                @"[In DeleteAllVersions operation] The DeleteAllVersions operation deletes all the previous versions of the specified file, except for the published version and the current version. ");

            bool isDeleteFileVersionExistInRecycleBin = false;
            bool isDeleted = false;

            foreach (VersionData versionData in getVersionsResponse.results.result)
            {
                isDeleted = !AdapterHelper.IsVersionExist(deleteAllVersionsResponse.results.result, versionData.version);
                if (isDeleted)
                {
                    // Verify whether the deleted versions exist in the Recycle Bin.
                    isDeleteFileVersionExistInRecycleBin = this.sutControlAdapterInstance.IsFileExistInRecycleBin(
                        this.fileName,
                        versionData.version);

                    if (!isDeleteFileVersionExistInRecycleBin)
                    {
                        break;
                    }
                }
            }

            // Verify MS-VERSS requirement: MS-VERSS_R169
            Site.CaptureRequirementIfIsTrue(
                isDeleteFileVersionExistInRecycleBin,
                169,
                @"[In DeleteAllVersions operation] If the Recycle Bin is enabled, the versions are placed in the Recycle Bin, instead.");
        }
        public void MSVERSS_S02_TC03_RestoreVersionWithoutEnforceCheckout()
        {
            // Enable the versioning of the list.
            bool setVersioning = this.sutControlAdapterInstance.SetVersioning(this.documentLibrary, true, true);

            Site.Assert.IsTrue(
                setVersioning,
                "SetVersioning operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                setVersioning);

            // Protocol server does not enforce that only checked out files can be modified.
            bool isSetServerEnforceCheckOut = this.sutControlAdapterInstance.SetEnforceCheckout(this.documentLibrary, false);

            Site.Assert.IsTrue(
                isSetServerEnforceCheckOut,
                "SetServerEnforceCheckOut operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isSetServerEnforceCheckOut);

            // Upload the first file into specific list.
            bool isAddFileSuccessful = this.sutControlAdapterInstance.AddFile(this.documentLibrary, this.fileName, TestSuiteHelper.UploadFileName);

            Site.Assert.IsTrue(
                isAddFileSuccessful,
                "AddFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isAddFileSuccessful);

            // Check out and check in first file to add the file versions.
            this.testSuiteHelper.AddOneFileVersion(this.fileName);

            // Call GetVersions operation using absolute fileName.
            GetVersionsResponseGetVersionsResult getVersionsResponse = this.protocolAdapterInstance.GetVersions(this.fileAbsoluteUrl.AbsoluteUri);

            // Verify the GetVersions results.
            this.testSuiteHelper.VerifyResultsInformation(getVersionsResponse.results, OperationName.GetVersions, true);

            // Get the current version.
            string currentVersionBeforeRestore = AdapterHelper.GetCurrentVersion(getVersionsResponse.results.result);

            // Get the previous version which is specific to be restored.
            string restoreVersion = AdapterHelper.GetPreviousVersion(getVersionsResponse.results.result);

            // Call RestoreVersion operation using absolute fileName and restore a specified file to a specific version.
            RestoreVersionResponseRestoreVersionResult restoreVersionNotCheckOutResponse =
                this.protocolAdapterInstance.RestoreVersion(this.fileAbsoluteUrl.AbsoluteUri, restoreVersion);

            // Verify the RestoreVersion results.
            this.testSuiteHelper.VerifyResultsInformation(restoreVersionNotCheckOutResponse.results, OperationName.RestoreVersion, true);

            // Get the current version in RestoreVersion response.
            string currentVersionAfterNotCheckOutRestore = AdapterHelper.GetCurrentVersion(
                restoreVersionNotCheckOutResponse.results.result);

            // Verify whether the current version after RestoreVersion is increased when the file is not checked out.
            bool isCurrentVersionIncreased = AdapterHelper.IsCurrentVersionIncreased(
                currentVersionBeforeRestore,
                currentVersionAfterNotCheckOutRestore);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-VERSS_R185, if the file is not checked out, the current version before RestoreVersion is {0}," +
                " and after RestoreVersion is {1}",
                currentVersionBeforeRestore,
                currentVersionAfterNotCheckOutRestore);

            // Verify MS-VERSS requirement: MS-VERSS_R185
            Site.CaptureRequirementIfIsTrue(
                isCurrentVersionIncreased,
                185,
                @"[In RestoreVersion] If the file is not checked out before the restoration, the current version number of the file MUST still be increased, as with any other change.");

            // Check out the file.
            bool isCheckOutFile = this.listsSutControlAdaterInstance.CheckoutFile(this.fileAbsoluteUrl);

            Site.Assert.IsTrue(
                isCheckOutFile,
                "CheckOutFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isCheckOutFile);

            // Call GetVersions operation using absolute fileName.
            getVersionsResponse = this.protocolAdapterInstance.GetVersions(this.fileAbsoluteUrl.AbsoluteUri);

            // Get current version before RestoreVersion operation in GetVersions response.
            currentVersionBeforeRestore = AdapterHelper.GetCurrentVersion(getVersionsResponse.results.result);

            // Get the previous version which is specific to be restored.
            restoreVersion = AdapterHelper.GetPreviousVersion(getVersionsResponse.results.result);

            // Call RestoreVersion operation using absolute fileName and restore a specified file to a specific version.
            RestoreVersionResponseRestoreVersionResult restoreVersionIsCheckOutResponse =
                this.protocolAdapterInstance.RestoreVersion(this.fileAbsoluteUrl.AbsoluteUri, restoreVersion);

            // Get the current version in RestoreVersion response.
            string currentVersionAfterIsCheckOutRestore = AdapterHelper.GetCurrentVersion(
                restoreVersionIsCheckOutResponse.results.result);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-VERSS_R186, if the file is checked out, the current version before RestoreVersion is {0}," +
                " and after RestoreVersion is {1}",
                currentVersionBeforeRestore,
                currentVersionAfterIsCheckOutRestore);

            // Verify MS-VERSS requirement: MS-VERSS_R186
            Site.CaptureRequirementIfAreEqual <string>(
                currentVersionBeforeRestore,
                currentVersionAfterIsCheckOutRestore,
                186,
                @"[In RestoreVersion] If the file is checked out, the current version number of the file after restoration MUST remain the same as before restoration.");

            // Check in file.
            bool isCheckInFile = this.listsSutControlAdaterInstance.CheckInFile(
                this.fileAbsoluteUrl,
                TestSuiteHelper.FileComments,
                ((int)VersionType.MinorCheckIn).ToString());

            Site.Assert.IsTrue(
                isCheckInFile,
                "CheckInFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isCheckInFile);
        }
        /// <summary>
        /// A common method used to verify that the client can get expected DeleteVersionSoapOut and
        /// GetVersionsSoapOut messages by calling DeleteVersion and GetVersions operations with the URL of a file.
        /// </summary>
        /// <param name="url">The URL of a file.</param>
        private void DeleteVersionVerification(string url)
        {
            // Enable the versioning of the list.
            bool setVersioning = this.sutControlAdapterInstance.SetVersioning(this.documentLibrary, true, true);

            Site.Assert.IsTrue(
                setVersioning,
                "SetVersioning operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                setVersioning);

            // Upload the file into specific list.
            bool isAddFileSuccessful = this.sutControlAdapterInstance.AddFile(this.documentLibrary, this.fileName, TestSuiteHelper.UploadFileName);

            Site.Assert.IsTrue(
                isAddFileSuccessful,
                "AddFile operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isAddFileSuccessful);

            // Check out and check in file one time to create a new version of the file.
            this.testSuiteHelper.AddOneFileVersion(this.fileName);

            // Call GetVersions with the relative filename to get details about all versions of the file.
            GetVersionsResponseGetVersionsResult getVersionsResponse =
                this.protocolAdapterInstance.GetVersions(url);

            // Verify the GetVersions response results.
            this.testSuiteHelper.VerifyResultsInformation(getVersionsResponse.results, OperationName.GetVersions, true);

            // Get the current version information by using the results element in the response of GetVersions.
            string currentVersion = AdapterHelper.GetCurrentVersion(getVersionsResponse.results.result);

            // Enable the Recycle Bin.
            bool isRecycleBinEnable = this.sutControlAdapterInstance.SetRecycleBinEnable(true);

            Site.Assert.IsTrue(
                isRecycleBinEnable,
                "SetRecycleBinEnable operation returns {0}, TRUE means the operation was executed successfully," +
                " FALSE means the operation failed",
                isRecycleBinEnable);

            // Get the version that needs to be deleted.
            string deleteFileVersion = AdapterHelper.GetPreviousVersion(getVersionsResponse.results.result);

            // Call DeleteVersion to delete a specific version of the file by using the relative filename.
            DeleteVersionResponseDeleteVersionResult deleteVersionResponse =
                this.protocolAdapterInstance.DeleteVersion(url, deleteFileVersion);

            // Verify DeleteVersion response results.
            this.testSuiteHelper.VerifyResultsInformation(deleteVersionResponse.results, OperationName.DeleteVersion, true);

            // Check whether the current version exists in the DeleteVersion response.
            bool isCurrentVersionExist =
                AdapterHelper.IsVersionExist(deleteVersionResponse.results.result, currentVersion);

            Site.Assert.IsTrue(
                isCurrentVersionExist,
                "The DeleteVersion operation should not delete the current version {0}",
                currentVersion);

            // Check whether the deleted version exists in the Recycle Bin.
            bool isDeleteFileVersionExistInRecycleBin =
                this.sutControlAdapterInstance.IsFileExistInRecycleBin(this.fileName, deleteFileVersion);

            // Verify MS-VERSS requirement: MS-VERSS_R173
            Site.CaptureRequirementIfIsTrue(
                isDeleteFileVersionExistInRecycleBin,
                173,
                @"[In DeleteVersion operation] If the Recycle Bin is enabled, the version is placed in the Recycle Bin, instead.");
        }