Example #1
0
        private static MediaUrlData ParseRenderUrl(string relativeUrl, out UrlKind urlKind)
        {
            try
            {
                var        queryParameters = new UrlBuilder(relativeUrl).GetQueryParameters();
                IMediaFile mediaFile       = MediaUrlHelper.GetFileFromQueryString(queryParameters);
                Verify.IsNotNull(mediaFile, "failed to get file from a query string");

                urlKind = UrlKind.Renderer;

                queryParameters.Remove("id");
                queryParameters.Remove("i");
                queryParameters.Remove("src");
                queryParameters.Remove("store");

                return(new MediaUrlData {
                    MediaId = mediaFile.Id, MediaStore = mediaFile.StoreId, QueryParameters = queryParameters
                });
            }
            catch (Exception)
            {
                urlKind = UrlKind.Undefined;
                return(null);
            }
        }
Example #2
0
        public HyperLinkEqualsValidator(string url, UrlKind kind, bool strictQueryStringParamsOrder, params UriComponents[] components)
        {
            this.strictQueryStringParamsOrder = strictQueryStringParamsOrder;
            this.url  = url;
            this.kind = kind;
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }
            UriComponents tempComponent = components[0];

            components.ToList().ForEach(s => tempComponent |= s);
            finalComponent = tempComponent;

            if (this.strictQueryStringParamsOrder == false && (finalComponent & UriComponents.Query) > 0)
            {
                checkQueryStringParams = true;
                finalComponent         = finalComponent & ~UriComponents.Query;
            }
            else if (this.strictQueryStringParamsOrder == false && (finalComponent & UriComponents.PathAndQuery) > 0)
            {
                checkQueryStringParams = true;
                finalComponent         = finalComponent & ~UriComponents.PathAndQuery;
                finalComponent         = finalComponent | UriComponents.Path;
            }
        }
        /// <summary>
        /// Compates current Url and given url.
        /// </summary>
        /// <param name="url">This url is compared with CurrentUrl.</param>
        /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
        /// <param name="components">Determine what parts of urls are compared.</param>
        public bool CompareUrl(string url, UrlKind urlKind, params UriComponents[] components)
        {
            var currentUri = new Uri(CurrentUrl);

            //support relative domain
            //(new Uri() cannot parse the url correctly when the host is missing
            if (urlKind == UrlKind.Relative)
            {
                url = url.StartsWith("/") ? $"{currentUri.Scheme}://{currentUri.Host}{url}" : $"{currentUri.Scheme}://{currentUri.Host}/{url}";
            }

            if (urlKind == UrlKind.Absolute && url.StartsWith("//"))
            {
                if (!string.IsNullOrWhiteSpace(currentUri.Scheme))
                {
                    url = currentUri.Scheme + ":" + url;
                }
            }

            var expectedUri = new Uri(url, UriKind.Absolute);

            if (components.Length == 0)
            {
                throw new BrowserLocationException($"Function CheckUrlCheckUrl(string, UriKind, params UriComponents) has to have one UriComponents at least.");
            }
            UriComponents finalComponent = components[0];

            components.ToList().ForEach(s => finalComponent |= s);

            return(Uri.Compare(currentUri, expectedUri, finalComponent, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0);
        }
 /// <summary>
 /// Checks url by its parts
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public BrowserWrapper CheckUrl(string url, UrlKind urlKind, params UriComponents[] components)
 {
     if (!CompareUrl(url, urlKind, components))
     {
         throw new BrowserLocationException($"Current url is not expected. Current url: '{CurrentUrl}'. Expected url: '{url}'");
     }
     return(this);
 }
 public BrowserWrapper CheckIfHyperLinkEquals(string selector, string url, UrlKind kind, params UriComponents[] components)
 {
     ForEach(selector, element =>
     {
         element.CheckIfHyperLinkEquals(url, kind, components);
     });
     return(this);
 }
Example #6
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="absoluteUrl">The absolute URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            if (absoluteUrl.StartsWith("http") && absoluteUrl.Contains("://"))
            {
                return UrlProvider.ParseUrl(absoluteUrl, out urlKind);
            }

            var context = HttpContext.Current;
            string hostname = context != null ? context.Request.Url.Host : null;
            var urlSpace = new UrlSpace(hostname, absoluteUrl);

            return UrlProvider.ParseUrl(absoluteUrl, urlSpace, out urlKind);
        }
