Ejemplo n.º 1
0
 public UrlShortener(string baseUrl, IAliasRepository repository, IHashScheme hashScheme, IUrlUnwrapper urlUnwrapper)
 {
     BaseUrl        = baseUrl;
     Repository     = repository;
     HashScheme     = hashScheme;
     UrlUnwrapper   = urlUnwrapper;
     ProtectedPaths = new string[] {};
 }
Ejemplo n.º 2
0
 private static void ShouldHonorLengthPreference(IHashScheme scheme, string name)
 {
     for (int i = 1; i <= 32; i++)
     {
         scheme.LengthPreference = i;
         scheme.GetKey("some long rambling string that is significantly longer than the expected hash value")
         .Should().HaveLength(i, "{0} should honor length preference", name);
     }
 }
Ejemplo n.º 3
0
 private static void ShouldMeetBasicHashRequirements(IHashScheme scheme, string name)
 {
     for (int i = 0; i < 2048; i++)
     {
         var s = i.ToString();
         scheme.GetKey(s)
         .Should().HaveLength(scheme.LengthPreference)
         .And.NotContain("/")
         .And.NotContain("+")
         .And.NotBe(scheme.GetKey(s, 1),
                    "{0} should permute hash", name);
         var alternates = Enumerable.Range(0, 32).Select(j => scheme.GetKey(s, j));
         alternates.Should().OnlyHaveUniqueItems(
             "{0} should return unique hashes", name);
     }
 }
Ejemplo n.º 4
0
        private void PrintExamples(IHashScheme scheme, string name)
        {
            Console.WriteLine(name);
            Console.WriteLine(new String('=', name.Length));
            var examples = new[]
            {
                "a", "b", "c",
                "cat", "dog", "fish",
                "the quick brown fox jumped over the lazy dog",
                "http://example.com"
            };

            foreach (var example in examples)
            {
                Console.WriteLine("{0} => {1}", example, scheme.GetKey(example));
            }
            Console.WriteLine();
        }
Ejemplo n.º 5
0
 public UrlShortener(string baseUrl, IAliasRepository repository, IHashScheme hashScheme)
     : this(baseUrl, repository, hashScheme, new WebClientUrlUnwrapper())
 {
 }
Ejemplo n.º 6
0
 private static void ShouldHaveDefaultLengthPreference(IHashScheme scheme, string name)
 {
     scheme.LengthPreference.Should().BeGreaterThan(0,
                                                    "{0} should have a default LengthPreference", name);
 }