public Given_another_response(HttpServerFixture serverFixture, HttpClientFixture clientFixture) : base(serverFixture, clientFixture) { // Arrange _expectedResponse = new Response(HttpStatusCode.OK, _expectedHeaders, _expectedResponseBody, _expectedElapsedTime); // Act _response = new Response <OperationResponseFixture>(_expectedResponse, _expectedResponseData); }
public void Set_Invalid_Proxy_Fails_RAW() { using var server = HttpServerFixture.StartServer((_, __) => { }); var requestUri = new Uri(new Uri(server.Url), ""); var webRequest = (HttpWebRequest)WebRequest.Create(requestUri); webRequest.Proxy = new WebProxy("non_existent_proxy", false); Assert.Throws <WebException>(() => webRequest.GetResponse()); }
public async Task Copy_RootElement_From_Request_To_IWithRootElement_Deserializer() { using var server = HttpServerFixture.StartServer("success", Handle); var client = new RestClient(server.Url).UseXmlSerializer(); var request = new RestRequest("success") { RootElement = "Success" }; var response = await client.ExecuteAsync <TestResponse>(request); response.Data.Should().NotBeNull(); response.Data !.Message.Should().Be("Works!");
public async Task Set_Invalid_Proxy_Fails() { using var server = HttpServerFixture.StartServer((_, __) => { }); var client = new RestClient(new RestClientOptions(server.Url) { Proxy = new WebProxy("non_existent_proxy", false) }); var request = new RestRequest(); var response = await client.ExecuteAsync(request); Assert.False(response.IsSuccessful); response.ErrorException.Should().BeOfType <HttpRequestException>(); }
public void Set_Invalid_Proxy_Fails() { using var server = HttpServerFixture.StartServer((_, __) => { }); var client = new RestClient(server.Url) { Proxy = new WebProxy("non_existent_proxy", false) }; var request = new RestRequest(); var response = client.Get(request); Assert.False(response.IsSuccessful); Assert.IsInstanceOf <WebException>(response.ErrorException); }
public void Copy_RootElement_From_Request_To_IWithRootElement_Deserializer() { using var server = HttpServerFixture.StartServer("success", Handle); var client = new RestClient(server.Url); var request = new RestRequest("success") { RootElement = "Success" }; var deserializer = new CustomDeserializer(); client.AddHandler(ContentType.Xml, () => deserializer); client.Execute <Response>(request); Assert.AreEqual(request.RootElement, deserializer.RootElement);
public void Use_JsonNet_For_Response() { var expected = Fixture.Create <TestClass>(); using var server = HttpServerFixture.StartServer( (request, response) => { var serializer = new JsonNetSerializer(); response.ContentType = "application/json"; response.ContentEncoding = Encoding.UTF8; response.OutputStream.WriteStringUtf8(serializer.Serialize(expected)); } ); var client = new RestClient(server.Url).UseNewtonsoftJson(); var actual = client.Get <TestClass>(new RestRequest()).Data; actual.Should().BeEquivalentTo(expected); }
public void Use_JsonNet_For_Requests() { using var server = HttpServerFixture.StartServer(CaptureBody); _body = null; var serializer = new JsonNetSerializer(); var testData = Fixture.Create <TestClass>(); var client = new RestClient(server.Url).UseNewtonsoftJson(); var request = new RestRequest().AddJsonBody(testData); var expected = testData; client.Post(request); var actual = serializer.Deserialize <TestClass>(new RestResponse { Content = _body }); actual.Should().BeEquivalentTo(expected); }
public void Use_JsonNet_For_Requests() { using var server = HttpServerFixture.StartServer(CaptureBody); _body = null; var serializer = new SystemTextJsonSerializer(); var testData = Fixture.Create <TestClass>(); var client = new RestClient(server.Url).UseSystemTextJson(); var request = new RestRequest().AddJsonBody(testData); var expected = testData; client.Post(request); var actual = serializer.Deserialize <TestClass>(new RestResponse { Content = _body }); actual.Should().BeEquivalentTo(expected); void CaptureBody(HttpListenerRequest req, HttpListenerResponse response) => _body = req.InputStream.StreamToString(); }
public DownloadFileTests() { _server = HttpServerFixture.StartServer("Assets/Koala.jpg", FileHandler); _client = new RestClient(_server.Url); }
public UITests(HttpServerFixture httpFixture, PlaywrightFixture playwrightFixture, ITestOutputHelper outputHelper) : base(httpFixture, outputHelper) { ArgumentNullException.ThrowIfNull(playwrightFixture); }
public void CreateClient() { _server = HttpServerFixture.StartServer("Assets/Koala.jpg", FileHandler); _client = new RestClient(_server.Url); }
public ReposTests(HttpServerFixture fixture, ITestOutputHelper outputHelper) { Fixture = fixture; Fixture.OutputHelper = outputHelper; OutputHelper = outputHelper; }
/// <summary> /// Initializes a new instance of the <see cref="ApiTests"/> class. /// </summary> /// <param name="fixture">The fixture to use.</param> /// <param name="outputHelper">The test output helper to use.</param> public ApiTests(HttpServerFixture fixture, ITestOutputHelper outputHelper) : base(fixture, outputHelper) { }
public Given_typed_response_OK_with_headers_and_body(HttpServerFixture serverFixture, HttpClientFixture clientFixture) : base(serverFixture, clientFixture) { // Act _response = new Response <OperationResponseFixture>(HttpStatusCode.OK, _expectedHeaders, _expectedResponseBody, _expectedResponseData, _expectedElapsedTime); }
public Given_simple_response_OK_with_headers_and_body(HttpServerFixture serverFixture, HttpClientFixture clientFixture) : base(serverFixture, clientFixture) { // Act _response = new Response(HttpStatusCode.OK, _expectedHeaders, _expectedResponseBody, _expectedElapsedTime); }
public HttpApplicationTests(HttpServerFixture fixture, ITestOutputHelper outputHelper) { Fixture = fixture; Fixture.OutputHelper = outputHelper; }
/// <summary> /// Initializes a new instance of the <see cref="IntegrationTest"/> class. /// </summary> /// <param name="fixture">The fixture to use.</param> /// <param name="outputHelper">The test output helper to use.</param> protected IntegrationTest(HttpServerFixture fixture, ITestOutputHelper outputHelper) { Fixture = fixture; OutputHelper = outputHelper; Fixture.SetOutputHelper(OutputHelper); }
protected AcceptanceTest(HttpServerFixture fixture) => this.fixture = fixture;