Example #7
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="absoluteUrl">The absolute URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            if (absoluteUrl.StartsWith("http") && absoluteUrl.Contains("://"))
            {
                return(UrlProvider.ParseUrl(absoluteUrl, out urlKind));
            }

            var    context  = HttpContext.Current;
            string hostname = context != null ? context.Request.Url.Host : null;
            var    urlSpace = new UrlSpace(hostname, absoluteUrl);

            return(UrlProvider.ParseUrl(absoluteUrl, urlSpace, out urlKind));
        }
        public HyperLinkEqualsValidator(string url, UrlKind kind, params UriComponents[] components)
        {
            this.url  = url;
            this.kind = kind;
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }
            UriComponents tempComponent = components[0];

            components.ToList().ForEach(s => tempComponent |= s);
            finalComponent = tempComponent;
        }
Example #9
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="mediaUrlData">The media URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static string BuildUrl(MediaUrlData mediaUrlData, UrlKind urlKind)
        {
            Verify.ArgumentNotNull(mediaUrlData, "mediaUrlData");

            switch (urlKind)
            {
            case UrlKind.Internal:
                return(BuildInternalUrl(mediaUrlData));

            case UrlKind.Renderer:
                return(BuildRendererUrl(mediaUrlData));

            case UrlKind.Public:
                return(BuildPublicUrl(mediaUrlData));
            }

            throw new NotSupportedException("Not supported url kind. urlKind == '{0}'".FormatWith(urlKind));
        }
Example #10
0
        /// <summary>
        /// Checks href value of element A (hyperlink)
        /// </summary>
        /// <param name="url">Expected value of href.</param>
        /// <param name="kind">Type of url of expected href.</param>
        /// <param name="components">Determines what parts of url should be compared.</param>
        /// <returns></returns>
        public ElementWrapper CheckIfHyperLinkEquals(string url, UrlKind kind, params UriComponents[] components)
        {
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }

            var providedHref = new Uri(WebElement.GetAttribute("href"));

            if (kind == UrlKind.Relative)
            {
                var host = BaseUrl;
                if (string.IsNullOrWhiteSpace(host))
                {
                    host = "http://example.com/";
                }
                else if (!host.EndsWith("/"))
                {
                    host += "/";
                }
                url = host + (url.StartsWith("/") ? url.Substring(1) : url);
            }
            if (kind == UrlKind.Absolute && url.StartsWith("//"))
            {
                url = providedHref.Scheme + ":" + url;
            }
            var           expectedHref   = new Uri(url);
            UriComponents finalComponent = components[0];

            components.ToList().ForEach(s => finalComponent |= s);

            if (Uri.Compare(providedHref, expectedHref, finalComponent, UriFormat.SafeUnescaped,
                            StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new UnexpectedElementStateException($"Link '{FullSelector}' provided value '{providedHref}' of attribute href. Provided value does not match with expected value '{url}'.");
            }

            return(this);
        }
        /// <summary>
        /// Checks if browser can access given Url (browser returns status code 2??).
        /// </summary>
        /// <param name="url"></param>
        /// <param name="urlKind"></param>
        /// <returns></returns>
        public BrowserWrapper CheckIfUrlIsAccessible(string url, UrlKind urlKind)
        {
            var currentUri = new Uri(CurrentUrl);

            if (urlKind == UrlKind.Relative)
            {
                url = GetAbsoluteUrl(url);
            }

            if (urlKind == UrlKind.Absolute && url.StartsWith("//"))
            {
                if (!string.IsNullOrWhiteSpace(currentUri.Scheme))
                {
                    url = currentUri.Scheme + ":" + url;
                }
            }

            HttpWebResponse response = null;

            SeleniumTestBase.Log($"CheckIfUrlIsAccessible: Checking of url: '{url}'", 10);
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "HEAD";

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException e)
            {
                throw new WebException($"Unable to access {url}! {e.Status}", e);
            }
            finally
            {
                response?.Close();
            }
            return(this);
        }
        public PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            Verify.ArgumentNotNullOrEmpty(absoluteUrl, "absoluteUrl");

            // Converting links
            // "http://localhost" to "http://localhost/"
            // "http://localhost?..." to "http://localhost/?..."
            if ((absoluteUrl.Count(c => c == '/') == 2) && absoluteUrl.Contains("//"))
            {
                int questionMarkIndex = absoluteUrl.IndexOf('?');
                if (questionMarkIndex > 0)
                {
                    absoluteUrl = absoluteUrl.Insert(questionMarkIndex, "/");
                }
                else
                {
                    absoluteUrl += "/";
                }
            }

            Uri uri = new Uri(absoluteUrl);

            string hostname = uri.DnsSafeHost;

            if (!IsKnownHostname(hostname))
            {
                urlKind = UrlKind.Undefined;
                return(null);
            }

            string serverUrl   = new UrlBuilder(absoluteUrl).ServerUrl;
            string relativeUrl = absoluteUrl.Substring(serverUrl.Length - 1);

            var urlSpace = new UrlSpace(hostname, relativeUrl);

            return(ParseUrl(relativeUrl, urlSpace, out urlKind));
        }
        public string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind, UrlSpace urlSpace)
        {
            Verify.ArgumentCondition(urlKind != UrlKind.Undefined, "urlKind", "Url kind is undefined");

            /*var page = pageUrlData.Data;
             * Verify.ArgumentCondition(page != null, "urlData", "Failed to get page from UrlData<IPage>");*/

            if (urlKind == UrlKind.Public)
            {
                return(BuildPublicUrl(pageUrlData, urlSpace));
            }

            if (urlKind == UrlKind.Renderer)
            {
                return(BuildRenderUrl(pageUrlData));
            }

            if (urlKind == UrlKind.Internal)
            {
                return(BuildInternalUrl(pageUrlData));
            }

            throw new NotImplementedException("Only 'Public' and 'Internal' url types are supported.");
        }
        public string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind, UrlSpace urlSpace)
        {
            Verify.ArgumentCondition(urlKind != UrlKind.Undefined, "urlKind", "Url kind is undefined");

            /*var page = pageUrlData.Data;
            Verify.ArgumentCondition(page != null, "urlData", "Failed to get page from UrlData<IPage>");*/

            if (urlKind == UrlKind.Public)
            {
                return BuildPublicUrl(pageUrlData, urlSpace);
            }

            if (urlKind == UrlKind.Renderer)
            {
                return BuildRenderUrl(pageUrlData);
            }

            if (urlKind == UrlKind.Internal)
            {
                return BuildInternalUrl(pageUrlData);
            }

            throw new NotImplementedException("Only 'Public' and 'Internal' url types are supported.");
        }
 /// <summary>
 /// Checks if browser can access given Url (browser returns status code 2??).
 /// </summary>
 /// <param name="url"></param>
 /// <param name="urlKind"></param>
 /// <returns></returns>
 public IBrowserWrapperFluentApi CheckIfUrlIsAccessible(string url, UrlKind urlKind)
 {
     return((IBrowserWrapperFluentApi)EvaluateBrowserCheck <BrowserLocationException>(new UrlIsAccessibleValidator(url, urlKind)));
 }
