Microsoft.Protocols.TestSuites.MS_SITESS.TestSuiteHelper.VerifyExportAndImportFile C# (CSharp) Méthode

VerifyExportAndImportFile() public static méthode

Verify exported files and log file for the ExportWeb, ImportWeb, ExportSolution and ExportWorkflowTemplate operations.
public static VerifyExportAndImportFile ( string fileName, int fileNumber, ITestSite testSite, IMS_SITESSSUTControlAdapter sutAdapter ) : string
fileName string A string indicates the expected file name.
fileNumber int A Integer indicates the expected file number.
testSite ITestSite The instance of ITestSite.
sutAdapter IMS_SITESSSUTControlAdapter The instance of the SUT control adapter.
Résultat string
        public static string VerifyExportAndImportFile(string fileName, int fileNumber, ITestSite testSite, IMS_SITESSSUTControlAdapter sutAdapter)
        {
            string[] exportFiles = null;
            DateTime beforeLoop = DateTime.Now;
            TimeSpan waitTime = new TimeSpan();
            int repeatTime = 0;
            int totalRepeatTime = Convert.ToInt32(Common.GetConfigurationPropertyValue(Constants.ExportRepeatTime, testSite));
            string files = string.Empty;
            do
            {
                // It is assumed that the server will generate all the exported files and log file after the preconfigured time period.
                int sleepTime = Convert.ToInt32(Common.GetConfigurationPropertyValue(Constants.ExportWaitTime, testSite));
                Thread.Sleep(1000 * sleepTime);

                // Get all the file names in the document library.
                files = sutAdapter.GetDocumentLibraryFileNames(string.Empty, string.Empty, Common.GetConfigurationPropertyValue(Constants.ValidLibraryName, testSite), fileName);
                exportFiles = files == null ? null : files.TrimEnd(new char[] { ';' }).Split(';');

                // If the expected files are created, the operation is considered as succeed.
                if (exportFiles != null && exportFiles.Length == fileNumber)
                {
                    break;
                }

                // If the server could not generate all the exported files and log file after the time period ExportWaitTime for some unknown reasons, for example, limit of server resources, try to repeat this sequence again.
                repeatTime++;
            }
            while (repeatTime < totalRepeatTime);
            waitTime = DateTime.Now - beforeLoop;

            // If the server still does not generate all the exported files and log file after repeating, or the server generate unexpected number of files, the operation is considered as failed.
            if (exportFiles == null)
            {
                testSite.Assert.Fail("The server does not export the files after {0} seconds", waitTime);
            }
            else if (exportFiles.Length != fileNumber)
            {
                testSite.Assert.Fail("The server does not export {0} files as expected but exports {1} file{2} in actual, and the exported file name list is {3}", 2, exportFiles.Length, exportFiles.Length > 1 ? "s" : string.Empty, files);
            }

            return files;
        }
    }

Usage Example

Exemple #1
0
        public void MSSITESS_S05_TC01_ExportWorkflowTemplateSucceed()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(5331, this.Site), @"Test is executed only when R5331Enabled is set to true.");

            #region Variables
            string   templateName   = Common.GetConfigurationPropertyValue(Constants.WorkflowTemplateName, this.Site);
            string   destinationUrl = Common.GetConfigurationPropertyValue(Constants.DataPath, this.Site);
            string   exportResult   = string.Empty;
            string[] exportFiles    = null;
            string[] expectedFiles  = null;

            #endregion Variables

            // Initialize the web service with an authenticated account.
            this.sitessAdapter.InitializeWebService(UserAuthenticationOption.Authenticated);

            // Invoke ExportWorkflowTemplate operation, a URL is expected to be returned and a solution file is expected to be exported.
            exportResult = this.sitessAdapter.ExportWorkflowTemplate(this.solutionName + Constants.WspExtension, Constants.SolutionTitle, Constants.SolutionDescription, templateName, destinationUrl);

            // If returned value is not a URL or exported files are inconsistent with the expected, log it.
            Site.Assert.IsTrue(
                Uri.IsWellFormedUriString(exportResult, UriKind.Relative),
                "ExportWorkflowTemplate should return a valid Uri, actual uri {0}.",
                exportResult);

            string solutions = TestSuiteHelper.VerifyExportAndImportFile(this.solutionName, 1, this.Site, this.sutAdapter);
            exportFiles = solutions == null ? null : solutions.TrimEnd(new char[] { ';' }).Split(';');
            this.isSolutionFileCreated = true;

            // Format the expected file names in the document library, only one solution file (i.e. SolutionName) is expected.
            expectedFiles = new string[] { this.solutionName + Constants.WspExtension };

            Site.Assert.IsTrue(
                AdapterHelper.CompareStringArrays(expectedFiles, exportFiles),
                "ExportWorkflowTemplate should export the solution file.");

            // If returned value is a URL and exported files are consistent with the expected, it means the ExportWorkflowTemplate operation succeed.
            // Invoke ExportWorkflowTemplate operation again, a URL is expected to be returned and a second solution file is expected to be exported.
            exportResult = this.sitessAdapter.ExportWorkflowTemplate(this.solutionName + Constants.WspExtension, Constants.SolutionTitle, Constants.SolutionDescription, templateName, destinationUrl);

            // If returned value is not a URL or exported files are inconsistent with the expected, log it.
            Site.Assert.IsTrue(
                Uri.IsWellFormedUriString(exportResult, UriKind.Relative),
                "ExportWorkflowTemplate should return a valid Uri, actual uri {0}.",
                exportResult);

            solutions   = TestSuiteHelper.VerifyExportAndImportFile(this.solutionName, 2, this.Site, this.sutAdapter);
            exportFiles = solutions == null ? null : solutions.TrimEnd(new char[] { ';' }).Split(';');

            // Format the expected file names in the document library, two solution files (i.e. SolutionName & SolutionName2) are expected.
            expectedFiles = new string[]
            {
                this.solutionName + Constants.WspExtension,
                this.solutionName + "2" + Constants.WspExtension
            };

            #region Capture requirements

            bool isFilesAreEqual = AdapterHelper.CompareStringArrays(expectedFiles, exportFiles);

            // If the exported files are consistent with the expected, R386 can be captured.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R386, the export files are {0}", exportFiles);

            // Verify MS-SITESS requirement: MS-SITESS_R386
            Site.CaptureRequirementIfIsTrue(
                isFilesAreEqual,
                386,
                @"[In ExportWorkflowTemplate] [solutionFileName:] If a solution with the specified name already exists in the document library in which the solution file needs to be created, the server MUST retry with <filename>2.wsp, where <filename> is obtained from solutionFileName after excluding the extension.");

            // If the exported files are consistent with the expected, R109 can be captured.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R109, the export files are {0}", exportFiles);

            // Verify MS-SITESS requirement: MS-SITESS_R109
            Site.CaptureRequirementIfIsTrue(
                isFilesAreEqual,
                109,
                @"[In ExportWorkflowTemplate] [solutionFileName:] If a unique name is obtained, the protocol server MUST continue with that name [to create a solution file using this unique name].");

            // If code can run to here, it means that Microsoft SharePoint Foundation 2010 and above support operation ExportWorkflowTemplate.
            this.VerifyOperationExportWorkflowTemplate();
            #endregion Capture requirements
        }