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;
            }
        }
Beispiel #2
0
 public TestRecording(RecordedTestMode mode, string sessionFile, RecordedTestSanitizer sanitizer, RecordMatcher matcher)
 {
     Mode         = mode;
     _sessionFile = sessionFile;
     _sanitizer   = sanitizer;
     _matcher     = matcher;
 }
Beispiel #3
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher, RecordedTestSanitizer sanitizer, Random random)
 {
     _session   = session;
     _matcher   = matcher;
     _random    = random;
     _sanitizer = sanitizer;
 }
 public RecordEntry Lookup(Request request, RecordMatcher matcher)
 {
     lock (Entries)
     {
         RecordEntry entry = matcher.FindMatch(request, Entries);
         Entries.Remove(entry);
         return(entry);
     }
 }
        public bool IsEquivalent(RecordSession session, RecordMatcher matcher)
        {
            if (session == null)
            {
                return(false);
            }

            return(session.Variables.SequenceEqual(Variables) &&
                   session.Entries.SequenceEqual(Entries, new EntryEquivalentComparer(matcher)));
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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)));
        }
        public RecordEntry Lookup(Request request, RecordMatcher matcher)
        {
            lock (Entries)
            {
                var index = matcher.FindMatch(request, Entries, out var failureMessage);
                if (index == -1)
                {
                    throw new InvalidOperationException(failureMessage);
                }

                var entry = Entries[index];
                Entries.RemoveAt(index);
                return(entry);
            }
        }
Beispiel #9
0
        public RecordEntry Lookup(Request request, RecordMatcher matcher)
        {
            lock (Entries)
            {
                var index = matcher.FindMatch(request, Entries);
                if (index == -1)
                {
                    throw new InvalidOperationException($"Unable to find recorded request with method {request.Method} and uri {request.UriBuilder.ToString()}");
                }

                var entry = Entries[index];
                Entries.RemoveAt(index);
                return(entry);
            }
        }
Beispiel #10
0
 public EntryEquivalentComparer(RecordMatcher matcher)
 {
     _matcher = matcher;
 }
Beispiel #11
0
 protected RecordedTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync)
 {
     Sanitizer = new RecordedTestSanitizer();
     Matcher   = new RecordMatcher(Sanitizer);
     Mode      = mode;
 }
Beispiel #12
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher, Random random)
 {
     _session = session;
     _matcher = matcher;
     _random  = random;
 }
Beispiel #13
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher)
 {
     _session = session;
     _matcher = matcher;
 }
 protected RecordedTestBase(bool isAsync) : base(isAsync)
 {
     Sanitizer = new RecordedTestSanitizer();
     Matcher   = new RecordMatcher(Sanitizer);
 }