public PlaybackTransport(RecordSession session, RecordMatcher matcher, RecordedTestSanitizer sanitizer, Random random, Func <RecordEntry, bool> skipRequestBodyFilter) { _session = session; _matcher = matcher; _random = random; _sanitizer = sanitizer; _skipRequestBodyFilter = skipRequestBodyFilter; }
public RecordEntry Lookup(RecordEntry requestEntry, RecordMatcher matcher, RecordedTestSanitizer sanitizer, bool remove = true) { sanitizer.Sanitize(requestEntry); lock (Entries) { RecordEntry entry = matcher.FindMatch(requestEntry, Entries); if (remove) { Entries.Remove(entry); } return(entry); } }
public bool IsEquivalent(RecordSession session, RecordMatcher matcher) { if (session == null) { return(false); } // The DateTimeOffsetNow variable is updated any time it's used so // we only care that both sessions use it or both sessions don't. var now = TestRecording.DateTimeOffsetNowVariableKey; return(session.Variables.TryGetValue(now, out string _) == Variables.TryGetValue(now, out string _) && session.Variables.Where(v => v.Key != now).SequenceEqual(Variables.Where(v => v.Key != now)) && session.Entries.SequenceEqual(Entries, new EntryEquivalentComparer(matcher))); }
public RecordEntry Lookup(RecordEntry requestEntry, RecordMatcher matcher, IEnumerable <RecordedTestSanitizer> sanitizers, bool remove = true) { foreach (RecordedTestSanitizer sanitizer in sanitizers) { sanitizer.Sanitize(requestEntry); } lock (Entries) { RecordEntry entry = matcher.FindMatch(requestEntry, Entries); if (remove) { Entries.Remove(entry); } return(entry); } }
public RecordEntry Lookup(RecordEntry requestEntry, RecordMatcher matcher, IEnumerable <RecordedTestSanitizer> sanitizers, bool remove = true) { foreach (RecordedTestSanitizer sanitizer in sanitizers) { sanitizer.Sanitize(requestEntry); } // normalize request body with STJ using relaxed escaping to match behavior when Deserializing from session files RecordEntry.NormalizeJsonBody(requestEntry.Request); lock (Entries) { RecordEntry entry = matcher.FindMatch(requestEntry, Entries); if (remove) { Entries.Remove(entry); } return(entry); } }
public TestRecording(RecordedTestMode mode, string sessionFile, RecordedTestSanitizer sanitizer, RecordMatcher matcher) { Mode = mode; _sessionFile = sessionFile; _sanitizer = sanitizer; _matcher = matcher; switch (Mode) { case RecordedTestMode.Record: _session = new RecordSession(); if (File.Exists(_sessionFile)) { try { _previousSession = Load(); } catch (Exception) { // ignore } } break; case RecordedTestMode.Playback: try { _session = Load(); } catch (Exception ex) when(ex is FileNotFoundException || ex is DirectoryNotFoundException) { throw new TestRecordingMismatchException(ex.Message, ex); } break; case RecordedTestMode.RemoteRecord: case RecordedTestMode.RemotePlayback: break; } }
public EntryEquivalentComparer(RecordMatcher matcher) { _matcher = matcher; }