Example #16
0
 /// <summary>
 /// Builds the URL.
 /// </summary>
 /// <param name="mediaFile">The media file.</param>
 /// <param name="urlKind">Kind of the URL.</param>
 /// <returns></returns>
 public static string BuildUrl(IMediaFile mediaFile, UrlKind urlKind = UrlKind.Public)
 {
     return(BuildUrl(new MediaUrlData(mediaFile), urlKind));
 }
 /// <summary>
 /// Compates current Url and given url.
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public bool CompareUrl(string url, UrlKind urlKind, params UriComponents[] components)
 {
     return(new UrlValidator(url, urlKind, components).CompareUrl(CurrentUrl));
 }
Example #18
0
 /// <summary>
 /// Checks href value of element A (hyperlink)
 /// </summary>
 /// <param name="url">Expected value of href.</param>
 /// <param name="kind">Type of url of expected href.</param>
 /// <param name="components">Determines what parts of url should be compared.</param>
 /// <returns></returns>
 public IElementWrapperFluentApi CheckIfHyperLinkEquals(string url, UrlKind kind, params UriComponents[] components)
 {
     return(EvaluateElementCheck <UnexpectedElementStateException>(
                new HyperLinkEqualsValidator(url, kind, true, components)));
 }
Example #19
0
 /// <summary>
 /// Builds the URL.
 /// </summary>
 /// <param name="mediaFile">The media file.</param>
 /// <param name="urlKind">Kind of the URL.</param>
 /// <returns></returns>
 public static string BuildUrl(IMediaFile mediaFile, UrlKind urlKind = UrlKind.Public)
 {
     return BuildUrl(new MediaUrlData(mediaFile), urlKind);
 }
