Beispiel #1
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher, RecordedTestSanitizer sanitizer, Random random)
 {
     _session   = session;
     _matcher   = matcher;
     _random    = random;
     _sanitizer = sanitizer;
 }
        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 #3
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);
        }
 public RecordTransport(RecordSession session, HttpPipelineTransport innerTransport, Func<RecordEntry, bool> filter, Random random)
 {
     _innerTransport = innerTransport;
     _filter = filter;
     _random = random;
     _session = session;
 }
        public bool IsEquivalent(RecordSession session, RecordMatcher matcher)
        {
            if (session == null)
            {
                return(false);
            }

            return(session.Variables.SequenceEqual(Variables) &&
                   session.Entries.SequenceEqual(Entries, new EntryEquivalentComparer(matcher)));
        }
        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);
            }
        }
        public void Start()
        {
            switch (Mode)
            {
            case RecordedTestMode.Record:
                _session = new RecordSession();
                break;

            case RecordedTestMode.Playback:
                _session = Load();
                break;
            }
        }
Beispiel #8
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)));
        }
Beispiel #9
0
        public void Start()
        {
            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;
            }
        }
 private RecordSession Load()
 {
     using FileStream fileStream     = File.OpenRead(_sessionFile);
     using JsonDocument jsonDocument = JsonDocument.Parse(fileStream);
     return(RecordSession.Deserialize(jsonDocument.RootElement));
 }
Beispiel #11
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher, Random random)
 {
     _session = session;
     _matcher = matcher;
     _random  = random;
 }
Beispiel #12
0
 public void DisableIdReuse()
 {
     _previousSession = null;
 }
Beispiel #13
0
 public RecordTransport(RecordSession session, HttpPipelineTransport innerTransport, Random random)
 {
     _innerTransport = innerTransport;
     _random         = random;
     _session        = session;
 }
Beispiel #14
0
 public PlaybackTransport(RecordSession session, RecordMatcher matcher)
 {
     _session = session;
     _matcher = matcher;
 }
 public RecordTransport(RecordSession session, HttpPipelineTransport innerTransport)
 {
     _innerTransport = innerTransport;
     _session        = session;
 }