Exemple #1
0
        public void HashCodeIgnoringUriCasing()
        {
            var comparer = new RequestExpectationEqualityComparer(new HttpClientTestingFactorySettings {
                IgnoreUriCasing = true
            });

            // Because GetHashCode may result in different values across different platforms or even processes
            // we can't actually do much validation here beyond asserting general contracts.
            var expectation = new RequestExpectation(HttpMethod.Get, new Uri("https://www.foo.com"));

            // Consistency
            Assert.AreEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(expectation));

            // Equivalence
            var expectationCopy = new RequestExpectation(HttpMethod.Get, new Uri("https://www.foo.com"));

            Assert.AreEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(expectationCopy));

            // Case-insensitivity
            var expectationCaseDifferent = new RequestExpectation(HttpMethod.Get, new Uri("https://www.FOO.com"));

            Assert.AreEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(expectationCopy));

            // Non-colliding
            var otherExpectation = new RequestExpectation(HttpMethod.Post, new Uri("https://www.bar.com"));

            Assert.AreNotEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(otherExpectation));
        }
Exemple #2
0
        public void HashCodeStrictUriCasing()
        {
            var comparer = new RequestExpectationEqualityComparer(new HttpClientTestingFactorySettings {
                IgnoreUriCasing = false
            });

            // Because GetHashCode may result in different values across different platforms or even processes
            // we can't actually do much validation here beyond asserting general contracts.
            var expectation = new RequestExpectation(HttpMethod.Get, new Uri("https://www.foo.com/bar"));

            // Consistency
            Assert.AreEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(expectation));

            // Equivalence
            Assert.AreEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(new RequestExpectation(HttpMethod.Get, new Uri("https://www.foo.com/bar"))));

            // Case-sensitivity
            Assert.AreNotEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(new RequestExpectation(HttpMethod.Get, new Uri("https://www.foo.com/BAR"))));

            // Non-colliding
            Assert.AreNotEqual(comparer.GetHashCode(expectation), comparer.GetHashCode(new RequestExpectation(HttpMethod.Post, new Uri("https://www.baz.com/bar"))));
        }