Example #20
0
        private PageUrlData ParseInternalUrl(string relativeUrl, out UrlKind urlKind)
        {
            var urlBuilder = new UrlBuilder(relativeUrl);

            if (IsPageRendererRequest(urlBuilder.FilePath))
            {
                urlKind = UrlKind.Renderer;
                return ParseRendererUrl(urlBuilder);
            }

            urlKind = UrlKind.Undefined;

            string decodedPath = HttpUtility.UrlDecode(urlBuilder.FullPath);

            string prefix = InternalUrlPrefix;

            if (!decodedPath.StartsWith(prefix, true))
            {
                prefix = InternalUrlPrefixResolved;
                if (!decodedPath.StartsWith(prefix, true))
                {
                    return null;
                }
            }

            int closingBracketOffset = decodedPath.IndexOf(')');
            if (closingBracketOffset < 0)
            {
                return null;
            }

            Guid pageId;
            if (!Guid.TryParse(decodedPath.Substring(prefix.Length, closingBracketOffset - prefix.Length), out pageId))
            {
                return null;
            }

            string pathInfo = decodedPath.Substring(closingBracketOffset + 1);
            if (pathInfo.Length > 0 && pathInfo[0] != '/')
            {
                return null;
            }

            bool isUnpublished = pathInfo.Contains(UrlMarker_Unpublished);
            if (isUnpublished)
            {
                pathInfo = pathInfo.Replace(UrlMarker_Unpublished, string.Empty);
            }

            NameValueCollection queryString = urlBuilder.GetQueryParameters();
            string cultureInfoStr = queryString["cultureInfo"];

            CultureInfo cultureInfo;
            if (!cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfo = new CultureInfo(cultureInfoStr);
            }
            else
            {
                cultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                if (cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    cultureInfo = DataLocalizationFacade.DefaultLocalizationCulture;
                }
            }

            queryString.Remove("cultureInfo");

            urlKind = UrlKind.Internal;

            return new PageUrlData(pageId, isUnpublished ? PublicationScope.Unpublished : PublicationScope.Published, cultureInfo)
            {
                PathInfo = pathInfo,
                QueryParameters = queryString
            };
        }
Example #21
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="pageUrlData">The page URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null)
        {
            Verify.ArgumentNotNull(pageUrlData, "pageUrlData");

            return(UrlProvider.BuildUrl(pageUrlData, urlKind, urlSpace ?? new UrlSpace()));
        }
 /// <summary>
 /// Checks url by its parts
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public IBrowserWrapperFluentApi CheckUrl(string url, UrlKind urlKind, params UriComponents[] components)
 {
     return((IBrowserWrapperFluentApi)EvaluateBrowserCheck <BrowserLocationException>(new UrlValidator(url, urlKind, components)));
 }
Example #23
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static MediaUrlData ParseUrl(string relativeUrl, out UrlKind urlKind)
        {
            relativeUrl = relativeUrl.Replace("%28", "(").Replace("%29", ")");

            if (relativeUrl.StartsWith(MediaUrl_RenderPrefix, StringComparison.OrdinalIgnoreCase) ||
                relativeUrl.StartsWith(MediaUrl_UnprocessedRenderPrefix, StringComparison.OrdinalIgnoreCase))
            {
                return(ParseRenderUrl(relativeUrl, out urlKind));
            }

            urlKind = UrlKind.Undefined;

            bool isInternalLink            = relativeUrl.StartsWith(MediaUrl_InternalPrefix, StringComparison.Ordinal);
            bool isInternalUnprocessedLink = !isInternalLink && relativeUrl.StartsWith(MediaUrl_UnprocessedInternalPrefix, StringComparison.Ordinal);

            if (isInternalLink || isInternalUnprocessedLink)
            {
                string prefix = isInternalLink ? MediaUrl_InternalPrefix : MediaUrl_UnprocessedInternalPrefix;

                var result = ParseInternalUrl(relativeUrl, prefix);
                if (result != null)
                {
                    urlKind = UrlKind.Internal;
                }

                return(result);
            }

            int minimumLengthOfPublicMediaUrl = MediaUrl_PublicPrefix.Length + 22; /* 2 - length of a compressed guid */

            if (relativeUrl.Length >= minimumLengthOfPublicMediaUrl &&
                relativeUrl.StartsWith(MediaUrl_PublicPrefix))
            {
                // Parsing urls like /<site root>/media/{MediaId}*
                Guid mediaId;

                if (TryExtractMediaId(relativeUrl, MediaUrl_PublicPrefix.Length, out mediaId))
                {
                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return(new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = DefaultMediaStore,
                        QueryParameters = queryParams
                    });
                }

                // Parsing urls like /<site root>/media/<MediaArchive>/{MediaId}*
                int slashOffset = relativeUrl.IndexOf('/', MediaUrl_PublicPrefix.Length + 1);

                if (slashOffset > MediaUrl_PublicPrefix.Length + 1 &&
                    TryExtractMediaId(relativeUrl, slashOffset + 1, out mediaId))
                {
                    string mediaStore = relativeUrl.Substring(MediaUrl_PublicPrefix.Length, slashOffset - MediaUrl_PublicPrefix.Length);

                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return(new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = mediaStore,
                        QueryParameters = queryParams
                    });
                }
            }

            return(null);
        }
