Esempio n. 1
0
        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:
                _session = Load();
                break;
            }
        }
 public PlaybackTransport(RecordSession session, RecordMatcher matcher, RecordedTestSanitizer sanitizer, Random random)
 {
     _session   = session;
     _matcher   = matcher;
     _random    = random;
     _sanitizer = sanitizer;
 }
Esempio n. 3
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher, RecordedTestSanitizer sanitizer, Random random, Func <RecordEntry, bool> skipRequestBodyFilter)
 {
     _session               = session;
     _matcher               = matcher;
     _random                = random;
     _sanitizer             = sanitizer;
     _skipRequestBodyFilter = skipRequestBodyFilter;
 }
Esempio n. 4
0
        public RecordEntry Lookup(RecordEntry requestEntry, RecordMatcher matcher, RecordedTestSanitizer sanitizer)
        {
            sanitizer.Sanitize(requestEntry);

            lock (Entries)
            {
                RecordEntry entry = matcher.FindMatch(requestEntry, Entries);
                Entries.Remove(entry);
                return(entry);
            }
        }
Esempio n. 5
0
        public RecordEntry Lookup(Request request, RecordMatcher matcher, RecordedTestSanitizer sanitizer)
        {
            var requestEntry = RecordTransport.CreateEntry(request, null);

            sanitizer.Sanitize(requestEntry);

            lock (Entries)
            {
                RecordEntry entry = matcher.FindMatch(requestEntry, Entries);
                Entries.Remove(entry);
                return(entry);
            }
        }
Esempio n. 6
0
        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)));
        }
Esempio n. 7
0
        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;
            }
        }
Esempio n. 8
0
 public EntryEquivalentComparer(RecordMatcher matcher)
 {
     _matcher = matcher;
 }
Esempio n. 9
0
 protected RecordedTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync)
 {
     Sanitizer = new RecordedTestSanitizer();
     Matcher   = new RecordMatcher();
     Mode      = mode;
 }