Пример #1
0
        public HttpMessageHandler GetHttpMessageHandler(HttpClientHandler httpClientHandler)
        {
            var handler = _vcr.GetVcrHandler();

            handler.InnerHandler = httpClientHandler;
            return(handler);
        }
Пример #2
0
        public async Task RecordsOnce_RecordsThenPlaybacks()
        {
            using (_vcr.UseCassette("something", RecordMode.Once))
            {
                var vcrHandler = _vcr.GetVcrHandler();
                var httpClient = CreateHttpClient(vcrHandler);
                var response   = await httpClient.GetAsync(s_testUrl);
            }

            using (_vcr.UseCassette("something", RecordMode.None))
            {
                var vcrHandler = _vcr.GetVcrHandler();
                var httpClient = CreateHttpClient(vcrHandler);
                var response   = await httpClient.GetAsync(s_testUrl);
            }

            Assert.True(true);
        }
Пример #3
0
        public CodeChallengeTests()
        {
            var cassettesPath = new DirectoryInfo($"{_baseDirectory}/resources/cassettes");

            _vcr = new VCR(new FileSystemCassetteStorage(cassettesPath));
            var vcrHandler = _vcr.GetVcrHandler();

            vcrHandler.InnerHandler = new HttpClientHandler();
            HttpClient client = new HttpClient(vcrHandler);

            _repository = new CodeChallenge(client);
        }
Пример #4
0
        public KinopoiskApiClientTests()
        {
            var dirInfo = new System.IO.DirectoryInfo("../../../cassettes"); //3 levels up to get to the root of the test project

            _vcr = new VCR(new FileSystemCassetteStorage(dirInfo));

            _clientFactoryMock = new Mock <IHttpClientFactory>();
            _clientFactoryMock
            .Setup(f => f.CreateClient(It.IsAny <string>()))
            .Returns(() =>
            {
                var httpHandler          = _vcr.GetVcrHandler();
                httpHandler.InnerHandler = new HttpClientHandler();
                return(new HttpClient(httpHandler));
            });
        }
        public EndToEndTest(WebApplicationFactory <MergeBot.Startup> factory)
        {
            //the directory created should be included in source
            //control to ensure future runs are playbacked and not recorded.
            var dirInfo = new System.IO.DirectoryInfo("../../../Cassettes"); //3 levels up to get to the root of the test project

            _vcr = new VCR(new FileSystemCassetteStorage(dirInfo));

            _factory = factory.WithWebHostBuilder(c => c.ConfigureTestServices(services => {
                var vcrHandler          = _vcr.GetVcrHandler();
                vcrHandler.InnerHandler = new SocketsHttpHandler {
                    UseCookies = false
                };
                var httpClient = new HttpClient(vcrHandler);
                services.AddSingleton <HttpClient>(httpClient);
            }));
        }
Пример #6
0
        public HomeControllerTest(WebApplicationFactory <SampleWebApp.Startup> factory)
        {
            //the directory created should be included in source
            //control to ensure future runs are playbacked and not recorded.
            var dirInfo = new System.IO.DirectoryInfo("../../../cassettes"); //3 levels up to get to the root of the test project

            _vcr = new VCR(new FileSystemCassetteStorage(dirInfo));

            _factory = factory.WithWebHostBuilder(c =>
            {
                c.ConfigureTestServices(services =>
                {
                    //Override application's HttpClient to use VCR's delegating handler.
                    var vcrHandler = _vcr.GetVcrHandler();
                    services.AddSingleton <HttpClient>(AppHttpClientFactory.Create(vcrHandler));
                });
            });
        }