Example #24
0
        public PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind)
        {
            if (IsInternalUrl(relativeUrl))
            {
                return ParseInternalUrl(relativeUrl, out urlKind);
            }

            var urlBuilder = new UrlBuilder(relativeUrl);

            // Structure of a public url:
            // http://<hostname>[/ApplicationVirtualPath]{/languageCode}[/Path to a page][/c1mode(unpublished)][/c1mode(relative)][UrlSuffix]{/PathInfo}
           

            string filePathAndPathInfo = HttpUtility.UrlDecode(urlBuilder.FullPath);
            filePathAndPathInfo = RemoveUrlMarkers(filePathAndPathInfo, urlSpace);

            string pathWithoutLanguageCode;

            IHostnameBinding hostnameBinding = urlSpace.ForceRelativeUrls ? null : GetHostnameBindings().FirstOrDefault(b => b.Hostname == urlSpace.Hostname);

            CultureInfo locale = GetCultureInfo(filePathAndPathInfo, hostnameBinding, out pathWithoutLanguageCode);
            if (locale == null)
            {
                urlKind = UrlKind.Undefined;
                return null;
            }

            var publicationScope = PublicationScope.Published;

            if (filePathAndPathInfo.Contains(UrlMarker_Unpublished))
            {
                publicationScope = PublicationScope.Unpublished;

                pathWithoutLanguageCode = pathWithoutLanguageCode.Replace(UrlMarker_Unpublished, string.Empty);
                if (pathWithoutLanguageCode == string.Empty)
                {
                    pathWithoutLanguageCode = "/";
                }
            }

            using (new DataScope(publicationScope, locale))
            {
                bool isObsolete = false;
                string pathToResolve = pathWithoutLanguageCode;

                // Supporting obsolete "*.aspx" urls
                if (!string.Equals(UrlSuffix, ".aspx", StringComparison.OrdinalIgnoreCase) 
                    && (pathToResolve.Contains(".aspx/") || pathToResolve.EndsWith(".aspx")))
                {
                    pathToResolve = pathToResolve.Replace(".aspx", UrlSuffix);
                    isObsolete = true;
                }

                PageUrlData data = ParsePagePath(pathToResolve, publicationScope, locale, hostnameBinding);
                if (data != null)
                {
                    urlKind = !isObsolete ? UrlKind.Public : UrlKind.Redirect;
                    data.QueryParameters = urlBuilder.GetQueryParameters();
                    return data;
                }

                Guid friendlyUrlPageId = ParseFriendlyUrlPath(pathWithoutLanguageCode);
                if (friendlyUrlPageId != Guid.Empty)
                {
                    urlKind = UrlKind.Friendly;
                    return new PageUrlData(friendlyUrlPageId, publicationScope, locale) {QueryParameters = urlBuilder.GetQueryParameters()};
                }
            }

            urlKind = UrlKind.Undefined;
            return null;
        }
Example #25
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="pageUrlData">The page URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null) 
        {
            Verify.ArgumentNotNull(pageUrlData, "pageUrlData");

            return UrlProvider.BuildUrl(pageUrlData, urlKind, urlSpace ?? new UrlSpace());
        }
Example #26
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(IPage page, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null)
        {
            Verify.ArgumentNotNull(page, "page");

            return BuildUrl(new PageUrlData(page), urlKind, urlSpace ?? new UrlSpace());
        }
