Microsoft.Protocols.TestSuites.MS_SITESS.S04_ExportSolution.MSSITESS_S04_TC01_ExportSolutionSucceed C# (CSharp) Méthode

MSSITESS_S04_TC01_ExportSolutionSucceed() private méthode

private MSSITESS_S04_TC01_ExportSolutionSucceed ( ) : void
Résultat void
        public void MSSITESS_S04_TC01_ExportSolutionSucceed()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(5301, this.Site), @"Test is executed only when R5301Enabled is set to true.");

            #region Variables
            string exportResult = string.Empty;
            string galleryName = Common.GetConfigurationPropertyValue(Constants.SolutionGalleryName, this.Site);
            string[] exportFiles = null;
            string[] expectedFiles = null;

            #endregion Variables

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

            // Invoke the ExportSolution operation, a url is expected to be returned and a solution file is expected to be exported.
            exportResult = this.sitessAdapter.ExportSolution(this.solutionName + Constants.WspExtension, Constants.SolutionTitle, Constants.SolutionDescription, true, true);

            DateTime beforeLoop = DateTime.Now;
            TimeSpan waitTime = new TimeSpan();
            int repeatTime = 0;
            int totalRepeatTime = Convert.ToInt32(Common.GetConfigurationPropertyValue(Constants.ExportRepeatTime, this.Site));
            string solutions = 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, this.Site));
                Thread.Sleep(1000 * sleepTime);

                // Get all the file names in the solution library.
                solutions = this.sutAdapter.GetDocumentLibraryFileNames(string.Empty, string.Empty, galleryName, this.solutionName);
                exportFiles = solutions == null ? null : solutions.TrimEnd(new char[] { ';' }).Split(';');

                // If the expected files are created, the operation is considered as succeed.
                if (exportFiles != null && exportFiles.Length == 1)
                {
                    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)
            {
                Site.Assert.Fail("The server does not export the files after {0} seconds", waitTime);
            }
            else if (exportFiles.Length != 1)
            {
                Site.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}", 1, exportFiles.Length, exportFiles.Length > 1 ? "s" : string.Empty, solutions);
            }

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

            // 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),
                "ExportSolution should return a valid Uri, actual uri {0}.",
                exportResult);

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

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

            beforeLoop = DateTime.Now;
            waitTime = new TimeSpan();
            repeatTime = 0;
            solutions = 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, this.Site));
                Thread.Sleep(1000 * sleepTime);

                // Get all the file names in the solution library.
                solutions = this.sutAdapter.GetDocumentLibraryFileNames(string.Empty, string.Empty, galleryName, this.solutionName);
                exportFiles = solutions == null ? null : solutions.TrimEnd(new char[] { ';' }).Split(';');

                // If the expected files are created, the operation is considered as succeed.
                if (exportFiles != null && exportFiles.Length == 2)
                {
                    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)
            {
                Site.Assert.Fail("The server does not export the files after {0} seconds", waitTime);
            }
            else if (exportFiles.Length != 2)
            {
                Site.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, solutions);
            }

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

            // 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),
                "ExportSolution should return a valid Uri, actual uri {0}.",
                exportResult);

            #region Capture requirements

            // If exported files are consistent with the expected, it means multiple wsp files 
            // are created and a positive, incrementing integer is append to the second file's 
            // name (i.e. ExportSolution.wsp & ExportSolution2.wsp), so R384 can be captured.
            bool isMutipleFile = AdapterHelper.CompareStringArrays(expectedFiles, exportFiles);

            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R384, the export file is {0}", exportFiles[1]);

            // Verify MS-SITESS requirement: MS-SITESS_R384
            Site.CaptureRequirementIfIsTrue(
                isMutipleFile,
                384,
                @"[In ExportSolution] [solutionFileName:] If a solution with the specified name already exists in the solution gallery, the server retry with <filename>2.wsp, where <filename> is obtained from solutionFileName after excluding the extension.");

            // If exported files are consistent with the expected, it means multiple wsp files 
            // are created and a positive, incrementing integer is append to the second file's 
            // name (i.e. ExportSolution.wsp & ExportSolution2.wsp), so R38 can be captured.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R38, the export file is {0}", exportFiles[1]);

            // Verify MS-SITESS requirement: MS-SITESS_R38
            Site.CaptureRequirementIfIsTrue(
                isMutipleFile,
                38,
                @"[In ExportSolution] [solutionFileName:] If a unique name is obtained, the 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 method ExportSolution.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R5301, Microsoft SharePoint Foundation 2010 and above support method ExportSolution.");

            // Verify MS-SITESS requirement: MS-SITESS_R5301
            Site.CaptureRequirement(
                5301,
                @"[In Appendix B: Product Behavior] Implementation does support this method [ExportSolution]. (Microsoft SharePoint Foundation 2010 and above follow this behavior.)");
            #endregion Capture requirements
        }