Canonicalize.Strategies.MapStrategy.Apply C# (CSharp) Method

Apply() public method

Makes a lookup in the backing dictionary for the path and replaces it if matched.
public Apply ( UriBuilder uri ) : void
uri System.UriBuilder The URL to be canonicalized.
return void
        public void Apply(UriBuilder uri)
        {
            string newPath;

            if (_dictionary.TryGetValue(uri.Path, out newPath))
            {
                uri.Path = newPath;
            }
        }

Usage Example

Esempio n. 1
0
        public void AssertUrlChange(string originalUrl, string expectedCanonicalUrl)
        {
            var uriBuilder = new UriBuilder(originalUrl);

            var dictionary = new Dictionary<string, string>
            {
                {"/foo", "/bar"}
            };

            IUrlStrategy strategy = new MapStrategy(dictionary);
            strategy.Apply(uriBuilder);

            Assert.That(uriBuilder.Uri, Is.EqualTo(new Uri(expectedCanonicalUrl)));
        }