Example #27
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static MediaUrlData ParseUrl(string relativeUrl, out UrlKind urlKind)
        {
            relativeUrl = relativeUrl.Replace("%28", "(").Replace("%29", ")");

            if(relativeUrl.StartsWith(MediaUrl_RenderPrefix, StringComparison.OrdinalIgnoreCase)
               || relativeUrl.StartsWith(MediaUrl_UnprocessedRenderPrefix, StringComparison.OrdinalIgnoreCase))
            {
                return ParseRenderUrl(relativeUrl, out urlKind);
            }

            urlKind = UrlKind.Undefined;

            bool isInternalLink = relativeUrl.StartsWith(MediaUrl_InternalPrefix, StringComparison.Ordinal);
            bool isInternalUnprocessedLink = !isInternalLink && relativeUrl.StartsWith(MediaUrl_UnprocessedInternalPrefix, StringComparison.Ordinal);

            if (isInternalLink || isInternalUnprocessedLink)
            {
                string prefix = isInternalLink ? MediaUrl_InternalPrefix : MediaUrl_UnprocessedInternalPrefix;

                var result = ParseInternalUrl(relativeUrl, prefix);
                if(result != null)
                {
                    urlKind = UrlKind.Internal;
                } 

                return result;
            }

            int minimumLengthOfPublicMediaUrl = MediaUrl_PublicPrefix.Length + 22; /* 2 - length of a compressed guid */
            if (relativeUrl.Length >= minimumLengthOfPublicMediaUrl
                && relativeUrl.StartsWith(MediaUrl_PublicPrefix))
            {
                // Parsing urls like /<site root>/media/{MediaId}*
                Guid mediaId;

                if (TryExtractMediaId(relativeUrl, MediaUrl_PublicPrefix.Length, out mediaId))
                {
                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = DefaultMediaStore,
                        QueryParameters = queryParams
                    };
                }

                // Parsing urls like /<site root>/media/<MediaArchive>/{MediaId}*
                int slashOffset = relativeUrl.IndexOf('/', MediaUrl_PublicPrefix.Length + 1);

                if (slashOffset > MediaUrl_PublicPrefix.Length + 1 
                    && TryExtractMediaId(relativeUrl, slashOffset + 1, out mediaId))
                {
                    string mediaStore = relativeUrl.Substring(MediaUrl_PublicPrefix.Length, slashOffset - MediaUrl_PublicPrefix.Length);

                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = mediaStore,
                        QueryParameters = queryParams
                    };
                }
            }

            return null;
        }
Example #28
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="mediaUrlData">The media URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static string BuildUrl(MediaUrlData mediaUrlData, UrlKind urlKind)
        {
            Verify.ArgumentNotNull(mediaUrlData, "mediaUrlData");

            switch (urlKind)
            {
                case UrlKind.Internal:
                    return BuildInternalUrl(mediaUrlData);
                case UrlKind.Renderer:
                    return BuildRendererUrl(mediaUrlData);
                case UrlKind.Public:
                    return BuildPublicUrl(mediaUrlData);
            }

            throw new NotSupportedException("Not supported url kind. urlKind == '{0}'".FormatWith(urlKind));
        }
        public IBrowserWrapperFluentApi CheckIfHyperLinkEquals(string selector, string url, UrlKind kind, params UriComponents[] components)
        {
            var elements  = FindElements(selector);
            var validator = new HyperLinkEqualsValidator(url, kind, components);
            var runner    = new AllOperationRunner <IElementWrapper>(elements);

            runner.Evaluate <UnexpectedElementStateException>(validator);

            return(this);
        }
Example #30
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind) 
        {
            Verify.ArgumentNotNull(relativeUrl, "relativeUrl");

            return UrlProvider.ParseUrl(relativeUrl, urlSpace, out urlKind);
        }
Example #31
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind)
        {
            Verify.ArgumentNotNull(relativeUrl, "relativeUrl");

            return(UrlProvider.ParseUrl(relativeUrl, urlSpace, out urlKind));
        }
Example #32
0
        //TODO
        //public static void HyperLinkEquals(this IOperationRunner<IBrowserWrapper> operationRunner, string selector, string url, UrlKind kind, params UriComponents[] components)
        //{
        //    var HyperLinkEquals = new HyperLinkEqualsValidator(selector, url, kind, components);
        //    operationRunner.Evaluate<UnexpectedElementStateException>(HyperLinkEquals);
        //}

        //public static void IsDisplayed(this IOperationRunner<IBrowserWrapper> operationRunner, string selector, Expression<Func<string, By>> tmpSelectedMethod = null)
        //{
        //    var IsDisplayed = new IsDisplayed();
        //    operationRunner.Evaluate<UnexpectedElementStateException>(IsDisplayed);
        //}
        //public static void IsNotDisplayed(this IOperationRunner<IBrowserWrapper> operationRunner, string selector, Expression<Func<string, By>> tmpSelectedMethod = null)
        //{
        //    var IsNotDisplayed = new Checkers.BrowserWrapperCheckers.IsNotDisplayed(selector, tmpSelectedMethod);
        //    operationRunner.Evaluate<BrowserException>(IsNotDisplayed);
        //}

        public static void UrlIsAccessible(this IOperationRunner <IBrowserWrapper> operationRunner, string url, UrlKind urlKind)
        {
            var UrlIsAccessible = new UrlIsAccessibleValidator(url, urlKind);

            operationRunner.Evaluate <BrowserException>(UrlIsAccessible);
        }
