예제 #1
0
        public void CustomMatcherDefaultMatches()
        {
            var sessionForRetrieval = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json");
            var identicalRequest    = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json").Session.Entries[0];
            var matcher             = new CustomDefaultMatcher();

            sessionForRetrieval.Session.Lookup(identicalRequest, matcher, sanitizers: new List <RecordedTestSanitizer>(), remove: false);
        }
예제 #2
0
        public void CustomMatcherSpecifyIgnoredHeadersMatches()
        {
            var sessionForRetrieval     = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json");
            var differentHeadersRequest = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json").Session.Entries[0];

            differentHeadersRequest.Request.Headers["Accept-Encoding"] = new string[] { "a-test-header-that-shouldn't-match" };

            var matcher = new CustomDefaultMatcher(ignoredHeaders: "Accept-Encoding");

            sessionForRetrieval.Session.Lookup(differentHeadersRequest, matcher, sanitizers: new List <RecordedTestSanitizer>(), remove: false);
        }
예제 #3
0
        public void CustomMatcherDisableBodyMatches()
        {
            var sessionForRetrieval = TestHelpers.LoadRecordSession("Test.RecordEntries/oauth_request.json");
            var differenBodyRequest = TestHelpers.LoadRecordSession("Test.RecordEntries/oauth_request.json").Session.Entries[0];

            differenBodyRequest.Request.Body = Encoding.UTF8.GetBytes("Definitely not the same body");

            var matcher = new CustomDefaultMatcher(compareBodies: false);

            sessionForRetrieval.Session.Lookup(differenBodyRequest, matcher, sanitizers: new List <RecordedTestSanitizer>(), remove: false);
        }
예제 #4
0
        public void CustomMatcherThrowsOnUnmatched()
        {
            var sessionForRetrieval = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json");
            var differentRequest    = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json").Session.Entries[0];
            var matcher             = new CustomDefaultMatcher(excludedHeaders: "Accept-Encoding");

            differentRequest.Request.Headers["Accept-Encoding"] = new string[] { "a-test-header-that-shouldn't-match" };
            differentRequest.RequestUri = "https://shouldntmatch.com";

            Assert.Throws <TestRecordingMismatchException>(() => {
                sessionForRetrieval.Session.Lookup(differentRequest, HeaderlessMatcher, sanitizers: new List <RecordedTestSanitizer>(), remove: false);
            });
        }
예제 #5
0
        public void CustomMatcherSpecifyIgnoredThrowsOnRecordNonPresence()
        {
            var sessionForRetrieval = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json");

            sessionForRetrieval.Session.Entries[0].Request.Headers.Remove("Accept-Encoding");
            var sameOriginalHeadersRequest = TestHelpers.LoadRecordSession("Test.RecordEntries/if_none_match_present.json").Session.Entries[0];

            var matcher = new CustomDefaultMatcher(ignoredHeaders: "Accept-Encoding");

            var assertion = Assert.Throws <TestRecordingMismatchException>(() => {
                sessionForRetrieval.Session.Lookup(sameOriginalHeadersRequest, matcher, sanitizers: new List <RecordedTestSanitizer>(), remove: false);
            });

            Assert.Contains("<Accept-Encoding> is absent in record", assertion.Message);
        }