diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/administrative-supplies.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/administrative-supplies.tsx index 6fbda6a2c..6c7ead4da 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/administrative-supplies.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/administrative-supplies.tsx @@ -46,7 +46,7 @@ export const AdministrativeSupplies: React.FC = ({s
+ aria-labelledby="accordion-heading-administrative-supplies" role="region">

Administrative supplies (Non-educational)

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/catering-staff-services.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/catering-staff-services.tsx index f8e32d6f9..7afb4bd19 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/catering-staff-services.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/catering-staff-services.tsx @@ -93,7 +93,7 @@ export const CateringStaffServices: React.FC = ({sch
+ aria-labelledby="accordion-heading-catering-staff-services" role="region">

Net catering costs

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-ict.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-ict.tsx index 161b3eb6a..7fa9af86d 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-ict.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-ict.tsx @@ -43,7 +43,7 @@ export const EducationalIct: React.FC = ({schools}) => {
+ aria-labelledby="accordion-heading-educational-ict" role="region">

Educational learning resources costs

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-supplies.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-supplies.tsx index c763b9427..b1700d52d 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-supplies.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/educational-supplies.tsx @@ -91,7 +91,7 @@ export const EducationalSupplies: React.FC = ({schools
+ aria-labelledby="accordion-heading-educational-supplies" role="region">

Total educational supplies costs

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/non-educational-support-staff.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/non-educational-support-staff.tsx index d02e10a39..781a27b19 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/non-educational-support-staff.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/non-educational-support-staff.tsx @@ -110,7 +110,7 @@ export const NonEducationalSupportStaff: React.FC
+ aria-labelledby="accordion-heading-non-educational-support-staff" role="region">

Total non-educational support staff costs

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/other-costs.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/other-costs.tsx index 6aafd3a96..084537f1e 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/other-costs.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/other-costs.tsx @@ -251,7 +251,7 @@ export const OtherCosts: React.FC = ({schools}) => {
+ aria-labelledby="accordion-heading-other-cost" role="region">

Total other costs

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/premises-staff-services.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/premises-staff-services.tsx index 942d14242..e08174bca 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/premises-staff-services.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/premises-staff-services.tsx @@ -108,7 +108,7 @@ export const PremisesStaffServices: React.FC = ({sch
+ aria-labelledby="accordion-heading-premises-staff-services" role="region">

Total premises staff and service costs

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/teaching-support-staff.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/teaching-support-staff.tsx index 62ef9234b..9653a88fa 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/teaching-support-staff.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/teaching-support-staff.tsx @@ -123,7 +123,7 @@ export const TeachingSupportStaff: React.FC = ({schoo
+ aria-labelledby="accordion-heading-teaching-support-staff" role="region">

Total teaching and teaching support staff

diff --git a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/utilities.tsx b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/utilities.tsx index 2ed8bbf65..6031a330b 100644 --- a/front-end-components/src/views/compare-your-costs/partials/accordion-sections/utilities.tsx +++ b/front-end-components/src/views/compare-your-costs/partials/accordion-sections/utilities.tsx @@ -75,7 +75,7 @@ export const Utilities: React.FC = ({schools}) => {
+ aria-labelledby="accordion-heading-utilities" role="region">

Total utilities costs

diff --git a/platform/pipelines/build.yaml b/platform/pipelines/build.yaml index 6ef3881de..c57ed29ea 100644 --- a/platform/pipelines/build.yaml +++ b/platform/pipelines/build.yaml @@ -84,8 +84,13 @@ stages: inputs: command: test packagesDirectory: $(NUGET_PACKAGES) - arguments: '--configuration Release --collect "Code coverage"' + arguments: '--configuration Release --collect "Code coverage" --logger "console;verbosity=detailed" --logger "trx;LogFileName=TestResults.trx"' projects: 'platform/**/*.Tests.csproj' + + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'XUnit' + testResultsFiles: '**/TestResults.trx' - job: BuildPlatform dependsOn: [Set_Build_Number] diff --git a/platform/src/search/EducationBenchmarking.Platform.Search.App/EducationBenchmarking.Platform.Search.App.csproj b/platform/src/search/EducationBenchmarking.Platform.Search.App/EducationBenchmarking.Platform.Search.App.csproj index 4aeb403ca..fdf5e09cc 100644 --- a/platform/src/search/EducationBenchmarking.Platform.Search.App/EducationBenchmarking.Platform.Search.App.csproj +++ b/platform/src/search/EducationBenchmarking.Platform.Search.App/EducationBenchmarking.Platform.Search.App.csproj @@ -16,7 +16,6 @@ - diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Drivers/ApiDriver.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Drivers/ApiDriver.cs index e4216b7b7..30ea9053b 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Drivers/ApiDriver.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Drivers/ApiDriver.cs @@ -1,4 +1,5 @@ using EducationBenchmarking.Platform.ApiTests.TestSupport; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Drivers; @@ -6,14 +7,17 @@ namespace EducationBenchmarking.Platform.ApiTests.Drivers; public class ApiDriver : Dictionary { private readonly HttpClient _client; + private readonly ITestOutputHelper _output; - public ApiDriver(Config.Api.ApiEndpoint endpoint) + public ApiDriver(Config.Api.ApiEndpoint endpoint, ITestOutputHelper output) { _client = new HttpClient { BaseAddress = new Uri(endpoint.Host ?? throw new NullException(endpoint.Host)) }; if (!string.IsNullOrEmpty(endpoint.Key)) { _client.DefaultRequestHeaders.Add("x-functions-key", endpoint.Key); } + + _output = output; } public void CreateRequest(string key, HttpRequestMessage request) @@ -26,7 +30,11 @@ public async Task Send() { foreach (var message in this.Where(m => m.Value.Response is null)) { - message.Value.Response = await _client.SendAsync(message.Value.Request); + var response = await _client.SendAsync(message.Value.Request); +#if DEBUG + _output.WriteLine($"{response.RequestMessage?.Method} {response.RequestMessage?.RequestUri} [{(int)response.StatusCode}]"); +#endif + message.Value.Response = response; } } diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkBandingsSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkBandingsSteps.cs index 18c8e71db..3df97cbfe 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkBandingsSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkBandingsSteps.cs @@ -1,22 +1,24 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class BenchmarkBandingsSteps +public class BenchmarkBandingsSteps : BenchmarkSteps { private const string FsmBandingKey = "free-school-meal-banding"; private const string SchoolSizeBandingKey = "school-size-banding"; - private readonly ApiDriver _api = new(Config.Apis.Benchmark ?? throw new NullException(Config.Apis.Benchmark)); + + public BenchmarkBandingsSteps(ITestOutputHelper output) : base(output) + { + } [Given(@"a valid fsm banding request")] public void GivenAValidFsmBandingRequest() { - _api.CreateRequest(FsmBandingKey, new HttpRequestMessage + Api.CreateRequest(FsmBandingKey, new HttpRequestMessage { RequestUri = new Uri("/api/free-school-meal/bandings", UriKind.Relative), Method = HttpMethod.Get @@ -26,7 +28,7 @@ public void GivenAValidFsmBandingRequest() [Then(@"the free school meal banding result should be ok")] public void ThenTheFreeSchoolMealBandingResultShouldBeOk() { - var response = _api[FsmBandingKey].Response ?? throw new NullException(_api[FsmBandingKey].Response); + var response = Api[FsmBandingKey].Response ?? throw new NullException(Api[FsmBandingKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -35,14 +37,14 @@ public void ThenTheFreeSchoolMealBandingResultShouldBeOk() [When(@"I submit the banding request")] public async Task WhenISubmitTheBandingRequest() { - await _api.Send(); + await Api.Send(); } [Then(@"the school size banding result should be ok")] public void ThenTheSchoolSizeBandingResultShouldBeOk() { - var response = _api[SchoolSizeBandingKey].Response ?? - throw new NullException(_api[SchoolSizeBandingKey].Response); + var response = Api[SchoolSizeBandingKey].Response ?? + throw new NullException(Api[SchoolSizeBandingKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -51,7 +53,7 @@ public void ThenTheSchoolSizeBandingResultShouldBeOk() [Given(@"a valid school size banding request")] public void GivenAValidSchoolSizeBandingRequest() { - _api.CreateRequest(SchoolSizeBandingKey, new HttpRequestMessage + Api.CreateRequest(SchoolSizeBandingKey, new HttpRequestMessage { RequestUri = new Uri("/api/school-size/bandings", UriKind.Relative), Method = HttpMethod.Get diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkComparatorSetSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkComparatorSetSteps.cs index 90fe588ce..fbe852b36 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkComparatorSetSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkComparatorSetSteps.cs @@ -1,137 +1,135 @@ using System.Net; using System.Text; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses.Characteristics; using EducationBenchmarking.Platform.Functions.Extensions; using FluentAssertions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using TechTalk.SpecFlow.Assist; +using Xunit.Abstractions; using Xunit.Sdk; -namespace EducationBenchmarking.Platform.ApiTests.Steps +namespace EducationBenchmarking.Platform.ApiTests.Steps; + +[Binding] +public class BenchmarkComparatorSetSteps : BenchmarkSteps { - [Binding] - public class BenchmarkComparatorSetSteps + private const string ComparatorSetCharacteristicsKey = "comparator-set-characteristics"; + private const string GetComparatorSetKey = "get-comparator-set"; + + public BenchmarkComparatorSetSteps(ITestOutputHelper output) : base(output) { - private const string ComparatorSetCharacteristicsKey = "comparator-set-characteristics"; - private const string GetComparatorSetKey = "get-comparator-set"; - private readonly ApiDriver _api = new(Config.Apis.Benchmark ?? throw new NullException(Config.Apis.Benchmark)); + } - [Then(@"the comparator result should be ok")] - public void ThenTheComparatorResultShouldBeOk() - { - var response = _api[GetComparatorSetKey].Response ?? - throw new NullException(_api[GetComparatorSetKey].Response); + [Then(@"the comparator result should be ok")] + public void ThenTheComparatorResultShouldBeOk() + { + var response = Api[GetComparatorSetKey].Response ?? + throw new NullException(Api[GetComparatorSetKey].Response); - response.Should().NotBeNull(); - response.StatusCode.Should().Be(HttpStatusCode.OK); - } + response.Should().NotBeNull(); + response.StatusCode.Should().Be(HttpStatusCode.OK); + } - [Then(@"a valid comparator set of size '(.*)' should be returned")] - public async Task ThenAValidComparatorSetOfSizeShouldBeReturned(string expectedSize) + [Then(@"a valid comparator set of size '(.*)' should be returned")] + public async Task ThenAValidComparatorSetOfSizeShouldBeReturned(string expectedSize) + { + var response = Api[GetComparatorSetKey].Response ?? + throw new NullException(Api[GetComparatorSetKey].Response); + + response.Should().NotBeNull(); + response.StatusCode.Should().Be(HttpStatusCode.OK); + + var responseBody = await response.Content.ReadAsStringAsync(); + var schoolComparatorSet = JsonConvert.DeserializeObject(responseBody); + schoolComparatorSet.Should().NotBeNull(); + schoolComparatorSet!["results"].Should().NotBeNull(); + var schools = schoolComparatorSet["results"]!.ToObject>(); + foreach (var school in schools!) { - var response = _api[GetComparatorSetKey].Response ?? - throw new NullException(_api[GetComparatorSetKey].Response); - - response.Should().NotBeNull(); - response.StatusCode.Should().Be(HttpStatusCode.OK); - - var responseBody = await response.Content.ReadAsStringAsync(); - var schoolComparatorSet = JsonConvert.DeserializeObject(responseBody); - schoolComparatorSet.Should().NotBeNull(); - schoolComparatorSet!["results"].Should().NotBeNull(); - var schools = schoolComparatorSet["results"]!.ToObject>(); - foreach (var school in schools!) - { - school.Should().ContainKey("urn"); - school.Should().ContainKey("name"); - school.Should().ContainKey("financeType"); - school.Should().ContainKey("kind"); - } - - schoolComparatorSet["results"]!.Children().Should().HaveCount(int.Parse(expectedSize)); + school.Should().ContainKey("urn"); + school.Should().ContainKey("name"); + school.Should().ContainKey("financeType"); + school.Should().ContainKey("kind"); } + schoolComparatorSet["results"]!.Children().Should().HaveCount(int.Parse(expectedSize)); + } + - [Given(@"I have a valid comparator set request of size set to '(.*)'")] - public void GivenIHaveAValidComparatorSetRequestOfSizeSetTo(string comparatorSize) + [Given(@"I have a valid comparator set request of size set to '(.*)'")] + public void GivenIHaveAValidComparatorSetRequestOfSizeSetTo(string comparatorSize) + { + var content = new { - var content = new - { - includeSet = "true", size = comparatorSize - }; - - _api.CreateRequest(GetComparatorSetKey, new HttpRequestMessage - { - RequestUri = new Uri("/api/comparator-set", UriKind.Relative), - Method = HttpMethod.Post, - Content = new StringContent(content.ToJson(), Encoding.UTF8, "application/json") - }); - } + includeSet = "true", size = comparatorSize + }; - [Given(@"I have a invalid comparator set request")] - public void GivenIHaveAInvalidComparatorSetRequest() + Api.CreateRequest(GetComparatorSetKey, new HttpRequestMessage { - var content = new - { - includeSet = "true", size = "7", sortMethod = new { sortBy = "bad request" } - }; - - _api.CreateRequest(GetComparatorSetKey, new HttpRequestMessage - { - RequestUri = new Uri("/api/comparator-set", UriKind.Relative), - Method = HttpMethod.Post, - Content = new StringContent(content.ToJson(), Encoding.UTF8, "application/json") - }); - } + RequestUri = new Uri("/api/comparator-set", UriKind.Relative), + Method = HttpMethod.Post, + Content = new StringContent(content.ToJson(), Encoding.UTF8, "application/json") + }); + } - [Given(@"a valid comparator set characteristics request")] - public void GivenAValidComparatorSetCharacteristicsRequest() + [Given(@"I have a invalid comparator set request")] + public void GivenIHaveAInvalidComparatorSetRequest() + { + var content = new { - _api.CreateRequest(ComparatorSetCharacteristicsKey, new HttpRequestMessage - { - RequestUri = new Uri($"/api/comparator-set/characteristics", UriKind.Relative), - Method = HttpMethod.Get - }); - } + includeSet = "true", size = "7", sortMethod = new { sortBy = "bad request" } + }; - [When(@"I submit the comparator set characteristics request")] - [When(@"I submit the comparator set request")] - public async Task WhenISubmitTheComparatorSetRequest() + Api.CreateRequest(GetComparatorSetKey, new HttpRequestMessage { - await _api.Send(); - } + RequestUri = new Uri("/api/comparator-set", UriKind.Relative), + Method = HttpMethod.Post, + Content = new StringContent(content.ToJson(), Encoding.UTF8, "application/json") + }); + } - [Then(@"the comparator set characteristics result should be:")] - public async Task ThenTheComparatorSetCharacteristicsResultShouldBe(Table expectedTable) + [Given(@"a valid comparator set characteristics request")] + public void GivenAValidComparatorSetCharacteristicsRequest() + { + Api.CreateRequest(ComparatorSetCharacteristicsKey, new HttpRequestMessage { - var response = _api[ComparatorSetCharacteristicsKey].Response ?? - throw new NullException(_api[ComparatorSetCharacteristicsKey].Response); + RequestUri = new Uri("/api/comparator-set/characteristics", UriKind.Relative), + Method = HttpMethod.Get + }); + } - response.Should().NotBeNull(); - response.StatusCode.Should().Be(HttpStatusCode.OK); + [When(@"I submit the comparator set characteristics request")] + [When(@"I submit the comparator set request")] + public async Task WhenISubmitTheComparatorSetRequest() + { + await Api.Send(); + } - var content = await response.Content.ReadAsStringAsync(); - var results = content.FromJson>() ?? throw new NullException(content); - var set = new List(); - foreach (var result in results) - { - set.Add(new { result.Code, result.Description }); - } + [Then(@"the comparator set characteristics result should be:")] + public async Task ThenTheComparatorSetCharacteristicsResultShouldBe(Table expectedTable) + { + var response = Api[ComparatorSetCharacteristicsKey].Response ?? + throw new NullException(Api[ComparatorSetCharacteristicsKey].Response); - expectedTable.CompareToDynamicSet(set, false); - } + response.Should().NotBeNull(); + response.StatusCode.Should().Be(HttpStatusCode.OK); - [Then(@"the comparator result should be bad request")] - public void ThenTheComparatorResultShouldBeBadRequest() - { - var response = _api[GetComparatorSetKey].Response ?? - throw new NullException(_api[GetComparatorSetKey].Response); + var content = await response.Content.ReadAsStringAsync(); + var results = content.FromJson>() ?? throw new NullException(content); + var set = new List(); + foreach (var result in results) set.Add(new { result.Code, result.Description }); - response.Should().NotBeNull(); - response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - } + expectedTable.CompareToDynamicSet(set, false); + } + + [Then(@"the comparator result should be bad request")] + public void ThenTheComparatorResultShouldBeBadRequest() + { + var response = Api[GetComparatorSetKey].Response ?? + throw new NullException(Api[GetComparatorSetKey].Response); + + response.Should().NotBeNull(); + response.StatusCode.Should().Be(HttpStatusCode.BadRequest); } } \ No newline at end of file diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkHealthcheckSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkHealthcheckSteps.cs index d283fd0ba..c75ace0e2 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkHealthcheckSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkHealthcheckSteps.cs @@ -2,20 +2,24 @@ using EducationBenchmarking.Platform.ApiTests.Drivers; using EducationBenchmarking.Platform.ApiTests.TestSupport; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class BenchmarkHealthcheckSteps +public class BenchmarkHealthcheckSteps : BenchmarkSteps { private const string RequestKey = "health-check"; - private readonly ApiDriver _api = new(Config.Apis.Benchmark ?? throw new NullException(Config.Apis.Benchmark)); + public BenchmarkHealthcheckSteps(ITestOutputHelper output) : base(output) + { + } + [Given("a valid benchmark health check request")] private void GivenAValidBenchmarkHealthCheckRequest() { - _api.CreateRequest(RequestKey, new HttpRequestMessage + Api.CreateRequest(RequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/health", UriKind.Relative), Method = HttpMethod.Get @@ -25,13 +29,13 @@ private void GivenAValidBenchmarkHealthCheckRequest() [When("I submit the benchmark health check request")] private async Task WhenISubmitTheBenchmarkHealthCheckRequest() { - await _api.Send(); + await Api.Send(); } [Then("the benchmark health check result should be healthy")] private async Task ThenTheBenchmarkHealthCheckResultShouldBeHealthy() { - var result = _api[RequestKey].Response ?? throw new NullException(_api[RequestKey].Response); + var result = Api[RequestKey].Response ?? throw new NullException(Api[RequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkSteps.cs new file mode 100644 index 000000000..3e1f644fa --- /dev/null +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/BenchmarkSteps.cs @@ -0,0 +1,16 @@ +using EducationBenchmarking.Platform.ApiTests.Drivers; +using EducationBenchmarking.Platform.ApiTests.TestSupport; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace EducationBenchmarking.Platform.ApiTests.Steps; + +public abstract class BenchmarkSteps +{ + protected readonly ApiDriver Api; + + protected BenchmarkSteps(ITestOutputHelper output) + { + Api = new ApiDriver(Config.Apis.Benchmark ?? throw new NullException(Config.Apis.Benchmark), output); + } +} \ No newline at end of file diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentHealthcheckSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentHealthcheckSteps.cs index 8d18774db..2eb95da73 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentHealthcheckSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentHealthcheckSteps.cs @@ -1,41 +1,43 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class EstablishmentHealthcheckSteps +public class EstablishmentHealthcheckSteps : EstablishmentSteps { private const string RequestKey = "health-check"; - private readonly ApiDriver _api = new(Config.Apis.Establishment ?? throw new NullException(Config.Apis.Establishment)); + + public EstablishmentHealthcheckSteps(ITestOutputHelper output) : base(output) + { + } [Given("a valid establishment health check request")] private void GivenAValidEstablishmentHealthCheckRequest() { - _api.CreateRequest(RequestKey, new HttpRequestMessage + Api.CreateRequest(RequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/health", UriKind.Relative), Method = HttpMethod.Get }); } - + [When("I submit the establishment health check request")] private async Task WhenISubmitTheEstablishmentHealthCheckRequest() { - await _api.Send(); + await Api.Send(); } [Then("the establishment health check result should be healthy")] private async Task ThenTheEstablishmentHealthCheckResultShouldBeHealthy() { - var result = _api[RequestKey].Response ?? throw new NullException(_api[RequestKey].Response); + var result = Api[RequestKey].Response ?? throw new NullException(Api[RequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); - + var content = await result.Content.ReadAsStringAsync(); content.Should().Be("Healthy"); } diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentLocalAuthoritiesSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentLocalAuthoritiesSteps.cs index 750af7b4e..16c68be88 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentLocalAuthoritiesSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentLocalAuthoritiesSteps.cs @@ -1,39 +1,41 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class EstablishmentLocalAuthoritiesSteps +public class EstablishmentLocalAuthoritiesSteps : EstablishmentSteps { private const string GetRequestKey = "get-local-authority"; private const string SuggestRequestKey = "suggest-local-authority"; private const string SearchRequestKey = "search-local-authority"; private const string QueryRequestKey = "query-local-authority"; - private readonly ApiDriver _api = new(Config.Apis.Establishment ?? throw new NullException(Config.Apis.Establishment)); - + + public EstablishmentLocalAuthoritiesSteps(ITestOutputHelper output) : base(output) + { + } + [When("I submit the local authorities request")] private async Task WhenISubmitTheLocalAuthoritiesRequest() { - await _api.Send(); + await Api.Send(); } [Then("the local authority result should be ok")] private void ThenTheLocalAuthorityResultShouldBeOk() { - var result = _api[GetRequestKey].Response ?? throw new NullException(_api[GetRequestKey].Response); + var result = Api[GetRequestKey].Response ?? throw new NullException(Api[GetRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); } - + [Given("a valid local authority request with id '(.*)'")] private void GivenAValidLocalAuthorityRequestWithId(string id) { - _api.CreateRequest(GetRequestKey, new HttpRequestMessage + Api.CreateRequest(GetRequestKey, new HttpRequestMessage { RequestUri = new Uri($"/api/local-authority/{id}", UriKind.Relative), Method = HttpMethod.Get @@ -43,7 +45,7 @@ private void GivenAValidLocalAuthorityRequestWithId(string id) [Given("a valid local authorities suggest request")] private void GivenAValidLocalAuthoritiesSuggestRequest() { - _api.CreateRequest(SuggestRequestKey, new HttpRequestMessage + Api.CreateRequest(SuggestRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/local-authorities/suggest", UriKind.Relative), Method = HttpMethod.Post @@ -53,7 +55,7 @@ private void GivenAValidLocalAuthoritiesSuggestRequest() [Given("a valid local authorities search request")] private void GivenAValidLocalAuthoritiesSearchRequest() { - _api.CreateRequest(SearchRequestKey, new HttpRequestMessage + Api.CreateRequest(SearchRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/local-authorities/search", UriKind.Relative), Method = HttpMethod.Post @@ -63,17 +65,17 @@ private void GivenAValidLocalAuthoritiesSearchRequest() [Given("a valid local authorities query request")] private void GivenAValidLocalAuthoritiesQueryRequest() { - _api.CreateRequest(QueryRequestKey, new HttpRequestMessage + Api.CreateRequest(QueryRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/local-authorities", UriKind.Relative), Method = HttpMethod.Get }); } - + [Then("the local authorities suggest result should be ok")] private void ThenTheLocalAuthoritiesSuggestResultShouldBeOk() { - var result = _api[SuggestRequestKey].Response ?? throw new NullException(_api[SuggestRequestKey].Response); + var result = Api[SuggestRequestKey].Response ?? throw new NullException(Api[SuggestRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); @@ -82,7 +84,7 @@ private void ThenTheLocalAuthoritiesSuggestResultShouldBeOk() [Then("the local authorities search result should be ok")] private void ThenTheLocalAuthoritiesSearchResultShouldBeOk() { - var result = _api[SearchRequestKey].Response ?? throw new NullException(_api[SearchRequestKey].Response); + var result = Api[SearchRequestKey].Response ?? throw new NullException(Api[SearchRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); @@ -91,7 +93,7 @@ private void ThenTheLocalAuthoritiesSearchResultShouldBeOk() [Then("the local authorities query result should be ok")] private void ThenTheLocalAuthoritiesQueryResultShouldBeOk() { - var result = _api[QueryRequestKey].Response ?? throw new NullException(_api[QueryRequestKey].Response); + var result = Api[QueryRequestKey].Response ?? throw new NullException(Api[QueryRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentOrganisationsSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentOrganisationsSteps.cs index 076c8e7cc..9280386c7 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentOrganisationsSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentOrganisationsSteps.cs @@ -1,30 +1,32 @@ using System.Net; using System.Text; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses; using EducationBenchmarking.Platform.Functions; using EducationBenchmarking.Platform.Functions.Extensions; using EducationBenchmarking.Platform.Infrastructure.Search; using FluentAssertions; using TechTalk.SpecFlow.Assist; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class EstablishmentOrganisationsSteps +public class EstablishmentOrganisationsSteps : EstablishmentSteps { private const string SuggestValidRequestKey = "suggest-organisation-valid"; private const string SuggestInvalidRequestKey = "suggest-organisation-invalid"; - private readonly ApiDriver _api = new(Config.Apis.Establishment ?? throw new NullException(Config.Apis.Establishment)); - + + public EstablishmentOrganisationsSteps(ITestOutputHelper output) : base(output) + { + } + [Given("a valid organisations suggest request")] private void GivenAValidOrganisationsSuggestRequest() { var content = new { SearchText = "school", Size = 10, SuggesterName = "organisation-suggester" }; - - _api.CreateRequest(SuggestValidRequestKey, new HttpRequestMessage + + Api.CreateRequest(SuggestValidRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/organisations/suggest", UriKind.Relative), Method = HttpMethod.Post, @@ -35,33 +37,32 @@ private void GivenAValidOrganisationsSuggestRequest() [When("I submit the organisations request")] private async Task WhenISubmitTheOrganisationsRequest() { - await _api.Send(); + await Api.Send(); } [Then("the organisations suggest result should be:")] private async Task ThenTheOrganisationsSuggestResultShouldBe(Table table) { - var response = _api[SuggestValidRequestKey].Response ?? throw new NullException(_api[SuggestValidRequestKey].Response); + var response = Api[SuggestValidRequestKey].Response ?? + throw new NullException(Api[SuggestValidRequestKey].Response); response.StatusCode.Should().Be(HttpStatusCode.OK); - + var content = await response.Content.ReadAsByteArrayAsync(); var results = content.FromJson>()?.Results ?? throw new NullException(content); - + var set = new List(); foreach (var result in results) - { - set.Add(new { result.Text, result.Document?.Identifier, result.Document?.Kind }); - } + set.Add(new { result.Text, result.Document?.Identifier, result.Document?.Kind }); - table.CompareToDynamicSet(set,false); + table.CompareToDynamicSet(set, false); } [Given("an invalid organisations suggest request")] private void GivenAnInvalidOrganisationsSuggestRequest() { var content = new { Size = 0 }; - - _api.CreateRequest(SuggestInvalidRequestKey, new HttpRequestMessage + + Api.CreateRequest(SuggestInvalidRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/organisations/suggest", UriKind.Relative), Method = HttpMethod.Post, @@ -72,18 +73,16 @@ private void GivenAnInvalidOrganisationsSuggestRequest() [Then("the organisations suggest result should have the follow validation errors:")] private async Task ThenTheOrganisationsSuggestResultShouldHaveTheFollowValidationErrors(Table table) { - var response = _api[SuggestInvalidRequestKey].Response ?? throw new NullException(_api[SuggestInvalidRequestKey].Response); + var response = Api[SuggestInvalidRequestKey].Response ?? + throw new NullException(Api[SuggestInvalidRequestKey].Response); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - + var content = await response.Content.ReadAsByteArrayAsync(); var results = content.FromJson() ?? throw new NullException(content); - + var set = new List(); - foreach (var result in results) - { - set.Add(new { result.PropertyName, result.ErrorMessage }); - } - - table.CompareToDynamicSet(set,false); + foreach (var result in results) set.Add(new { result.PropertyName, result.ErrorMessage }); + + table.CompareToDynamicSet(set, false); } } \ No newline at end of file diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSchoolsSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSchoolsSteps.cs index 64670c921..116076183 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSchoolsSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSchoolsSteps.cs @@ -1,19 +1,18 @@ using System.Net; using System.Text; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses; using EducationBenchmarking.Platform.Functions; using EducationBenchmarking.Platform.Functions.Extensions; using EducationBenchmarking.Platform.Infrastructure.Search; using FluentAssertions; using TechTalk.SpecFlow.Assist; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class EstablishmentSchoolsSteps +public class EstablishmentSchoolsSteps : EstablishmentSteps { private const string GetRequestKey = "get-school"; private const string GetNotFoundRequestKey = "get-school-not-found"; @@ -21,15 +20,17 @@ public class EstablishmentSchoolsSteps private const string SearchRequestKey = "search-school"; private const string SuggestInvalidRequestKey = "suggest-school-invalid"; private const string SuggestValidRequestKey = "suggest-school-invalid"; - private readonly ApiDriver _api = new(Config.Apis.Establishment ?? throw new NullException(Config.Apis.Establishment)); - - + + public EstablishmentSchoolsSteps(ITestOutputHelper output) : base(output) + { + } + [Given("an invalid schools suggest request")] private void GivenAnInvalidSchoolsSuggestRequest() { var content = new { Size = 0 }; - - _api.CreateRequest(SuggestInvalidRequestKey, new HttpRequestMessage + + Api.CreateRequest(SuggestInvalidRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/schools/suggest", UriKind.Relative), Method = HttpMethod.Post, @@ -40,62 +41,58 @@ private void GivenAnInvalidSchoolsSuggestRequest() [When("I submit the schools request")] private async Task WhenISubmitTheSchoolsRequest() { - await _api.Send(); + await Api.Send(); } [Then("the schools suggest result should have the follow validation errors:")] private async Task ThenTheSchoolsSuggestResultShouldHaveTheFollowValidationErrors(Table table) { - var response = _api[SuggestInvalidRequestKey].Response ?? throw new NullException(_api[SuggestInvalidRequestKey].Response); + var response = Api[SuggestInvalidRequestKey].Response ?? + throw new NullException(Api[SuggestInvalidRequestKey].Response); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - + var content = await response.Content.ReadAsByteArrayAsync(); var results = content.FromJson() ?? throw new NullException(content); - + var set = new List(); - foreach (var result in results) - { - set.Add(new { result.PropertyName, result.ErrorMessage }); - } - - table.CompareToDynamicSet(set,false); + foreach (var result in results) set.Add(new { result.PropertyName, result.ErrorMessage }); + + table.CompareToDynamicSet(set, false); } [Given("a valid schools suggest request")] private void GivenAValidSchoolsSuggestRequest() { var content = new { SearchText = "school", Size = 10, SuggesterName = "school-suggester" }; - - _api.CreateRequest(SuggestValidRequestKey, new HttpRequestMessage + + Api.CreateRequest(SuggestValidRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/schools/suggest", UriKind.Relative), Method = HttpMethod.Post, Content = new StringContent(content.ToJson(), Encoding.UTF8, "application/json") }); } - + [Then("the schools suggest result should be:")] private async Task ThenTheSchoolsSuggestResultShouldBe(Table table) { - var response = _api[SuggestValidRequestKey].Response ?? throw new NullException(_api[SuggestValidRequestKey].Response); + var response = Api[SuggestValidRequestKey].Response ?? + throw new NullException(Api[SuggestValidRequestKey].Response); response.StatusCode.Should().Be(HttpStatusCode.OK); - + var content = await response.Content.ReadAsByteArrayAsync(); var results = content.FromJson>()?.Results ?? throw new NullException(content); - + var set = new List(); - foreach (var result in results) - { - set.Add(new { result.Text, result.Document?.Name, result.Document?.Urn }); - } + foreach (var result in results) set.Add(new { result.Text, result.Document?.Name, result.Document?.Urn }); - table.CompareToDynamicSet(set,false); + table.CompareToDynamicSet(set, false); } [Given("a valid school request with id '(.*)'")] private void GivenAValidSchoolRequestWithId(string id) { - _api.CreateRequest(GetRequestKey, new HttpRequestMessage + Api.CreateRequest(GetRequestKey, new HttpRequestMessage { RequestUri = new Uri($"/api/school/{id}", UriKind.Relative), Method = HttpMethod.Get @@ -105,7 +102,7 @@ private void GivenAValidSchoolRequestWithId(string id) [Then("the school result should be ok")] private async Task ThenTheSchoolResultShouldBeOk() { - var response = _api[GetRequestKey].Response ?? throw new NullException(_api[GetRequestKey].Response); + var response = Api[GetRequestKey].Response ?? throw new NullException(Api[GetRequestKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -118,7 +115,7 @@ private async Task ThenTheSchoolResultShouldBeOk() [Given("a invalid school request")] private void GivenAInvalidSchoolRequest() { - _api.CreateRequest(GetNotFoundRequestKey, new HttpRequestMessage + Api.CreateRequest(GetNotFoundRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/school/invalid-urn", UriKind.Relative), Method = HttpMethod.Get @@ -128,7 +125,8 @@ private void GivenAInvalidSchoolRequest() [Then("the school result should be not found")] private void ThenTheSchoolResultShouldBeNotFound() { - var response = _api[GetNotFoundRequestKey].Response ?? throw new NullException(_api[GetNotFoundRequestKey].Response); + var response = Api[GetNotFoundRequestKey].Response ?? + throw new NullException(Api[GetNotFoundRequestKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); @@ -137,7 +135,7 @@ private void ThenTheSchoolResultShouldBeNotFound() [Given("a valid schools query request with page '(.*)'")] private void GivenAValidSchoolsQueryRequestWithPage(string page) { - _api.CreateRequest(QueryRequestKey, new HttpRequestMessage + Api.CreateRequest(QueryRequestKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools?page={page}", UriKind.Relative), Method = HttpMethod.Get @@ -147,7 +145,7 @@ private void GivenAValidSchoolsQueryRequestWithPage(string page) [Then("the schools query result should be page '(.*)' with '(.*)' records")] private async Task ThenTheSchoolsQueryResultShouldBePageWithRecords(int page, int pageSize) { - var response = _api[QueryRequestKey].Response ?? throw new NullException(_api[QueryRequestKey].Response); + var response = Api[QueryRequestKey].Response ?? throw new NullException(Api[QueryRequestKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -161,7 +159,7 @@ private async Task ThenTheSchoolsQueryResultShouldBePageWithRecords(int page, in [Given("a valid schools query request with page size '(.*)'")] private void GivenAValidSchoolsQueryRequestWithPageSize(int pageSize) { - _api.CreateRequest(QueryRequestKey, new HttpRequestMessage + Api.CreateRequest(QueryRequestKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools?pageSize={pageSize}", UriKind.Relative), Method = HttpMethod.Get @@ -172,7 +170,7 @@ private void GivenAValidSchoolsQueryRequestWithPageSize(int pageSize) private void GivenAValidSchoolsSearchRequest() { var content = new { }; - _api.CreateRequest(SearchRequestKey, new HttpRequestMessage + Api.CreateRequest(SearchRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/schools/search", UriKind.Relative), Method = HttpMethod.Post, @@ -183,11 +181,11 @@ private void GivenAValidSchoolsSearchRequest() [Then("the schools search result should be ok")] private async Task ThenTheSchoolsSearchResultShouldBeOk() { - var response = _api[SearchRequestKey].Response ?? throw new NullException(_api[SearchRequestKey].Response); + var response = Api[SearchRequestKey].Response ?? throw new NullException(Api[SearchRequestKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); - + var content = await response.Content.ReadAsByteArrayAsync(); var result = content.FromJson>() ?? throw new NullException(content); diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSteps.cs new file mode 100644 index 000000000..2dd4ea868 --- /dev/null +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentSteps.cs @@ -0,0 +1,16 @@ +using EducationBenchmarking.Platform.ApiTests.Drivers; +using EducationBenchmarking.Platform.ApiTests.TestSupport; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace EducationBenchmarking.Platform.ApiTests.Steps; + +public abstract class EstablishmentSteps +{ + protected readonly ApiDriver Api; + + protected EstablishmentSteps(ITestOutputHelper output) + { + Api = new ApiDriver(Config.Apis.Establishment ?? throw new NullException(Config.Apis.Establishment), output); + } +} \ No newline at end of file diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentTrustsSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentTrustsSteps.cs index 1efb88b8b..f23ad9722 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentTrustsSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/EstablishmentTrustsSteps.cs @@ -1,31 +1,33 @@ using System.Net; using System.Text; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses; using EducationBenchmarking.Platform.Functions; using EducationBenchmarking.Platform.Functions.Extensions; using EducationBenchmarking.Platform.Infrastructure.Search; using FluentAssertions; using TechTalk.SpecFlow.Assist; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class EstablishmentTrustsSteps +public class EstablishmentTrustsSteps : EstablishmentSteps { private const string GetRequestKey = "get-trust"; private const string QueryRequestKey = "query-trust"; private const string SearchRequestKey = "search-trust"; private const string SuggestInvalidRequestKey = "suggest-trust-invalid"; private const string SuggestValidRequestKey = "suggest-trust-invalid"; - private readonly ApiDriver _api = new(Config.Apis.Establishment ?? throw new NullException(Config.Apis.Establishment)); - + + public EstablishmentTrustsSteps(ITestOutputHelper output) : base(output) + { + } + [Given("a valid trust request with id '(.*)'")] private void GivenAValidTrustRequestWithId(string id) { - _api.CreateRequest(GetRequestKey, new HttpRequestMessage + Api.CreateRequest(GetRequestKey, new HttpRequestMessage { RequestUri = new Uri($"/api/trust/{id}", UriKind.Relative), Method = HttpMethod.Get @@ -35,13 +37,13 @@ private void GivenAValidTrustRequestWithId(string id) [When("I submit the trusts request")] private async Task WhenISubmitTheTrustsRequest() { - await _api.Send(); + await Api.Send(); } [Then("the trust result should be ok")] private void ThenTheTrustResultShouldBeOk() { - var result = _api[GetRequestKey].Response ?? throw new NullException(_api[GetRequestKey].Response); + var result = Api[GetRequestKey].Response ?? throw new NullException(Api[GetRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); @@ -50,7 +52,7 @@ private void ThenTheTrustResultShouldBeOk() [Given("a valid trusts query request")] private void GivenAValidTrustsQueryRequest() { - _api.CreateRequest(QueryRequestKey, new HttpRequestMessage + Api.CreateRequest(QueryRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/trusts", UriKind.Relative), Method = HttpMethod.Get @@ -60,7 +62,7 @@ private void GivenAValidTrustsQueryRequest() [Then("the trusts query result should be ok")] private void ThenTheTrustsQueryResultShouldBeOk() { - var result = _api[QueryRequestKey].Response ?? throw new NullException(_api[QueryRequestKey].Response); + var result = Api[QueryRequestKey].Response ?? throw new NullException(Api[QueryRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); @@ -69,7 +71,7 @@ private void ThenTheTrustsQueryResultShouldBeOk() [Given("a valid trusts search request")] private void GivenAValidTrustsSearchRequest() { - _api.CreateRequest(SearchRequestKey, new HttpRequestMessage + Api.CreateRequest(SearchRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/trusts/search", UriKind.Relative), Method = HttpMethod.Post @@ -79,7 +81,7 @@ private void GivenAValidTrustsSearchRequest() [Then("the trusts search result should be ok")] private void ThenTheTrustsSearchResultShouldBeOk() { - var result = _api[SearchRequestKey].Response ?? throw new NullException(_api[SearchRequestKey].Response); + var result = Api[SearchRequestKey].Response ?? throw new NullException(Api[SearchRequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); @@ -89,8 +91,8 @@ private void ThenTheTrustsSearchResultShouldBeOk() private void GivenAnInvalidTrustsSuggestRequest() { var content = new { Size = 0 }; - - _api.CreateRequest(SuggestInvalidRequestKey, new HttpRequestMessage + + Api.CreateRequest(SuggestInvalidRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/trusts/suggest", UriKind.Relative), Method = HttpMethod.Post, @@ -101,27 +103,25 @@ private void GivenAnInvalidTrustsSuggestRequest() [Then("the trusts suggest result should have the follow validation errors:")] private async Task ThenTheTrustsSuggestResultShouldHaveTheFollowValidationErrors(Table table) { - var response = _api[SuggestInvalidRequestKey].Response ?? throw new NullException(_api[SuggestInvalidRequestKey].Response); + var response = Api[SuggestInvalidRequestKey].Response ?? + throw new NullException(Api[SuggestInvalidRequestKey].Response); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - + var content = await response.Content.ReadAsByteArrayAsync(); var results = content.FromJson() ?? throw new NullException(content); - + var set = new List(); - foreach (var result in results) - { - set.Add(new { result.PropertyName, result.ErrorMessage }); - } - - table.CompareToDynamicSet(set,false); + foreach (var result in results) set.Add(new { result.PropertyName, result.ErrorMessage }); + + table.CompareToDynamicSet(set, false); } [Given("a valid trusts suggest request")] private void GivenAValidTrustsSuggestRequest() { var content = new { SearchText = "trust", Size = 10, SuggesterName = "trust-suggester" }; - - _api.CreateRequest(SuggestValidRequestKey, new HttpRequestMessage + + Api.CreateRequest(SuggestValidRequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/trusts/suggest", UriKind.Relative), Method = HttpMethod.Post, @@ -132,18 +132,17 @@ private void GivenAValidTrustsSuggestRequest() [Then("the trusts suggest result should be:")] private async Task ThenTheTrustsSuggestResultShouldBe(Table table) { - var response = _api[SuggestValidRequestKey].Response ?? throw new NullException(_api[SuggestValidRequestKey].Response); + var response = Api[SuggestValidRequestKey].Response ?? + throw new NullException(Api[SuggestValidRequestKey].Response); response.StatusCode.Should().Be(HttpStatusCode.OK); - + var content = await response.Content.ReadAsByteArrayAsync(); var results = content.FromJson>()?.Results ?? throw new NullException(content); - + var set = new List(); foreach (var result in results) - { - set.Add(new { result.Text, result.Document?.Name, result.Document?.CompanyNumber }); - } + set.Add(new { result.Text, result.Document?.Name, result.Document?.CompanyNumber }); - table.CompareToDynamicSet(set,false); + table.CompareToDynamicSet(set, false); } } \ No newline at end of file diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightAcademiesSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightAcademiesSteps.cs index bdbce3b12..dc9a33bf6 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightAcademiesSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightAcademiesSteps.cs @@ -1,23 +1,25 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses; using EducationBenchmarking.Platform.Functions.Extensions; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class InsightAcademiesSteps +public class InsightAcademiesSteps : InsightSteps { private const string GetAcademyKey = "get-academy"; - private readonly ApiDriver _api = new(Config.Apis.Insight ?? throw new NullException(Config.Apis.Insight)); + + public InsightAcademiesSteps(ITestOutputHelper output) : base(output) + { + } [Given(@"a valid academy request with urn '(.*)'")] public void GivenAValidAcademyRequestWithUrn(string urn) { - _api.CreateRequest(GetAcademyKey, new HttpRequestMessage + Api.CreateRequest(GetAcademyKey, new HttpRequestMessage { RequestUri = new Uri($"/api/academy/{urn}", UriKind.Relative), Method = HttpMethod.Get @@ -27,13 +29,13 @@ public void GivenAValidAcademyRequestWithUrn(string urn) [When(@"I submit the academies request")] public async Task WhenISubmitTheAcademiesRequest() { - await _api.Send(); + await Api.Send(); } [Then(@"the academies result should be ok")] public async Task ThenTheAcademiesResultShouldBeOk() { - var response = _api[GetAcademyKey].Response ?? throw new NullException(_api[GetAcademyKey].Response); + var response = Api[GetAcademyKey].Response ?? throw new NullException(Api[GetAcademyKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -46,9 +48,9 @@ public async Task ThenTheAcademiesResultShouldBeOk() [Given(@"a invalid academy request")] public void GivenAInvalidAcademyRequest() { - _api.CreateRequest(GetAcademyKey, new HttpRequestMessage + Api.CreateRequest(GetAcademyKey, new HttpRequestMessage { - RequestUri = new Uri($"/api/academy/00", UriKind.Relative), + RequestUri = new Uri("/api/academy/00", UriKind.Relative), Method = HttpMethod.Get }); } @@ -56,7 +58,7 @@ public void GivenAInvalidAcademyRequest() [Then(@"the academies result should be not found")] public void ThenTheAcademiesResultShouldBeNotFound() { - var response = _api[GetAcademyKey].Response ?? throw new NullException(_api[GetAcademyKey].Response); + var response = Api[GetAcademyKey].Response ?? throw new NullException(Api[GetAcademyKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightHealthcheckSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightHealthcheckSteps.cs index 0f365e030..10bdbe9b1 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightHealthcheckSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightHealthcheckSteps.cs @@ -1,21 +1,23 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class InsightHealthcheckSteps +public class InsightHealthcheckSteps : InsightSteps { private const string RequestKey = "health-check"; - private readonly ApiDriver _api = new(Config.Apis.Insight ?? throw new NullException(Config.Apis.Insight)); + + public InsightHealthcheckSteps(ITestOutputHelper output) : base(output) + { + } [Given("a valid insight health check request")] private void GivenAValidInsightHealthCheckRequest() { - _api.CreateRequest(RequestKey, new HttpRequestMessage + Api.CreateRequest(RequestKey, new HttpRequestMessage { RequestUri = new Uri("/api/health", UriKind.Relative), Method = HttpMethod.Get @@ -25,13 +27,13 @@ private void GivenAValidInsightHealthCheckRequest() [When("I submit the insight health check request")] private async Task WhenISubmitTheInsightHealthCheckRequest() { - await _api.Send(); + await Api.Send(); } [Then("the insight health check result should be healthy")] private async Task ThenTheInsightHealthCheckResultShouldBeHealthy() { - var result = _api[RequestKey].Response ?? throw new NullException(_api[RequestKey].Response); + var result = Api[RequestKey].Response ?? throw new NullException(Api[RequestKey].Response); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.OK); diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMaintainedSchoolsSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMaintainedSchoolsSteps.cs index 3b2199405..3029236fe 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMaintainedSchoolsSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMaintainedSchoolsSteps.cs @@ -1,29 +1,31 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses; using EducationBenchmarking.Platform.Functions.Extensions; using FluentAssertions; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class InsightMaintainedSchoolsSteps +public class InsightMaintainedSchoolsSteps : InsightSteps { private const string GetMaintainedSchoolKey = "get-maintained-school"; - private readonly ApiDriver _api = new(Config.Apis.Insight ?? throw new NullException(Config.Apis.Insight)); + + public InsightMaintainedSchoolsSteps(ITestOutputHelper output) : base(output) + { + } [When(@"I submit the maintained school request")] public async Task WhenISubmitTheMaintainedSchoolRequest() { - await _api.Send(); + await Api.Send(); } [Given(@"a valid maintained school request with urn '(.*)'")] public void GivenAValidMaintainedSchoolRequestWithUrn(string urn) { - _api.CreateRequest(GetMaintainedSchoolKey, new HttpRequestMessage + Api.CreateRequest(GetMaintainedSchoolKey, new HttpRequestMessage { RequestUri = new Uri($"/api/maintained-school/{urn}", UriKind.Relative), Method = HttpMethod.Get @@ -33,8 +35,8 @@ public void GivenAValidMaintainedSchoolRequestWithUrn(string urn) [Then(@"the maintained school result should be ok")] public async Task ThenTheMaintainedSchoolResultShouldBeOk() { - var response = _api[GetMaintainedSchoolKey].Response ?? - throw new NullException(_api[GetMaintainedSchoolKey].Response); + var response = Api[GetMaintainedSchoolKey].Response ?? + throw new NullException(Api[GetMaintainedSchoolKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -47,9 +49,9 @@ public async Task ThenTheMaintainedSchoolResultShouldBeOk() [Given(@"a invalid maintained school request")] public void GivenAInvalidMaintainedSchoolRequest() { - _api.CreateRequest(GetMaintainedSchoolKey, new HttpRequestMessage + Api.CreateRequest(GetMaintainedSchoolKey, new HttpRequestMessage { - RequestUri = new Uri($"/api/maintained-school/00", UriKind.Relative), + RequestUri = new Uri("/api/maintained-school/00", UriKind.Relative), Method = HttpMethod.Get }); } @@ -57,8 +59,8 @@ public void GivenAInvalidMaintainedSchoolRequest() [Then(@"the maintained school result should be not found")] public void ThenTheMaintainedSchoolResultShouldBeNotFound() { - var response = _api[GetMaintainedSchoolKey].Response ?? - throw new NullException(_api[GetMaintainedSchoolKey].Response); + var response = Api[GetMaintainedSchoolKey].Response ?? + throw new NullException(Api[GetMaintainedSchoolKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); } diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMiscellaneousSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMiscellaneousSteps.cs index e0f4de94a..2ef0d5202 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMiscellaneousSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightMiscellaneousSteps.cs @@ -1,25 +1,27 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using FluentAssertions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class InsightMiscellaneousSteps +public class InsightMiscellaneousSteps : InsightSteps { private const string GetFinanceYearKey = "get-finance-year"; - private readonly ApiDriver _api = new(Config.Apis.Insight ?? throw new NullException(Config.Apis.Insight)); + + public InsightMiscellaneousSteps(ITestOutputHelper output) : base(output) + { + } [Given(@"a valid finance year request")] public void GivenAValidFinanceYearRequest() { - _api.CreateRequest(GetFinanceYearKey, new HttpRequestMessage + Api.CreateRequest(GetFinanceYearKey, new HttpRequestMessage { - RequestUri = new Uri($"/api/finance-years", UriKind.Relative), + RequestUri = new Uri("/api/finance-years", UriKind.Relative), Method = HttpMethod.Get }); } @@ -27,13 +29,13 @@ public void GivenAValidFinanceYearRequest() [When(@"I submit the finance year request")] public async Task WhenISubmitTheFinanceYearRequest() { - await _api.Send(); + await Api.Send(); } [Then(@"the finance year result should be ok")] public async Task ThenTheFinanceYearResultShouldBeOk() { - var response = _api[GetFinanceYearKey].Response ?? throw new NullException(_api[GetFinanceYearKey].Response); + var response = Api[GetFinanceYearKey].Response ?? throw new NullException(Api[GetFinanceYearKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSchoolsSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSchoolsSteps.cs index b31183c41..6a2aeb1d3 100644 --- a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSchoolsSteps.cs +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSchoolsSteps.cs @@ -1,32 +1,34 @@ using System.Net; -using EducationBenchmarking.Platform.ApiTests.Drivers; -using EducationBenchmarking.Platform.ApiTests.TestSupport; using EducationBenchmarking.Platform.Domain.Responses; using EducationBenchmarking.Platform.Functions.Extensions; using FluentAssertions; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; using Xunit.Sdk; namespace EducationBenchmarking.Platform.ApiTests.Steps; [Binding] -public class InsightSchoolsSteps +public class InsightSchoolsSteps : InsightSteps { private const string GetSchoolFinancesKey = "get-school-finances"; private const string GetSchoolWorkforceKey = "get-school-workforce"; - private readonly ApiDriver _api = new(Config.Apis.Insight ?? throw new NullException(Config.Apis.Insight)); + + public InsightSchoolsSteps(ITestOutputHelper output) : base(output) + { + } [When(@"I submit the schools insights request")] public async Task WhenISubmitTheSchoolsInsightsRequest() { - await _api.Send(); + await Api.Send(); } [Then(@"the school expenditure result should be ok")] public async Task ThenTheSchoolExpenditureResultShouldBeOk() { - var response = _api[GetSchoolFinancesKey].Response ?? - throw new NullException(_api[GetSchoolFinancesKey].Response); + var response = Api[GetSchoolFinancesKey].Response ?? + throw new NullException(Api[GetSchoolFinancesKey].Response); response.Should().NotBeNull().And.Subject.StatusCode.Should().Be(HttpStatusCode.OK); var jsonString = await response.Content.ReadAsStringAsync(); @@ -50,7 +52,7 @@ public async Task ThenTheSchoolExpenditureResultShouldBeOk() [Given(@"a valid schools expenditure request with urn '(.*)' and '(.*)'")] public void GivenAValidSchoolsExpenditureRequestWithUrnAnd(string urn1, string urn2) { - _api.CreateRequest(GetSchoolFinancesKey, new HttpRequestMessage + Api.CreateRequest(GetSchoolFinancesKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools/expenditure?urns={urn1}%2c{urn2}", UriKind.Relative), Method = HttpMethod.Get @@ -60,7 +62,7 @@ public void GivenAValidSchoolsExpenditureRequestWithUrnAnd(string urn1, string u [Given(@"a valid school expenditure request with page '(.*)' and urn '(.*)'")] public void GivenAValidSchoolExpenditureRequestWithPageAndUrn(string size, string urn) { - _api.CreateRequest(GetSchoolFinancesKey, new HttpRequestMessage + Api.CreateRequest(GetSchoolFinancesKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools/expenditure?urns={urn}&page={size}", UriKind.Relative), Method = HttpMethod.Get @@ -70,8 +72,8 @@ public void GivenAValidSchoolExpenditureRequestWithPageAndUrn(string size, strin [Then(@"the schools expenditure result should be page '(.*)' with '(.*)' page size")] public async Task ThenTheSchoolsExpenditureResultShouldBePageWithPageSize(int page, int pageSize) { - var response = _api[GetSchoolFinancesKey].Response ?? - throw new NullException(_api[GetSchoolFinancesKey].Response); + var response = Api[GetSchoolFinancesKey].Response ?? + throw new NullException(Api[GetSchoolFinancesKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -84,7 +86,7 @@ public async Task ThenTheSchoolsExpenditureResultShouldBePageWithPageSize(int pa [Given(@"a valid school expenditure request with size '(.*)' and urn '(.*)'")] public void GivenAValidSchoolExpenditureRequestWithSizeAndUrn(string pageSize, string urn) { - _api.CreateRequest(GetSchoolFinancesKey, new HttpRequestMessage + Api.CreateRequest(GetSchoolFinancesKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools/expenditure?urns={urn}&pageSize={pageSize}", UriKind.Relative), Method = HttpMethod.Get @@ -94,7 +96,7 @@ public void GivenAValidSchoolExpenditureRequestWithSizeAndUrn(string pageSize, s [Given(@"a valid schools workforce request with urn '(.*)'")] public void GivenAValidSchoolsWorkforceRequestWithUrn(string urn) { - _api.CreateRequest(GetSchoolWorkforceKey, new HttpRequestMessage + Api.CreateRequest(GetSchoolWorkforceKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools/workforce?urns={urn}", UriKind.Relative), Method = HttpMethod.Get @@ -104,8 +106,8 @@ public void GivenAValidSchoolsWorkforceRequestWithUrn(string urn) [Then(@"the school workforce result should be ok")] public async Task ThenTheSchoolWorkforceResultShouldBeOk() { - var response = _api[GetSchoolWorkforceKey].Response ?? - throw new NullException(_api[GetSchoolFinancesKey].Response); + var response = Api[GetSchoolWorkforceKey].Response ?? + throw new NullException(Api[GetSchoolFinancesKey].Response); response.Should().NotBeNull().And.Subject.StatusCode.Should().Be(HttpStatusCode.OK); var jsonString = await response.Content.ReadAsStringAsync(); @@ -124,7 +126,7 @@ public async Task ThenTheSchoolWorkforceResultShouldBeOk() [Given(@"a valid school workforce request with page '(.*)' and urn '(.*)'")] public void GivenAValidSchoolWorkforceRequestWithPageAndUrn(string page, string urn) { - _api.CreateRequest(GetSchoolWorkforceKey, new HttpRequestMessage + Api.CreateRequest(GetSchoolWorkforceKey, new HttpRequestMessage { RequestUri = new Uri($"/api/schools/workforce?urns={urn}&page={page}", UriKind.Relative), Method = HttpMethod.Get @@ -134,8 +136,8 @@ public void GivenAValidSchoolWorkforceRequestWithPageAndUrn(string page, string [Then(@"the schools workforce result should be page '(.*)' with '(.*)' page size")] public async Task ThenTheSchoolsWorkforceResultShouldBePageWithPageSize(int page, int pageSize) { - var response = _api[GetSchoolWorkforceKey].Response ?? - throw new NullException(_api[GetSchoolWorkforceKey].Response); + var response = Api[GetSchoolWorkforceKey].Response ?? + throw new NullException(Api[GetSchoolWorkforceKey].Response); response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); @@ -147,11 +149,11 @@ public async Task ThenTheSchoolsWorkforceResultShouldBePageWithPageSize(int page } [Given(@"a valid school workforce request with size '(.*)' and urn '(.*)'")] - public void GivenAValidSchoolWorkforceRequestWithSizeAndUrn(string urn, string pageSize) + public void GivenAValidSchoolWorkforceRequestWithSizeAndUrn(string pageSize, string urn) { - _api.CreateRequest(GetSchoolWorkforceKey, new HttpRequestMessage + Api.CreateRequest(GetSchoolWorkforceKey, new HttpRequestMessage { - RequestUri = new Uri($"/api/schools/workforce?urns={urn}?pageSize={pageSize}", UriKind.Relative), + RequestUri = new Uri($"/api/schools/workforce?urns={urn}&pageSize={pageSize}", UriKind.Relative), Method = HttpMethod.Get }); } diff --git a/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSteps.cs b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSteps.cs new file mode 100644 index 000000000..91d30e3bf --- /dev/null +++ b/platform/tests/EducationBenchmarking.Platform.ApiTests/Steps/InsightSteps.cs @@ -0,0 +1,16 @@ +using EducationBenchmarking.Platform.ApiTests.Drivers; +using EducationBenchmarking.Platform.ApiTests.TestSupport; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace EducationBenchmarking.Platform.ApiTests.Steps; + +public abstract class InsightSteps +{ + protected readonly ApiDriver Api; + + protected InsightSteps(ITestOutputHelper output) + { + Api = new ApiDriver(Config.Apis.Insight ?? throw new NullException(Config.Apis.Insight), output); + } +} \ No newline at end of file diff --git a/web/pipelines/build.yaml b/web/pipelines/build.yaml index d40a753b7..586b0bb86 100644 --- a/web/pipelines/build.yaml +++ b/web/pipelines/build.yaml @@ -84,8 +84,13 @@ stages: inputs: command: test packagesDirectory: $(NUGET_PACKAGES) - arguments: '--configuration Release --collect "Code coverage"' + arguments: '--configuration Release --collect "Code coverage" --logger "console;verbosity=detailed" --logger "trx;LogFileName=TestResults.trx"' projects: 'web/**/*.Tests.csproj' + + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'XUnit' + testResultsFiles: '**/TestResults.trx' - job: BuildWeb dependsOn: [Set_Build_Number] diff --git a/web/tests/EducationBenchmarking.Web.A11yTests/Steps/AccessibilitySteps.cs b/web/tests/EducationBenchmarking.Web.A11yTests/Steps/AccessibilitySteps.cs index dc03a063b..b5cc06b5e 100644 --- a/web/tests/EducationBenchmarking.Web.A11yTests/Steps/AccessibilitySteps.cs +++ b/web/tests/EducationBenchmarking.Web.A11yTests/Steps/AccessibilitySteps.cs @@ -17,6 +17,9 @@ public sealed class AccessibilitySteps public AccessibilitySteps(ScenarioContext scenarioContext, IPage page, ITestOutputHelper output) { _page = page; +#if DEBUG + _page.Response += (sender, r) => output.WriteLine($"{r.Request.Method} {r.Url} [{r.Status}]"); +#endif _output = output; } diff --git a/web/tests/EducationBenchmarking.Web.E2ETests/Hooks/Hook.cs b/web/tests/EducationBenchmarking.Web.E2ETests/Hooks/Hook.cs index 8ac5aa4f8..7d4479378 100644 --- a/web/tests/EducationBenchmarking.Web.E2ETests/Hooks/Hook.cs +++ b/web/tests/EducationBenchmarking.Web.E2ETests/Hooks/Hook.cs @@ -6,6 +6,7 @@ namespace EducationBenchmarking.Web.E2ETests.Hooks; [Binding] public class Hooks { + private IPlaywright PlaywrightInstance { get; set; } = null!; private readonly IObjectContainer _objectContainer; public Hooks(IObjectContainer objectContainer) @@ -26,10 +27,10 @@ public static void InstallBrowsers() [BeforeScenario] public async Task RegisterInstance() { - var playwrightInstance = await Playwright.CreateAsync(); + PlaywrightInstance = await Playwright.CreateAsync(); var launchOptions = new BrowserTypeLaunchOptions { Headless = false }; - var browser = await playwrightInstance.Chromium.LaunchAsync(launchOptions); + var browser = await PlaywrightInstance.Chromium.LaunchAsync(launchOptions); var contextOptions = new BrowserNewContextOptions { IgnoreHTTPSErrors = true }; var browserContext = await browser.NewContextAsync(contextOptions); @@ -39,4 +40,10 @@ public async Task RegisterInstance() _objectContainer.RegisterInstanceAs(browser); _objectContainer.RegisterInstanceAs(page); } + + [AfterScenario] + public async Task AfterScenario() + { + PlaywrightInstance.Dispose(); + } } \ No newline at end of file diff --git a/web/tests/EducationBenchmarking.Web.E2ETests/Steps/CompareYourCostsSteps.cs b/web/tests/EducationBenchmarking.Web.E2ETests/Steps/CompareYourCostsSteps.cs index b3143fe81..c1556db1e 100644 --- a/web/tests/EducationBenchmarking.Web.E2ETests/Steps/CompareYourCostsSteps.cs +++ b/web/tests/EducationBenchmarking.Web.E2ETests/Steps/CompareYourCostsSteps.cs @@ -1,6 +1,7 @@ using EducationBenchmarking.Web.E2ETests.Pages; using EducationBenchmarking.Web.E2ETests.TestSupport; using Microsoft.Playwright; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.E2ETests.Steps; @@ -9,11 +10,16 @@ public class CompareYourCostsSteps { private readonly IPage _page; private readonly CompareYourCostsPage _compareYourCostsPage; + private readonly ITestOutputHelper _output; - public CompareYourCostsSteps(IPage page, CompareYourCostsPage compareYourCostsPage) + public CompareYourCostsSteps(IPage page, CompareYourCostsPage compareYourCostsPage, ITestOutputHelper output) { _page = page; +#if DEBUG + _page.Response += (sender, r) => output.WriteLine($"{r.Request.Method} {r.Url} [{r.Status}]"); +#endif _compareYourCostsPage = compareYourCostsPage; + _output = output; } [Then(@"I am taken to compare your costs page")] diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/BenchmarkingWebAppClient.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/BenchmarkingWebAppClient.cs index a6e0969ee..6365f4e23 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/BenchmarkingWebAppClient.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/BenchmarkingWebAppClient.cs @@ -3,6 +3,7 @@ using EducationBenchmarking.Web.Infrastructure.Apis; using Moq; using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; @@ -13,7 +14,7 @@ public class BenchmarkingWebAppClient : ClientBase, IClassFixture BenchmarkApi = new(); protected Fixture Fixture { get; private set; } - public BenchmarkingWebAppClient(BenchmarkingWebAppFactory factory) : base(factory) + public BenchmarkingWebAppClient(BenchmarkingWebAppFactory factory, ITestOutputHelper output) : base(factory, output) { Fixture = new Fixture(); } diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/ClientBase.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/ClientBase.cs index 3d3a29036..a8602bf89 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/ClientBase.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/ClientBase.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; @@ -11,8 +12,9 @@ public abstract class ClientBase : IDisposable where TStartup : class { private HttpClient _http; + private readonly ITestOutputHelper _output; - public ClientBase(WebApplicationFactory factory) + public ClientBase(WebApplicationFactory factory, ITestOutputHelper output) { _http = factory.WithWebHostBuilder(builder => { @@ -22,6 +24,8 @@ public ClientBase(WebApplicationFactory factory) BaseAddress = new Uri("https://localhost"), HandleCookies = true }); + + _output = output; } protected abstract void Configure(IServiceCollection services); @@ -33,11 +37,22 @@ public Task Follow(IElement element) throw new ArgumentNullException(nameof(element)); } + async Task GetDocumentAsync(string? href) + { + var response = await _http.GetAsync(href); +#if DEBUG + _output.WriteLine($"↳ {response.RequestMessage?.Method} {response.RequestMessage?.RequestUri} [{(int)response.StatusCode}]"); +#endif + return await response.GetDocumentAsync(); + } + switch (element) { case IHtmlLinkElement link: + _output.WriteLine($"Following "); return _http.GetAsync(link.Href).GetDocumentAsync(); case IHtmlAnchorElement a: + _output.WriteLine($"Following "); return _http.GetAsync(a.Href).GetDocumentAsync(); default: throw new Exception($"Unable to follow a {element.GetType()}"); @@ -47,6 +62,9 @@ public Task Follow(IElement element) public async Task Navigate(string uri, Action? responseValidation = null) { var response = await _http.GetAsync(uri); +#if DEBUG + _output.WriteLine($"{response.RequestMessage?.Method} {response.RequestMessage?.RequestUri} [{(int)response.StatusCode}]"); +#endif responseValidation?.Invoke(response); return await response.GetDocumentAsync(); } diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingErrors.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingErrors.cs index 324b98bb1..d0666fd38 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingErrors.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingErrors.cs @@ -1,10 +1,11 @@ using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; public class WhenViewingErrors : BenchmarkingWebAppClient { - public WhenViewingErrors(BenchmarkingWebAppFactory factory) : base(factory) + public WhenViewingErrors(BenchmarkingWebAppFactory factory, ITestOutputHelper output) : base(factory, output) { } diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchool.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchool.cs index 4c3c0e538..8a36826f0 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchool.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchool.cs @@ -4,12 +4,13 @@ using AutoFixture; using EducationBenchmarking.Web.Domain; using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; public class WhenViewingSchool : BenchmarkingWebAppClient { - public WhenViewingSchool(BenchmarkingWebAppFactory factory) : base(factory) + public WhenViewingSchool(BenchmarkingWebAppFactory factory, ITestOutputHelper output) : base(factory, output) { } diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolComparison.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolComparison.cs index 1f0ecaf59..6867be5a6 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolComparison.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolComparison.cs @@ -4,12 +4,13 @@ using AutoFixture; using EducationBenchmarking.Web.Domain; using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; public class WhenViewingSchoolComparison : BenchmarkingWebAppClient { - public WhenViewingSchoolComparison(BenchmarkingWebAppFactory factory) : base(factory) + public WhenViewingSchoolComparison(BenchmarkingWebAppFactory factory, ITestOutputHelper output) : base(factory, output) { } diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolWorkforce.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolWorkforce.cs index 138f13554..5ab6af45a 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolWorkforce.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingSchoolWorkforce.cs @@ -4,12 +4,13 @@ using AutoFixture; using EducationBenchmarking.Web.Domain; using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; public class WhenViewingSchoolWorkforce : BenchmarkingWebAppClient { - public WhenViewingSchoolWorkforce(BenchmarkingWebAppFactory factory) : base(factory) + public WhenViewingSchoolWorkforce(BenchmarkingWebAppFactory factory, ITestOutputHelper output) : base(factory, output) { } diff --git a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingServiceHome.cs b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingServiceHome.cs index d1f155f1d..70fd7ba50 100644 --- a/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingServiceHome.cs +++ b/web/tests/EducationBenchmarking.Web.Integration.Tests/WhenViewingServiceHome.cs @@ -1,10 +1,11 @@ using Xunit; +using Xunit.Abstractions; namespace EducationBenchmarking.Web.Integration.Tests; public class WhenViewingServiceHome : BenchmarkingWebAppClient { - public WhenViewingServiceHome(BenchmarkingWebAppFactory factory) : base(factory) + public WhenViewingServiceHome(BenchmarkingWebAppFactory factory, ITestOutputHelper output) : base(factory, output) { }