Example #33
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(IPage page, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null)
        {
            Verify.ArgumentNotNull(page, "page");

            return(BuildUrl(new PageUrlData(page), urlKind, urlSpace ?? new UrlSpace()));
        }
Example #34
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public UrlValidator(string url, UrlKind urlKind, params UriComponents[] components)
 {
     this.url        = url;
     this.urlKind    = urlKind;
     this.components = components;
 }
Example #35
0
        public PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            Verify.ArgumentNotNullOrEmpty(absoluteUrl, "absoluteUrl");

            // Converting links 
            // "http://localhost" to "http://localhost/"
            // "http://localhost?..." to "http://localhost/?..."
            if((absoluteUrl.Count(c => c == '/') == 2) && absoluteUrl.Contains("//"))
            {
                int questionMarkIndex = absoluteUrl.IndexOf('?');
                if(questionMarkIndex > 0)
                {
                    absoluteUrl = absoluteUrl.Insert(questionMarkIndex, "/");
                }
                else
                {
                    absoluteUrl += "/";
                }
            }

            Uri uri = new Uri(absoluteUrl);

            string hostname = uri.DnsSafeHost;
            if(!IsKnownHostname(hostname))
            {
                urlKind = UrlKind.Undefined;
                return null;
            }

            string serverUrl = new UrlBuilder(absoluteUrl).ServerUrl;
            string relativeUrl = absoluteUrl.Substring(serverUrl.Length - 1);

            var urlSpace = new UrlSpace(hostname, relativeUrl);

            return ParseUrl(relativeUrl, urlSpace, out urlKind);
        }
Example #36
0
        private static MediaUrlData ParseRenderUrl(string relativeUrl, out UrlKind urlKind)
        {
            try
            {
                var queryParameters = new UrlBuilder(relativeUrl).GetQueryParameters();
                IMediaFile mediaFile = MediaUrlHelper.GetFileFromQueryString(queryParameters);
                Verify.IsNotNull(mediaFile, "failed to get file from a query string");

                urlKind = UrlKind.Renderer;

                queryParameters.Remove("id");
                queryParameters.Remove("i");
                queryParameters.Remove("src");
                queryParameters.Remove("store");

                return new MediaUrlData { MediaId = mediaFile.Id, MediaStore = mediaFile.StoreId, QueryParameters = queryParameters };
            }
            catch(Exception)
            {
                urlKind = UrlKind.Undefined;
                return null;
            }
        }
        private PageUrlData ParseInternalUrl(string relativeUrl, out UrlKind urlKind)
        {
            var urlBuilder = new UrlBuilder(relativeUrl);

            if (IsPageRendererRequest(urlBuilder.FilePath))
            {
                urlKind = UrlKind.Renderer;
                return(ParseRendererUrl(urlBuilder));
            }

            urlKind = UrlKind.Undefined;

            string decodedPath = HttpUtility.UrlDecode(urlBuilder.FullPath);

            string prefix = InternalUrlPrefix;

            if (!decodedPath.StartsWith(prefix, true))
            {
                prefix = InternalUrlPrefixResolved;
                if (!decodedPath.StartsWith(prefix, true))
                {
                    return(null);
                }
            }

            int closingBracketOffset = decodedPath.IndexOf(')');

            if (closingBracketOffset < 0)
            {
                return(null);
            }

            Guid pageId;

            if (!Guid.TryParse(decodedPath.Substring(prefix.Length, closingBracketOffset - prefix.Length), out pageId))
            {
                return(null);
            }

            string pathInfo = decodedPath.Substring(closingBracketOffset + 1);

            bool isUnpublished = pathInfo.Contains(UrlMarker_Unpublished);

            if (isUnpublished)
            {
                pathInfo = pathInfo.Replace(UrlMarker_Unpublished, string.Empty);
            }

            NameValueCollection queryString = urlBuilder.GetQueryParameters();
            string cultureInfoStr           = queryString["cultureInfo"];

            CultureInfo cultureInfo;

            if (!cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfo = new CultureInfo(cultureInfoStr);
            }
            else
            {
                cultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                if (cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    cultureInfo = DataLocalizationFacade.DefaultLocalizationCulture;
                }
            }

            queryString.Remove("cultureInfo");

            urlKind = UrlKind.Internal;

            return(new PageUrlData(pageId, isUnpublished ? PublicationScope.Unpublished : PublicationScope.Published, cultureInfo)
            {
                PathInfo = pathInfo,
                QueryParameters = queryString
            });
        }
