Exemplo n.º 1
0
        public void GetCanonical_DoesNotError()
        {
            // arrange
            string canonJson = File.ReadAllText(".\\TestData\\canon.json");

            RdostrId[]       rdostrId         = JsonConvert.DeserializeObject <RdostrId[]>(canonJson);
            string           radiohead        = "Radiohead";
            string           jackieWilson     = "Jackie Wilson";
            CanonicalService canonicalService = new CanonicalService();

            // act
            try
            {
                RdostrId artistRdostrId0 = canonicalService.GetArtistId(radiohead);
                RdostrId artistRdostrId1 = canonicalService.GetArtistId(jackieWilson);

                // assert
                Assert.AreEqual(rdostrId[0].Urn, artistRdostrId0.Urn);
                Assert.AreEqual(rdostrId[0].UrnId, artistRdostrId0.UrnId);
                Assert.AreEqual(rdostrId[1].Urn, artistRdostrId1.Urn);
                Assert.AreEqual(rdostrId[1].UrnId, artistRdostrId1.UrnId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Exemplo n.º 2
0
        public void CanonicaliseUrl_ShouldChangeProtocolToMatchExpected(string inputUrl, bool enableHttps, string expectedResult)
        {
            var service = new CanonicalService
            {
                HostName    = "example.com",
                EnableHttps = enableHttps
            };

            var result = service.CanonicaliseUrl(inputUrl);

            result.Should().Be(expectedResult);
        }
Exemplo n.º 3
0
        public void CanonicaliseUrl_ShouldLowercaseQueryKey_ButNotQueryValue(string inputUrl, string expectedResult)
        {
            var parsedHost = new Uri(inputUrl).Host;
            var service    = new CanonicalService
            {
                HostName            = parsedHost,
                EnableTrailingSlash = false,
                EnableLowerCase     = true,
            };

            var result = service.CanonicaliseUrl(inputUrl);

            result.Should().Be(expectedResult);
        }
Exemplo n.º 4
0
        public void CanonicaliseUrl_ShouldReturnSameResult_WhenCanonical(
            string hostName, bool enableTrailingSlash, bool enableLowerCase, string inputUrl)
        {
            var service = new CanonicalService
            {
                HostName            = hostName,
                EnableTrailingSlash = enableTrailingSlash,
                EnableLowerCase     = enableLowerCase,
            };

            var result = service.CanonicaliseUrl(inputUrl);

            result.Should().Be(expected: inputUrl);
        }
Exemplo n.º 5
0
        public void CanonicaliseUrl_ShouldTrimTrailingSlashes_WhenEnabled(string inputUrl, string expectedResult)
        {
            var parsedHost = new Uri(inputUrl).Host;
            var service    = new CanonicalService
            {
                HostName            = parsedHost,
                EnableTrailingSlash = false,
                EnableLowerCase     = true,
            };

            var result = service.CanonicaliseUrl(inputUrl);

            result.Should().Be(expectedResult);
        }
Exemplo n.º 6
0
        public void CanonicaliseUrl_ShouldProduceResult_WhenCallingOverrides()
        {
            var inputUrl       = new Uri("https://example.com/Ok/Hi/");
            var expectedResult = "https://example.com/ok/hi";

            var service = new CanonicalService
            {
                HostName            = "example.com",
                EnableTrailingSlash = false,
                EnableLowerCase     = true,
            };

            var result = service.CanonicaliseUrl(inputUrl);

            result.Should().Be(expectedResult);
        }
Exemplo n.º 7
0
        public void CanonicaliseUrl_ShouldRemovePort_WhenDefault(string inputUrl, bool expectedPortRemoved)
        {
            var service = new CanonicalService
            {
                HostName            = "example.com",
                EnableTrailingSlash = true,
                EnableLowerCase     = true,
            };

            var result = service.CanonicaliseUrl(inputUrl);

            if (expectedPortRemoved)
            {
                result.Should().NotMatchRegex(@":\d+");
            }
            else
            {
                result.Should().MatchRegex(@":\d+");
            }
        }