Пример #1
0
        public void ItShouldNotAllowMultipleContexts()
        {
            using var context = new HttpRecorderContext();
            Action act = () => { var ctx2 = new HttpRecorderContext(); };

            act.Should().Throw <HttpRecorderException>().WithMessage("*multiple*");
        }
Пример #2
0
        public async Task ItShouldWorkWithHttpRecorderContextWhenNotRecording()
        {
            var services = new ServiceCollection();

            services
            .AddHttpRecorderContextSupport()
            .AddHttpClient(
                "TheClient",
                options =>
            {
                options.BaseAddress = _fixture.ServerUri;
            });

            HttpResponseMessage passthroughResponse = null;

            using (var context = new HttpRecorderContext((sp, builder) => new HttpRecorderConfiguration
            {
                Enabled = false,
                Mode = HttpRecorderMode.Record,
                InteractionName = nameof(ItShouldWorkWithHttpRecorderContextWhenNotRecording),
            }))
            {
                var client = services.BuildServiceProvider().GetRequiredService <IHttpClientFactory>().CreateClient("TheClient");
                passthroughResponse = await client.GetAsync(ApiController.JsonUri);

                passthroughResponse.EnsureSuccessStatusCode();
            }

            using (var context = new HttpRecorderContext((sp, builder) => new HttpRecorderConfiguration
            {
                Mode = HttpRecorderMode.Replay,
                InteractionName = nameof(ItShouldWorkWithHttpRecorderContextWhenNotRecording),
            }))
            {
                var         client = services.BuildServiceProvider().GetRequiredService <IHttpClientFactory>().CreateClient("TheClient");
                Func <Task> act    = async() => await client.GetAsync(ApiController.JsonUri);

                act.Should().Throw <HttpRecorderException>();
            }
        }