Example #38
0
        public static void HyperLineEquals(this IOperationRunner <IElementWrapper> operationRunner, string url, UrlKind kind, params UriComponents[] components)
        {
            var HyperLinkEquals = new HyperLinkEqualsValidator(url, kind, true, components);

            operationRunner.Evaluate <UnexpectedElementStateException>(HyperLinkEquals);
        }
        public PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind)
        {
            if (IsInternalUrl(relativeUrl))
            {
                return(ParseInternalUrl(relativeUrl, out urlKind));
            }

            var urlBuilder = new UrlBuilder(relativeUrl);

            // Structure of a public url:
            // http://<hostname>[/ApplicationVirtualPath]{/languageCode}[/Path to a page][/c1mode(unpublished)][/c1mode(relative)][UrlSuffix]{/PathInfo}


            string filePathAndPathInfo = HttpUtility.UrlDecode(urlBuilder.FullPath);

            filePathAndPathInfo = RemoveUrlMarkers(filePathAndPathInfo, urlSpace);

            string pathWithoutLanguageCode;

            IHostnameBinding hostnameBinding = urlSpace.ForceRelativeUrls ? null : GetHostnameBindings().FirstOrDefault(b => b.Hostname == urlSpace.Hostname);

            CultureInfo locale = GetCultureInfo(filePathAndPathInfo, hostnameBinding, out pathWithoutLanguageCode);

            if (locale == null)
            {
                urlKind = UrlKind.Undefined;
                return(null);
            }

            var publicationScope = PublicationScope.Published;

            if (filePathAndPathInfo.Contains(UrlMarker_Unpublished))
            {
                publicationScope = PublicationScope.Unpublished;

                pathWithoutLanguageCode = pathWithoutLanguageCode.Replace(UrlMarker_Unpublished, string.Empty);
                if (pathWithoutLanguageCode == string.Empty)
                {
                    pathWithoutLanguageCode = "/";
                }
            }

            using (new DataScope(publicationScope, locale))
            {
                bool   isObsolete    = false;
                string pathToResolve = pathWithoutLanguageCode;

                // Supporting obsolete "*.aspx" urls
                if (!string.Equals(UrlSuffix, ".aspx", StringComparison.OrdinalIgnoreCase) &&
                    (pathToResolve.Contains(".aspx/") || pathToResolve.EndsWith(".aspx")))
                {
                    pathToResolve = pathToResolve.Replace(".aspx", UrlSuffix);
                    isObsolete    = true;
                }

                PageUrlData data = ParsePagePath(pathToResolve, publicationScope, locale, hostnameBinding);
                if (data != null)
                {
                    urlKind = !isObsolete ? UrlKind.Public : UrlKind.Redirect;
                    data.QueryParameters = urlBuilder.GetQueryParameters();
                    return(data);
                }

                Guid friendlyUrlPageId = ParseFriendlyUrlPath(pathWithoutLanguageCode);
                if (friendlyUrlPageId != Guid.Empty)
                {
                    urlKind = UrlKind.Friendly;
                    return(new PageUrlData(friendlyUrlPageId, publicationScope, locale)
                    {
                        QueryParameters = urlBuilder.GetQueryParameters()
                    });
                }
            }

            urlKind = UrlKind.Undefined;
            return(null);
        }
Example #40
0
        public static void Url(this IOperationRunner <IBrowserWrapper> operationRunner, string url, UrlKind urlKind, params UriComponents[] components)
        {
            var checkUrl = new UrlValidator(url, urlKind, components);

            operationRunner.Evaluate <BrowserLocationException>(checkUrl);
        }
 public UrlIsAccessibleValidator(string url, UrlKind urlKind)
 {
     this.url     = url;
     this.urlKind = urlKind;
 }
Example #42
0
        public static void UrlIsAccessible(IBrowserWrapper wrapper, string url, UrlKind urlKind)
        {
            var urlIsAccessible = new UrlIsAccessibleValidator(url, urlKind);

            EvaluateValidator <BrowserException, IBrowserWrapper>(wrapper, urlIsAccessible);
        }