Esempio n. 1
0
 public RecordTransport(RecordSession session, HttpPipelineTransport innerTransport, Func <RecordEntry, EntryRecordModel> filter, Random random)
 {
     _innerTransport = innerTransport;
     _filter         = filter;
     _random         = random;
     _session        = session;
 }
Esempio n. 2
0
        public static RecordSession Deserialize(JsonElement element)
        {
            var session = new RecordSession();

            if (element.TryGetProperty(nameof(Entries), out JsonElement property))
            {
                foreach (JsonElement item in property.EnumerateArray())
                {
                    session.Entries.Add(RecordEntry.Deserialize(item));
                }
            }

            if (element.TryGetProperty(nameof(Variables), out property))
            {
                foreach (JsonProperty item in property.EnumerateObject())
                {
                    session.Variables[item.Name] = item.Value.GetString();
                }
            }

            if (element.TryGetProperty(nameof(Names), out property))
            {
                foreach (JsonProperty item in property.EnumerateObject())
                {
                    var queue = new Queue <string>();
                    foreach (JsonElement subItem in item.Value.EnumerateArray())
                    {
                        queue.Enqueue(subItem.GetString());
                    }
                    session.Names[item.Name] = queue;
                }
            }
            return(session);
        }
Esempio n. 3
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. 5
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;
 }
        public virtual void Sanitize(RecordSession session)
        {
            foreach (RecordEntry entry in session.Entries)
            {
                Sanitize(entry);
            }

            foreach (KeyValuePair <string, string> variable in session.Variables.ToArray())
            {
                session.Variables[variable.Key] = SanitizeVariable(variable.Key, variable.Value);
            }
        }
Esempio n. 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)));
        }
Esempio n. 8
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. 9
0
 private RecordSession Load()
 {
     using FileStream fileStream     = File.OpenRead(_sessionFile);
     using JsonDocument jsonDocument = JsonDocument.Parse(fileStream);
     return(RecordSession.Deserialize(jsonDocument.RootElement));
 }