GetFileNameFromFullUrl() public static method

This method is used to get the file name from the URL.
public static GetFileNameFromFullUrl ( string fullUrlOfFile ) : string
fullUrlOfFile string A parameter represents the full URL of the file.
return string
Exemplo n.º 1
0
        /// <summary>
        /// A method used to delete collected files. If a collected file URL is not a valid file URL, this method will ignore it. If not all the valid file URLs are processed successfully, this method will raise an InvalidOperationException.
        /// </summary>
        /// <param name="collectedFiles">A parameter represents the collected file URLs.</param>
        private static void DeleteCollectedFiles(List <string> collectedFiles)
        {
            if (null == collectedFiles || 0 == collectedFiles.Count)
            {
                BaseTestSite.Log.Add(LogEntryKind.Debug, "There are no added files, skip the delete process.");
                return;
            }

            StringBuilder invalidUrlRecorder      = new StringBuilder();
            StringBuilder validUrlRecorder        = new StringBuilder();
            StringBuilder logsForValidUrlRecorder = new StringBuilder();

            foreach (string fileUrlItem in collectedFiles)
            {
                if (string.IsNullOrEmpty(fileUrlItem))
                {
                    continue;
                }

                string errorMsg;
                if (!TryVerifyFileUrl(fileUrlItem, out errorMsg))
                {
                    invalidUrlRecorder.AppendLine(string.Format(@"Invalid file URL:[{0}], Error:[{1}]", fileUrlItem, errorMsg));
                    continue;
                }

                // Construct the SUT controller input parameter.
                validUrlRecorder.Append(fileUrlItem + ",");

                // Log the files the test suite plan to delete.
                string fileName = TestSuiteHelper.GetFileNameFromFullUrl(fileUrlItem);
                logsForValidUrlRecorder.AppendLine(string.Format(@"File name:[{0}] File URL:[{1}]", fileName, fileUrlItem));
            }

            if (invalidUrlRecorder.Length != 0)
            {
                BaseTestSite.Log.Add(
                    LogEntryKind.Debug,
                    "There are some invalid URLs for collected files, test suite will skip these file URLs:\r\n{0}",
                    invalidUrlRecorder.ToString());
            }

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Test suite prepare to delete these collected files:\r\n{0}",
                logsForValidUrlRecorder.ToString());

            // Call SUT controller method to delete files.
            string uploadedfilesUrls         = validUrlRecorder.ToString(0, validUrlRecorder.Length - 1);
            bool   areFilesDeletedSuccessful = false;

            try
            {
                areFilesDeletedSuccessful = SutController.DeleteUploadedFilesOnSUT(TargetDocLibraryListName, uploadedfilesUrls);
            }
            finally
            {
                AddedFilesRecorder.Clear();
            }

            if (!areFilesDeletedSuccessful)
            {
                throw new InvalidOperationException("Not all the collected files are deleted successfully.");
            }
        }
Exemplo n.º 2
0
        public void MSWOPI_S20_TC01_EnumerateChildren()
        {
            // Get the folder URL.
            string folderFullUrl = Common.GetConfigurationPropertyValue("SubFolderUrl", this.Site);

            // Get the WOPI URL.
            string wopiTargetFolderUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(folderFullUrl, WOPIRootResourceUrlType.FolderLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get folder content URL.
            string wopiFolderContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFolderUrl, WOPISubResourceUrlType.FolderChildrenLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiFolderContentsLevelUrl);

            // Return the contents of a folder on the WOPI server.
            WOPIHttpResponse httpWebResponseForEnumerateChildren = WopiAdapter.EnumerateChildren(wopiFolderContentsLevelUrl, commonHeaders);

            int statusCode = httpWebResponseForEnumerateChildren.StatusCode;

            // Get the json string from the response of EnumerateChildren.
            string jsonStringForEnumerateChildren = WOPIResponseHelper.ReadHTTPResponseBodyToString(httpWebResponseForEnumerateChildren);

            // Convert the json string to object.
            EnumerateChildren enchildren = WOPISerializerHelper.JsonToObject <EnumerateChildren>(jsonStringForEnumerateChildren);
            string            fileName   = enchildren.Children[0].Name;

            // Verify MS-WOPI requirement: MS-WOPI_R707
            this.Site.CaptureRequirementIfAreEqual <int>(
                200,
                statusCode,
                707,
                @"[In EnumerateChildren] Status code ""200"" means ""Success"".");

            // The status code is 200 mean success.When response is success the URIs are return.
            this.Site.CaptureRequirement(
                703,
                @"[In HTTP://server/<...>/wopi*/folder/<id>/children] Operation ""EnumerateChildren"" is used for ""Returns a set of URIs that provides access to resources in the folder"".");

            // The status code is 200 mean success.When response is success the contexts are return.
            this.Site.CaptureRequirement(
                704,
                @"[In EnumerateChildren] The EnumerateChildren method returns the contents of a folder on the WOPI server.");

            // The status code is 200 mean success.When response is success the URI follows the format.
            this.Site.CaptureRequirement(
                705,
                @"[In EnumerateChildren] HTTP Verb: GET
                          URI: HTTP://server/<...>/wopi*/folder/<id>/children?access_token=<token>");

            string subFileUrl       = Common.GetConfigurationPropertyValue("UrlOfFileOnSubFolder", this.Site);
            string expectedFileName = TestSuiteHelper.GetFileNameFromFullUrl(subFileUrl);

            // Verify MS-WOPI requirement: MS-WOPI_R713
            bool isEqualToExpectedFileName = expectedFileName.CompareStringValueIgnoreCase(fileName, this.Site);

            this.Site.CaptureRequirementIfIsTrue(
                isEqualToExpectedFileName,
                713,
                @"[In Response Body] Name: The name of the child resource.");

            // Verify MS-WOPI requirement: MS-WOPI_R714
            // The EnumerateChildren request message follow this format and use the id and token return by WOPI server.
            // If the WOPI server can return the response of EnumerateChildren, capture R714
            this.Site.CaptureRequirement(
                714,
                @"[In Response Body] Url: The URI of the child resource of the form http://server/<...>/wopi*/files/<id>?access_token=<token> where id is the WOPI server’s unique id of the resource and token is the token that provides access to the resource.");
        }