public async Task <HttpResponseMessage> SendExplorerApiRequest( HttpMethod method, string endpoint, object?data, string testClassName, string vcrSessionName, VCRMode vcrMode = VCRMode.Record) { // For the explorer interactions, most of the times, we don't want to use the cache // So we set the default vcr mode to always record. var testConfig = GetTestConfig(testClassName, vcrSessionName, vcrMode); using var request = new HttpRequestMessage(method, endpoint); if (data != null) { request.Content = new StringContent(JsonSerializer.Serialize(data)); request.Content.Headers.ContentType = new MediaTypeHeaderValue(System.Net.Mime.MediaTypeNames.Application.Json); } using var clientHandler = new HttpClientHandler(); using var cassette = new Cassette(testConfig.VcrCassettePath); using var handler = new ReplayingHandler( clientHandler, testConfig.VcrMode, cassette, RecordingOptions.RecordAll); using var client = CreateDefaultClient(handler); return(await client.SendAsync(request)); }
public ReplayingHandler( VCRMode vcrMode, Cassette cassette, RecordingOptions options = RecordingOptions.SuccessOnly) : base() { this.cassette = cassette; this.options = options; this.vcrMode = vcrMode; }
public ReplayingHandler( HttpMessageHandler innerHandler, VCRMode vcrMode, Cassette cassette, RecordingOptions options) : base(innerHandler) { this.cassette = cassette; this.options = options; this.vcrMode = vcrMode; }
public TestScope OverrideVcrOptions( VCRMode vcrMode = VCRMode.Cache, RecordingOptions recordingOptions = RecordingOptions.SuccessOnly) { var vcrFactory = Scope.GetInstance <VcrApiHttpClientFactory>(); vcrFactory.VcrMode = vcrMode; vcrFactory.RecordingOptions = recordingOptions; return(this); }
#pragma warning disable CA1822 // method should be made static internal TestConfig GetTestConfig(string testClassName, string vcrSessionName, VCRMode vcrMode = VCRMode.Cache) { var vcrCassetteFile = new FileInfo($"../../../.vcr/{testClassName}.{vcrSessionName}.yaml"); // take care to use a small polling interval only when VCR is allowed to playback and we have a non-empty cassette // (i.e. when in Record only mode, the polling interval will be large) var vcrPlayback = vcrMode == VCRMode.Playback || vcrMode == VCRMode.Cache; var pollFrequency = (vcrCassetteFile.Exists && vcrCassetteFile.Length > 0 && vcrPlayback) ? 1 : TestConfig.PollFrequency; return(new TestConfig { AircloakApiKey = TestConfig.AircloakApiKey, DefaultApiUrl = TestConfig.DefaultApiUrl, PollFrequency = pollFrequency, VcrCassettePath = vcrCassetteFile.FullName, VcrMode = vcrMode, }); }