Exemplo n.º 1
0
        /// <summary>
        /// A method used to get source file URL. The URL's file name is unique.
        /// </summary>
        /// <param name="sourceFileType">A parameter represents the source URL type.</param>
        /// <returns>A return value represents the destination URL.</returns>
        protected string GetSourceFileUrl(SourceFileUrlType sourceFileType)
        {
            string expectedPropertyName;

            switch (sourceFileType)
            {
            case SourceFileUrlType.SourceFileOnDesSUT:
            {
                expectedPropertyName = "SourceFileUrlOnDesSUT";
                break;
            }

            case SourceFileUrlType.SourceFileOnSourceSUT:
            {
                expectedPropertyName = "SourceFileUrlOnSourceSUT";
                break;
            }

            default:
            {
                throw new InvalidOperationException("The test suite only support two source URL type: [SourceFileUrlOnDesSUT] and [SourceFileUrlOnSourceSUT].");
            }
            }

            string expectedSourceFileUrl = Common.GetConfigurationPropertyValue(expectedPropertyName, this.Site);

            // Verify the URL whether point to a file.
            FileUrlHelper.ValidateFileUrl(expectedSourceFileUrl);

            return(expectedSourceFileUrl);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the adapter instance.
        /// </summary>
        /// <param name="testSite">A return value represents the ITestSite instance which contains the test context.</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);
            TestSuiteManageHelper.Initialize(this.Site);
            TestSuiteManageHelper.AcceptServerCertificate();

            // Initial the listsws proxy without schema validation.
            if (null == this.listswsProxy)
            {
                this.listswsProxy = Proxy.CreateProxy <ListsSoap>(testSite, true, false, false);
            }

            FileUrlHelper.ValidateFileUrl(TestSuiteManageHelper.TargetServiceUrlOfMSCOPYS);

            // Point to listsws service according to the MS-COPYS service URL.
            string targetServiceUrl = Path.GetDirectoryName(TestSuiteManageHelper.TargetServiceUrlOfMSCOPYS);

            targetServiceUrl = Path.Combine(targetServiceUrl, @"lists.asmx");

            // Work around for local path format mapping to URL path format.
            targetServiceUrl = targetServiceUrl.Replace(@"\", @"/");
            targetServiceUrl = targetServiceUrl.Replace(@":/", @"://");

            // Setting the properties of listsws service proxy.
            this.listswsProxy.Url         = targetServiceUrl;
            this.listswsProxy.Credentials = TestSuiteManageHelper.DefaultUserCredential;
            this.listswsProxy.SoapVersion = TestSuiteManageHelper.GetSoapProtoclVersionByCurrentSetting();

            // 60000 means the configure SOAP Timeout is in minute.
            this.listswsProxy.Timeout = TestSuiteManageHelper.CurrentSoapTimeOutValue;
        }
Exemplo n.º 3
0
        /// <summary>
        /// A method used to generate invalid file URL by construct a not-existing file name.
        /// </summary>
        /// <param name="originalFilePath">A parameter represents the original file path, it must be a valid URL.</param>
        /// <returns>A return value represents a file URL with a not-existing file name.</returns>
        protected string GenerateInvalidFileUrl(string originalFilePath)
        {
            FileUrlHelper.ValidateFileUrl(originalFilePath);
            string directoryName = Path.GetDirectoryName(originalFilePath);

            // Append an invalid URL char to file name is not.
            string invalidFileName = string.Format(@"Invalid{0}File{1}Name.txt", @"%", @"&");
            string invalidFileUrl  = Path.Combine(directoryName, invalidFileName);

            // Work around for local path format mapping to URL path format.
            invalidFileUrl = invalidFileUrl.Replace(@"\", @"/");
            invalidFileUrl = invalidFileUrl.Replace(@":/", @"://");
            return(invalidFileUrl);
        }
Exemplo n.º 4
0
        /// <summary>
        /// A method used to generate invalid file URL by confusing the folder path. The method will confuse the path part which is nearest to the file name part.
        /// </summary>
        /// <param name="originalFilePath">A parameter represents the original file path.</param>
        /// <returns>A return value represents a file URL with an invalid folder path.</returns>
        protected string GenerateInvalidFolderPathForFileUrl(string originalFilePath)
        {
            string fileName      = FileUrlHelper.ValidateFileUrl(originalFilePath);
            string directoryName = Path.GetDirectoryName(originalFilePath);

            // Append a guid value to ensure the folder name is not a valid folder.
            string invalidDirectoryName = directoryName + Guid.NewGuid().ToString("N");
            string invalidFileUrl       = Path.Combine(invalidDirectoryName, fileName);

            // Work around for local path format mapping to URL path format.
            invalidFileUrl = invalidFileUrl.Replace(@"\", @"/");
            invalidFileUrl = invalidFileUrl.Replace(@":/", @"://");
            return(invalidFileUrl);
        }
Exemplo n.º 5
0
        /// <summary>
        /// A method used to upload a txt file to the destination SUT.
        /// </summary>
        /// <param name="fileUrl">A parameter represents the expected URL of a file which will be uploaded into the destination SUT. The file URL must point to the destination SUT which is indicated by "SutComputerName" property in "SharePointCommonConfiguration.deployment.ptfconfig" file.</param>
        protected void UploadTxtFileByFileUrl(string fileUrl)
        {
            if (null == MSCOPYSSutControlAdapter)
            {
                throw new InvalidOperationException("The SUT control adapter is not initialized.");
            }

            FileUrlHelper.ValidateFileUrl(fileUrl);
            bool isFileUploadSuccessful = MSCOPYSSutControlAdapter.UploadTextFile(fileUrl);

            if (!isFileUploadSuccessful)
            {
                this.Site.Assert.Fail("Could not upload a txt file to the destination SUT. Expected file URL:[{0}]", fileUrl);
            }

            this.CollectFileToRecorder(fileUrl);
        }
Exemplo n.º 6
0
        /// <summary>
        /// A method is used to generate the destination URL. The file name in the URL is unique.
        /// </summary>
        /// <param name="destinationType">A parameter represents the destination URL type.</param>
        /// <returns>A return value represents the destination URL.</returns>
        protected string GetDestinationFileUrl(DestinationFileUrlType destinationType)
        {
            string urlPatternValueOfDestinationFile = string.Empty;
            string expectedPropertyName             = string.Empty;

            switch (destinationType)
            {
            case DestinationFileUrlType.NormalDesLibraryOnDesSUT:
            {
                expectedPropertyName = "UrlPatternOfDesFileOnDestinationSUT";
                break;
            }

            case DestinationFileUrlType.MWSLibraryOnDestinationSUT:
            {
                expectedPropertyName = "UrlPatternOfDesFileForMWSOnDestinationSUT";
                break;
            }

            default:
            {
                throw new InvalidOperationException("The test suite only supports two destination type: [NormalDesLibraryOnDesSUT] and [MWSLibraryOnDestinationSUT].");
            }
            }

            // Get match URL pattern.
            urlPatternValueOfDestinationFile = Common.GetConfigurationPropertyValue(expectedPropertyName, this.Site);

            if (urlPatternValueOfDestinationFile.IndexOf("{FileName}", StringComparison.OrdinalIgnoreCase) <= 0)
            {
                throw new InvalidOperationException(string.Format(@"The [{0}] property should contain the ""{fileName}"" placeholder.", expectedPropertyName));
            }

            string fileNameValue            = this.GetUniqueFileName();
            string actualDestinationFileUrl = urlPatternValueOfDestinationFile.ToLower().Replace("{filename}", fileNameValue);

            // Verify the URL whether point to a file.
            FileUrlHelper.ValidateFileUrl(actualDestinationFileUrl);

            return(actualDestinationFileUrl);
        }
Exemplo n.º 7
0
        /// <summary>
        /// A method used to undo checkout for a file by specified user credential.
        /// </summary>
        /// <param name="fileUrl">A parameter represents the absolute URL of a file which will be undo checkout by specified user.</param>
        /// <param name="userName">A parameter represents the user name which will check out the file. The file must be stored in the destination SUT which is indicated by "SutComputerName" property in "SharePointCommonConfiguration.deployment.ptfconfig" file.</param>
        /// <param name="password">A parameter represents the password of the user.</param>
        /// <param name="domain">A parameter represents the domain of the user.</param>
        /// <returns>Return true if the operation succeeds, otherwise returns false.</returns>
        public bool UndoCheckOutFileByUser(string fileUrl, string userName, string password, string domain)
        {
            #region parameter validation
            FileUrlHelper.ValidateFileUrl(fileUrl);

            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }

            #endregion parameter validation

            if (null == this.listswsProxy)
            {
                throw new InvalidOperationException("The LISTSWS proxy is not initialized, should call the [Initialize] method before calling this method.");
            }

            this.listswsProxy.Credentials = new NetworkCredential(userName, password, domain);

            bool undoCheckOutResult;
            try
            {
                undoCheckOutResult = this.listswsProxy.UndoCheckOut(fileUrl);
            }
            catch (SoapException soapEx)
            {
                this.Site.Log.Add(
                    LogEntryKind.Debug,
                    @"There is an exception generated when the SUT control adapter try to undo check out for a file[{0}]:\r\nExcetption Message:\r\n[{1}]\r\\nStackTrace:\r\n[{2}]",
                    fileUrl,
                    string.IsNullOrEmpty(soapEx.Message) ? "None" : soapEx.Message,
                    string.IsNullOrEmpty(soapEx.StackTrace) ? "None" : soapEx.StackTrace);
                return(false);
            }
            finally
            {
                this.listswsProxy.Credentials = TestSuiteManageHelper.DefaultUserCredential;
            }

            return(undoCheckOutResult);
        }
Exemplo n.º 8
0
 /// <summary>
 /// A method used to collect a file by specified file URL. The test suite will try to delete all collect files.
 /// </summary>
 /// <param name="fileUrl">A parameter represents the URL of a file which will be collected to delete. The file must be stored in the destination SUT which is indicated by "SutComputerName" property in "SharePointCommonConfiguration.deployment.ptfconfig" file.</param>
 protected void CollectFileByUrl(string fileUrl)
 {
     FileUrlHelper.ValidateFileUrl(fileUrl);
     this.CollectFileToRecorder(fileUrl);
 }