public void Should_fire_resolve_with_correct_values()
        {
            A.CallTo(() => _urlResolver.Resolve(A <Uri> .Ignored, A <string> .Ignored, A <WebHeaderCollection> .Ignored))
            .Returns("<response status=\"ok\" version=\"1.2\" ><serviceStatus><serverTime>2011-03-04T08:10:29Z</serverTime></serviceStatus></response>");

            const string expectedMethod  = "GET";
            var          expectedHeaders = new WebHeaderCollection();

            var endPointState = new EndPointInfo()
            {
                Uri = "test", HttpMethod = expectedMethod, Headers = expectedHeaders
            };
            var expected = new Uri(string.Format("{0}/test?oauth_consumer_key={1}", _apiUrl, _consumerKey));

            _endpointResolver.HitEndpoint(endPointState);

            A.CallTo(() => _urlResolver.Resolve(A <Uri> .That.Matches(x => x.PathAndQuery == expected.PathAndQuery), expectedMethod, A <WebHeaderCollection> .Ignored))
            .MustHaveHappened();
        }
Esempio n. 2
0
        public IEnumerable <string> Resolve(ResolverContext resolverContext, WebAssetCollection assets)
        {
            var resolvedUrls = new List <string>();

            foreach (var asset in assets)
            {
                resolvedUrls.AddRange(resolverFactory.Create(asset).Resolve(resolverContext));
            }

            return(resolvedUrls
                   .Distinct(StringComparer.OrdinalIgnoreCase)
                   .Select((url) => urlResolver.Resolve(url)));
        }
        public string Filter(string basePath, string content)
        {
            content = urlRegex.Replace(content, match =>
            {
                string url = match.Groups["url"].Value.Trim("'\"".ToCharArray());

                if (url.HasValue() &&
                    !url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
                    !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) &&
                    !url.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
                {
                    url = provider.CombinePaths(basePath, url);

                    return("url('{0}')".FormatWith(resolver.Resolve(url)));
                }

                return("url('{0}')".FormatWith(url));
            });

            return(content);
        }
Esempio n. 4
0
        public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            var r = base.Match(processor, ref slice);

            // only replace links to images
            if (r && processor.Inline is LinkInline {
                IsImage : true
            } link&& !string.IsNullOrEmpty(link.Url))
            {
                // TODO: svg support
                // BitmapImage doesn't support svg, so this is a crude way to avoid errors on rendering
                if (link.Url.EndsWith(".svg"))
                {
                    link.Url = null;
                    return(r);
                }

                link.Url = resolver.Resolve(link.Url);
            }

            return(r);
        }
Esempio n. 5
0
        /// <summary>
        /// Merges the specified assets.
        /// </summary>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="assetHandlerPath">The asset handler path.</param>
        /// <param name="isSecured">if set to <c>true</c> [is secure].</param>
        /// <param name="canCompress">if set to <c>true</c> [can compress].</param>
        /// <param name="assets">The assets.</param>
        /// <returns>The collection of web asset paths.</returns>
        public IList <string> Merge(string contentType, string assetHandlerPath, bool isSecured, bool canCompress, WebAssetItemCollection assets)
        {
            // If the instance object is null.
            if (contentType == null)
            {
                throw new System.ArgumentNullException("contentType");
            }
            if (assetHandlerPath == null)
            {
                throw new System.ArgumentNullException("assetHandlerPath");
            }
            if (assets == null)
            {
                throw new System.ArgumentNullException("assets");
            }

            IList <string> mergedList = new List <string>();
            Func <string, string, string> getRelativePath = (source, version) => _urlResolver.Resolve(_assetRegistry.Locate(source, version));

            Action <WebAssetItemGroup> processGroup = group =>
            {
                if (group.Combined)
                {
                    string id           = _assetRegistry.Store(contentType, group);
                    string virtualPath  = "{0}?{1}={2}".FormatWith(assetHandlerPath, _urlEncoder.Encode(WebAssetHttpHandler.IdParameterName), _urlEncoder.Encode(id));
                    string relativePath = _urlResolver.Resolve(virtualPath);

                    if (!mergedList.Contains(relativePath, StringComparer.OrdinalIgnoreCase))
                    {
                        mergedList.Add(relativePath);
                    }
                }
                else
                {
                    group.Items.Each(i =>
                    {
                        if (!mergedList.Contains(i.Source, StringComparer.OrdinalIgnoreCase))
                        {
                            mergedList.Add(getRelativePath(i.Source, group.Version));
                        }
                    });
                }
            };

            if (!assets.IsEmpty())
            {
                foreach (IWebAssetItem asset in assets)
                {
                    WebAssetItem      item      = asset as WebAssetItem;
                    WebAssetItemGroup itemGroup = asset as WebAssetItemGroup;

                    if (item != null)
                    {
                        mergedList.Add(getRelativePath(item.Source, null));
                    }
                    else if (itemGroup != null)
                    {
                        WebAssetItemGroup frameworkGroup = null;

                        if ((frameworkGroup != null) && !frameworkGroup.Items.IsEmpty())
                        {
                            processGroup(frameworkGroup);
                        }

                        if (!itemGroup.Items.IsEmpty())
                        {
                            processGroup(itemGroup);
                        }
                    }
                }
            }

            // Return the list.
            return(mergedList.ToList());
        }