From 0bf817ee9386088f1aa0f75ef41b5502f724e433 Mon Sep 17 00:00:00 2001 From: Bas Dijkstra Date: Wed, 20 Nov 2024 13:55:44 +0100 Subject: [PATCH] Update tests, remove warnings --- .../JsonRequestBodySerializationTests.cs | 2 -- RestAssured.Net.Tests/LoggingTests.cs | 2 -- RestAssured.Net.Tests/NtlmAuthenticationTests.cs | 1 - RestAssured.Net.Tests/QueryParameterTests.cs | 5 ++--- RestAssured.Net.Tests/RequestBodyTests.cs | 1 + RestAssured.Net.Tests/RequestSpecificationTests.cs | 8 +++++++- .../ResponseBodyHtmlVerificationTests.cs | 1 - .../ResponseBodyLengthVerificationTests.cs | 9 +++++++-- RestAssured.Net.Tests/ResponseBodyVerificationTests.cs | 1 + .../ResponseBodyXmlVerificationTests.cs | 6 ++++++ RestAssured.Net.Tests/ResponseHeaderVerificationTests.cs | 3 +++ RestAssured.Net.Tests/TestBase.cs | 7 ++++++- RestAssured.Net.Tests/TimeoutTests.cs | 3 +-- RestAssured.Net.Tests/UserAgentTests.cs | 3 +-- 14 files changed, 35 insertions(+), 17 deletions(-) diff --git a/RestAssured.Net.Tests/JsonRequestBodySerializationTests.cs b/RestAssured.Net.Tests/JsonRequestBodySerializationTests.cs index 9c0bb80..c2c4c8f 100644 --- a/RestAssured.Net.Tests/JsonRequestBodySerializationTests.cs +++ b/RestAssured.Net.Tests/JsonRequestBodySerializationTests.cs @@ -15,10 +15,8 @@ // namespace RestAssured.Tests { - using System; using System.Collections.Generic; using NUnit.Framework; - using RestAssured.Request.Exceptions; using RestAssured.Tests.Models; using WireMock.Matchers; using WireMock.RequestBuilders; diff --git a/RestAssured.Net.Tests/LoggingTests.cs b/RestAssured.Net.Tests/LoggingTests.cs index 47edb6c..3e2f5c8 100644 --- a/RestAssured.Net.Tests/LoggingTests.cs +++ b/RestAssured.Net.Tests/LoggingTests.cs @@ -18,8 +18,6 @@ namespace RestAssured.Tests using NUnit.Framework; using RestAssured.Logging; using RestAssured.Request.Builders; - using RestAssured.Request.Logging; - using RestAssured.Response.Logging; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; using static RestAssured.Dsl; diff --git a/RestAssured.Net.Tests/NtlmAuthenticationTests.cs b/RestAssured.Net.Tests/NtlmAuthenticationTests.cs index 9c63dbb..b9c4606 100644 --- a/RestAssured.Net.Tests/NtlmAuthenticationTests.cs +++ b/RestAssured.Net.Tests/NtlmAuthenticationTests.cs @@ -16,7 +16,6 @@ namespace RestAssured.Tests { using NUnit.Framework; - using WireMock.Matchers; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; using static RestAssured.Dsl; diff --git a/RestAssured.Net.Tests/QueryParameterTests.cs b/RestAssured.Net.Tests/QueryParameterTests.cs index 0f0664e..1acf6d1 100644 --- a/RestAssured.Net.Tests/QueryParameterTests.cs +++ b/RestAssured.Net.Tests/QueryParameterTests.cs @@ -42,8 +42,7 @@ public class QueryParameterTests : TestBase public void CreateRequestSpecifications() { this.requestSpecification = new RequestSpecBuilder() - .WithScheme("http") - .WithHostName("localhost") + .WithBaseUri("http://localhost") .WithBasePath("api") .WithPort(MOCK_SERVER_PORT) .Build(); @@ -131,7 +130,7 @@ public void MultipleQueryParametersCanBeSpecifiedUsingADictionary() [Test] public void MultipleQueryParametersCanBeSpecifiedUsingAListOfKeyValuePairs() { - List> queryParams = new List>() + var queryParams = new List>() { new KeyValuePair("name", this.name), new KeyValuePair("id", this.firstId), diff --git a/RestAssured.Net.Tests/RequestBodyTests.cs b/RestAssured.Net.Tests/RequestBodyTests.cs index 6ffc577..157a1c8 100644 --- a/RestAssured.Net.Tests/RequestBodyTests.cs +++ b/RestAssured.Net.Tests/RequestBodyTests.cs @@ -36,6 +36,7 @@ public class RequestBodyTests : TestBase /// A test demonstrating RestAssuredNet syntax for sending /// a plaintext request body when performing an HTTP POST. /// + /// The size of the plaintext request body. [TestCase("small", TestName = "Sending small plaintext request body")] [TestCase("medium", TestName = "Sending medium plaintext request body")] [TestCase("large", TestName = "Sending large plaintext request body")] diff --git a/RestAssured.Net.Tests/RequestSpecificationTests.cs b/RestAssured.Net.Tests/RequestSpecificationTests.cs index 9b4af7f..bf05ffa 100644 --- a/RestAssured.Net.Tests/RequestSpecificationTests.cs +++ b/RestAssured.Net.Tests/RequestSpecificationTests.cs @@ -17,6 +17,7 @@ namespace RestAssured.Tests { using System.Text; using NUnit.Framework; + using RestAssured.Logging; using RestAssured.Request.Builders; using RestAssured.Request.Exceptions; using RestAssured.Request.Logging; @@ -40,12 +41,17 @@ public class RequestSpecificationTests : TestBase [TestCase("request-specification", TestName = "With base path in request specification, works without a leading /")] public void FullRequestSpecificationCanBeUsed(string endpoint) { + var logConfig = new LogConfiguration + { + RequestLogLevel = Logging.RequestLogLevel.All, + }; + var fullRequestSpecification = new RequestSpecBuilder() .WithBaseUri("http://localhost:9876") .WithBasePath("api") .WithQueryParam("param_name", "param_value") .WithQueryParam("another_param_name", "another_param_value") - .WithRequestLogLevel(RequestLogLevel.All) + .WithLogConfiguration(logConfig) .Build(); this.CreateStubForRequestSpecification(); diff --git a/RestAssured.Net.Tests/ResponseBodyHtmlVerificationTests.cs b/RestAssured.Net.Tests/ResponseBodyHtmlVerificationTests.cs index 391f18a..6ede995 100644 --- a/RestAssured.Net.Tests/ResponseBodyHtmlVerificationTests.cs +++ b/RestAssured.Net.Tests/ResponseBodyHtmlVerificationTests.cs @@ -15,7 +15,6 @@ // namespace RestAssured.Tests { - using System.Net.Http; using NUnit.Framework; using RestAssured.Response; using RestAssured.Response.Exceptions; diff --git a/RestAssured.Net.Tests/ResponseBodyLengthVerificationTests.cs b/RestAssured.Net.Tests/ResponseBodyLengthVerificationTests.cs index 9c7306d..ef4b6fc 100644 --- a/RestAssured.Net.Tests/ResponseBodyLengthVerificationTests.cs +++ b/RestAssured.Net.Tests/ResponseBodyLengthVerificationTests.cs @@ -15,9 +15,9 @@ // namespace RestAssured.Tests { - using System; using System.Collections.Generic; using NUnit.Framework; + using RestAssured.Logging; using RestAssured.Response.Exceptions; using RestAssured.Tests.Models; using WireMock.RequestBuilders; @@ -83,11 +83,16 @@ public void ResponseBodyLengthCanBeVerified() { this.CreateStubForJsonResponseBody(); + var logConfig = new LogConfiguration + { + ResponseLogLevel = ResponseLogLevel.All, + }; + Given() + .Log(logConfig) .When() .Get($"{MOCK_SERVER_BASE_URL}/json-response-body") .Then() - .Log(RestAssured.Response.Logging.ResponseLogLevel.All) .StatusCode(200) .ResponseBodyLength(NHamcrest.Is.GreaterThan(25)); } diff --git a/RestAssured.Net.Tests/ResponseBodyVerificationTests.cs b/RestAssured.Net.Tests/ResponseBodyVerificationTests.cs index f19cee5..fda59af 100644 --- a/RestAssured.Net.Tests/ResponseBodyVerificationTests.cs +++ b/RestAssured.Net.Tests/ResponseBodyVerificationTests.cs @@ -36,6 +36,7 @@ public class ResponseBodyVerificationTests : TestBase /// A test demonstrating RestAssuredNet syntax for verifying /// a plaintext response body. /// + /// The plain text body size to be used in the test. [TestCase("small")] [TestCase("medium")] [TestCase("large")] diff --git a/RestAssured.Net.Tests/ResponseBodyXmlVerificationTests.cs b/RestAssured.Net.Tests/ResponseBodyXmlVerificationTests.cs index fd4e2a2..a784c85 100644 --- a/RestAssured.Net.Tests/ResponseBodyXmlVerificationTests.cs +++ b/RestAssured.Net.Tests/ResponseBodyXmlVerificationTests.cs @@ -39,6 +39,9 @@ public class ResponseBodyXmlVerificationTests : TestBase private int placeInhabitants; private bool isCapital; + /// + /// Initializes test data used in these tests. + /// [SetUp] public void SetLocation() { @@ -62,6 +65,9 @@ public void SetLocation() this.location.Places.Add(new Place()); } + /// + /// Clears the list of places. + /// [TearDown] public void ClearPlaces() { diff --git a/RestAssured.Net.Tests/ResponseHeaderVerificationTests.cs b/RestAssured.Net.Tests/ResponseHeaderVerificationTests.cs index dc95752..c2cb4ee 100644 --- a/RestAssured.Net.Tests/ResponseHeaderVerificationTests.cs +++ b/RestAssured.Net.Tests/ResponseHeaderVerificationTests.cs @@ -30,6 +30,9 @@ public class ResponseHeaderVerificationTests : TestBase private string headerName; private string headerValue; + /// + /// Initializes the header name and value to be used in the tests. + /// [SetUp] public void InitializeHeaderNameAndValue() { diff --git a/RestAssured.Net.Tests/TestBase.cs b/RestAssured.Net.Tests/TestBase.cs index 41581e0..bf5e837 100644 --- a/RestAssured.Net.Tests/TestBase.cs +++ b/RestAssured.Net.Tests/TestBase.cs @@ -15,7 +15,6 @@ // namespace RestAssured.Tests { - using System; using System.Collections.Generic; using NUnit.Framework; using RestAssured.Tests.Models; @@ -31,8 +30,14 @@ public class TestBase /// protected WireMockServer Server { get; private set; } + /// + /// The port used by the WireMock mock server. + /// protected static readonly int MOCK_SERVER_PORT = 9876; + /// + /// The base URL used by the WireMock mock server. + /// protected static readonly string MOCK_SERVER_BASE_URL = $"http://localhost:{MOCK_SERVER_PORT}"; /// diff --git a/RestAssured.Net.Tests/TimeoutTests.cs b/RestAssured.Net.Tests/TimeoutTests.cs index 6af1653..4ebaacd 100644 --- a/RestAssured.Net.Tests/TimeoutTests.cs +++ b/RestAssured.Net.Tests/TimeoutTests.cs @@ -38,8 +38,7 @@ public class TimeoutTests : TestBase public void CreateRequestSpecifications() { this.requestSpecification = new RequestSpecBuilder() - .WithScheme("http") - .WithHostName("localhost") + .WithBaseUri("http://localhost") .WithPort(9876) .WithTimeout(TimeSpan.FromSeconds(2)) .Build(); diff --git a/RestAssured.Net.Tests/UserAgentTests.cs b/RestAssured.Net.Tests/UserAgentTests.cs index bef95c5..6fd8d96 100644 --- a/RestAssured.Net.Tests/UserAgentTests.cs +++ b/RestAssured.Net.Tests/UserAgentTests.cs @@ -37,8 +37,7 @@ public class UserAgentTests : TestBase public void CreateRequestSpecifications() { this.requestSpecification = new RequestSpecBuilder() - .WithScheme("http") - .WithHostName("localhost") + .WithBaseUri("http://localhost") .WithPort(9876) .WithUserAgent(new ProductInfoHeaderValue("MyUserAgent", "1.0")) .Build();