diff --git a/Directory.Packages.props b/Directory.Packages.props index b06fb34f..8ae5f089 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,6 +6,7 @@ + @@ -32,6 +33,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + - + \ No newline at end of file diff --git a/sample/CustomerApi.Tests/CustomerApi.Tests.csproj b/sample/CustomerApi.Tests/CustomerApi.Tests.csproj index 9acc26fb..d53cb390 100644 --- a/sample/CustomerApi.Tests/CustomerApi.Tests.csproj +++ b/sample/CustomerApi.Tests/CustomerApi.Tests.csproj @@ -14,6 +14,7 @@ + diff --git a/sample/CustomerApi.Tests/CustomerController/CreateCustomerTests.cs b/sample/CustomerApi.Tests/CustomerController/CreateCustomerTests.cs index dcb3486b..abb138c2 100644 --- a/sample/CustomerApi.Tests/CustomerController/CreateCustomerTests.cs +++ b/sample/CustomerApi.Tests/CustomerController/CreateCustomerTests.cs @@ -4,17 +4,25 @@ using CustomerApi.Uris; using FluentAssertions; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.CustomerController; public class CreateCustomerTests { + private readonly ITestOutputHelper _testOutputHelper; + + public CreateCustomerTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Theory] [InlineData(true)] [InlineData(false)] public async Task Valid_ReturnsOk(bool disableAutoProvisioning) { - using var customerApi = new TestCustomerApi(disableAutoProvisioning); + using var customerApi = new TestCustomerApi(_testOutputHelper, disableAutoProvisioning); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Create"); var client = customerApi.CreateClient(authHeader); @@ -30,7 +38,7 @@ public async Task Valid_ReturnsOk(bool disableAutoProvisioning) [InlineData(false)] public async Task Valid_StoredCorrectly(bool disableAutoProvisioning) { - using var customerApi = new TestCustomerApi(disableAutoProvisioning); + using var customerApi = new TestCustomerApi(_testOutputHelper, disableAutoProvisioning); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Create"); var client = customerApi.CreateClient(authHeader); @@ -51,7 +59,7 @@ await customerApi.Then.TheCustomerShouldMatch( [Fact] public async Task Invalid_DuplicateEmailAddress() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var customerUri = CustomerUri.Parse("/customers/CustomerId"); await customerApi.Given.AnExistingCustomer(customerUri, emailAddress: "bob@bobertson.co.uk"); @@ -69,7 +77,7 @@ public async Task Invalid_DuplicateEmailAddress() [Fact] public async Task Valid_DeleteCustomer_DuplicateEmailAddress() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var customerUri = CustomerUri.Parse("/customers/CustomerId"); await customerApi.Given.AnExistingCustomer(customerUri, emailAddress: "bob@bobertson.co.uk"); @@ -96,7 +104,7 @@ public async Task Valid_DeleteCustomer_DuplicateEmailAddress() [InlineData("not-an-email-address", "Bob", "Bobertson")] public async Task Invalid_ReturnsBadRequest(string email, string firstName, string lastName) { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Create"); var client = customerApi.CreateClient(authHeader); @@ -110,7 +118,7 @@ public async Task Invalid_ReturnsBadRequest(string email, string firstName, stri [Fact] public async Task Unauthorized() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var client = customerApi.CreateClient(); var request = new CreateCustomerRequest("bob@bobertson.co.uk", "Bob", "Bobertson"); @@ -123,7 +131,7 @@ public async Task Unauthorized() [Fact] public async Task Forbidden() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.InvalidRole"); var client = customerApi.CreateClient(authHeader); diff --git a/sample/CustomerApi.Tests/CustomerController/DeleteCustomerTests.cs b/sample/CustomerApi.Tests/CustomerController/DeleteCustomerTests.cs index b26c59c8..2ba96873 100644 --- a/sample/CustomerApi.Tests/CustomerController/DeleteCustomerTests.cs +++ b/sample/CustomerApi.Tests/CustomerController/DeleteCustomerTests.cs @@ -2,15 +2,23 @@ using CustomerApi.Uris; using FluentAssertions; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.CustomerController; public class DeleteCustomerTests { + private readonly ITestOutputHelper _testOutputHelper; + + public DeleteCustomerTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Fact] public async Task NoExisting_ReturnsNotFound() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Delete"); var client = customerApi.CreateClient(authHeader); @@ -24,7 +32,7 @@ public async Task Existing_ReturnsNoContent() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Delete"); await customerApi.Given.AnExistingCustomer(customerUri); var client = customerApi.CreateClient(authHeader); @@ -39,7 +47,7 @@ public async Task ExistingDeleted_ReturnsNoContent() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Delete"); await customerApi.Given.AnExistingCustomer(customerUri); await customerApi.Given.TheCustomerIsDeleted(customerUri); @@ -55,7 +63,7 @@ public async Task Existing_HasBeenRemoved() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Delete"); await customerApi.Given.AnExistingCustomer(customerUri); var client = customerApi.CreateClient(authHeader); @@ -70,7 +78,7 @@ public async Task ExistingDeleted_HasBeenRemoved() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Delete"); await customerApi.Given.AnExistingCustomer(customerUri); await customerApi.Given.TheCustomerIsDeleted(customerUri); @@ -84,7 +92,7 @@ public async Task ExistingDeleted_HasBeenRemoved() [Fact] public async Task Unauthorized() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var client = customerApi.CreateClient(); var response = await client.DeleteAsync("/customers/CustomerId"); @@ -95,7 +103,7 @@ public async Task Unauthorized() [Fact] public async Task Forbidden() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.InvalidRole"); var client = customerApi.CreateClient(authHeader); diff --git a/sample/CustomerApi.Tests/CustomerController/GetAllCustomersTests.cs b/sample/CustomerApi.Tests/CustomerController/GetAllCustomersTests.cs index c4a0c010..f2d17ca2 100644 --- a/sample/CustomerApi.Tests/CustomerController/GetAllCustomersTests.cs +++ b/sample/CustomerApi.Tests/CustomerController/GetAllCustomersTests.cs @@ -5,15 +5,23 @@ using FluentAssertions; using LogOtter.JsonHal; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.CustomerController; public class GetAllCustomersTests { + private readonly ITestOutputHelper _testOutputHelper; + + public GetAllCustomersTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Fact] public async Task Valid_ReturnsOk() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/ExistingUser"), "bob@bobertson.co.uk", "Bob", "Bobertson"); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/AnotherExistingUser"), "bobetta@bobson.co.uk", "Bobetta", "Bobson"); @@ -59,7 +67,7 @@ public async Task Valid_ReturnsOk() [Fact] public async Task Valid_MultiplePages_Page1() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); for (var i = 0; i < 10; i++) { await customerApi.Given.AnExistingCustomer(CustomerUri.Parse($"/customers/ExistingUser{i}")); @@ -92,7 +100,7 @@ public async Task Valid_MultiplePages_Page1() [Fact] public async Task Valid_MultiplePages_Page2() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); for (var i = 0; i < 20; i++) { await customerApi.Given.AnExistingCustomer(CustomerUri.Parse($"/customers/ExistingUser{i}")); @@ -126,7 +134,7 @@ public async Task Valid_MultiplePages_Page2() [Fact] public async Task Valid_NoCustomers_ReturnsOk() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Read"); @@ -152,7 +160,7 @@ public async Task Valid_NoCustomers_ReturnsOk() [InlineData("foo")] public async Task Invalid_Page(string page) { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Read"); @@ -166,7 +174,7 @@ public async Task Invalid_Page(string page) [Fact] public async Task Unauthorized() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/ExistingUser")); var client = customerApi.CreateClient(); @@ -179,7 +187,7 @@ public async Task Unauthorized() [Fact] public async Task Forbidden() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/ExistingUser")); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.InvalidRole"); diff --git a/sample/CustomerApi.Tests/CustomerController/GetCustomerByIdTests.cs b/sample/CustomerApi.Tests/CustomerController/GetCustomerByIdTests.cs index 42932373..9388b894 100644 --- a/sample/CustomerApi.Tests/CustomerController/GetCustomerByIdTests.cs +++ b/sample/CustomerApi.Tests/CustomerController/GetCustomerByIdTests.cs @@ -4,15 +4,23 @@ using CustomerApi.Uris; using FluentAssertions; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.CustomerController; public class GetCustomerByIdTests { + private readonly ITestOutputHelper _testOutputHelper; + + public GetCustomerByIdTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Fact] public async Task Valid_ReturnsOk() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/ExistingUser"), "bob@bobertson.co.uk", "Bob", "Bobertson"); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Read"); @@ -36,7 +44,7 @@ public async Task Valid_ReturnsOk() [Fact] public async Task NotFound() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.Read"); @@ -50,7 +58,7 @@ public async Task NotFound() [Fact] public async Task Unauthorized() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/ExistingUser")); var client = customerApi.CreateClient(); @@ -63,7 +71,7 @@ public async Task Unauthorized() [Fact] public async Task Forbidden() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(CustomerUri.Parse("/customers/ExistingUser")); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.InvalidRole"); diff --git a/sample/CustomerApi.Tests/CustomerController/PatchCustomerTests.cs b/sample/CustomerApi.Tests/CustomerController/PatchCustomerTests.cs index cb5579bc..cfffd544 100644 --- a/sample/CustomerApi.Tests/CustomerController/PatchCustomerTests.cs +++ b/sample/CustomerApi.Tests/CustomerController/PatchCustomerTests.cs @@ -6,17 +6,25 @@ using FluentAssertions; using LogOtter.HttpPatch; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.CustomerController; public class PatchCustomerTests { + private readonly ITestOutputHelper _testOutputHelper; + + public PatchCustomerTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Fact] public async Task Valid_ReturnsOk() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.ReadWrite"); await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); @@ -32,7 +40,7 @@ public async Task Valid_ModifiedCorrectly() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.ReadWrite"); var existingCustomer = await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); @@ -55,7 +63,7 @@ public async Task Valid_ReuseEmailAddress() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.ReadWrite", "Customers.Create"); await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk"); @@ -90,7 +98,7 @@ OptionallyPatched lastName { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.ReadWrite"); await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); var client = customerApi.CreateClient(authHeader); @@ -121,7 +129,7 @@ public async Task SameValues_ReturnsOk() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.ReadWrite"); var existingCustomer = await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); var previousRevision = existingCustomer.Revision; @@ -147,7 +155,7 @@ public async Task NoChange_ReturnsOk() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.ReadWrite"); await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); @@ -167,7 +175,7 @@ public async Task Unauthorized() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); var client = customerApi.CreateClient(); @@ -182,7 +190,7 @@ public async Task Forbidden() { var customerUri = CustomerUri.Parse("/customers/CustomerId"); - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("Customers.InvalidRole"); await customerApi.Given.AnExistingCustomer(customerUri, "bob@bobertson.co.uk", "Bob", "Bobertson"); diff --git a/sample/CustomerApi.Tests/CustomerInterestsController/CreateCustomerInterestTests.cs b/sample/CustomerApi.Tests/CustomerInterestsController/CreateCustomerInterestTests.cs index 401fa392..4b44835c 100644 --- a/sample/CustomerApi.Tests/CustomerInterestsController/CreateCustomerInterestTests.cs +++ b/sample/CustomerApi.Tests/CustomerInterestsController/CreateCustomerInterestTests.cs @@ -4,17 +4,25 @@ using CustomerApi.Uris; using FluentAssertions; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.CustomerInterestsController; public class CreateCustomerInterestTests { + private readonly ITestOutputHelper _testOutputHelper; + + public CreateCustomerInterestTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Theory] [InlineData(true)] [InlineData(false)] public async Task ValidMovie_ReturnsOk(bool disableAutoProvisioning) { - using var customerApi = new TestCustomerApi(disableAutoProvisioning); + using var customerApi = new TestCustomerApi(_testOutputHelper, disableAutoProvisioning); var authHeader = await customerApi.Given.AnExistingConsumer("CustomerInterests.Create"); var client = customerApi.CreateClient(authHeader); @@ -30,7 +38,7 @@ public async Task ValidMovie_ReturnsOk(bool disableAutoProvisioning) [InlineData(false)] public async Task ValidMovie_StoredCorrectly(bool disableAutoProvisioning) { - using var customerApi = new TestCustomerApi(disableAutoProvisioning); + using var customerApi = new TestCustomerApi(_testOutputHelper, disableAutoProvisioning); var authHeader = await customerApi.Given.AnExistingConsumer("CustomerInterests.Create"); var client = customerApi.CreateClient(authHeader); @@ -48,7 +56,7 @@ public async Task ValidMovie_StoredCorrectly(bool disableAutoProvisioning) [Fact] public async Task ValidMovie_ProcessedToSearchableInterest() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("CustomerInterests.Create"); var client = customerApi.CreateClient(authHeader); @@ -66,7 +74,7 @@ public async Task ValidMovie_ProcessedToSearchableInterest() [Fact] public async Task ValidSong_ReturnsOk() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("CustomerInterests.Create"); var client = customerApi.CreateClient(authHeader); @@ -80,7 +88,7 @@ public async Task ValidSong_ReturnsOk() [Fact] public async Task ValidSong_StoredCorrectly() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("CustomerInterests.Create"); var client = customerApi.CreateClient(authHeader); @@ -98,7 +106,7 @@ public async Task ValidSong_StoredCorrectly() [Fact] public async Task ValidSong_ProcessedToSearchableInterest() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var authHeader = await customerApi.Given.AnExistingConsumer("CustomerInterests.Create"); var client = customerApi.CreateClient(authHeader); diff --git a/sample/CustomerApi.Tests/EventStoreApi/RetrieveEventsFromEventStream.cs b/sample/CustomerApi.Tests/EventStoreApi/RetrieveEventsFromEventStream.cs index cc1b9da9..e1ee105a 100644 --- a/sample/CustomerApi.Tests/EventStoreApi/RetrieveEventsFromEventStream.cs +++ b/sample/CustomerApi.Tests/EventStoreApi/RetrieveEventsFromEventStream.cs @@ -4,15 +4,23 @@ using FluentAssertions; using LogOtter.CosmosDb.EventStore.EventStreamApi.Responses; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.EventStoreApi; public class RetrieveEventsFromEventStream { + private readonly ITestOutputHelper _testOutputHelper; + + public RetrieveEventsFromEventStream(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Fact] public async Task CanRetrieveEventStream() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var customerUri = CustomerUri.Generate(); await customerApi.Given.AnExistingCustomer(customerUri, emailAddress: "bob@bobertson.co.uk"); diff --git a/sample/CustomerApi.Tests/MovieController/MovieTests.cs b/sample/CustomerApi.Tests/MovieController/MovieTests.cs index 7ed5d50e..2c56a0b7 100644 --- a/sample/CustomerApi.Tests/MovieController/MovieTests.cs +++ b/sample/CustomerApi.Tests/MovieController/MovieTests.cs @@ -4,15 +4,23 @@ using CustomerApi.Uris; using FluentAssertions; using Xunit; +using Xunit.Abstractions; namespace CustomerApi.Tests.MovieController; public class MovieTests { + private readonly ITestOutputHelper _testOutputHelper; + + public MovieTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + [Fact] public async Task Valid_ReturnsOkWhenUsingEventStream() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var movieUri = MovieUri.Parse("/movies/ExistingMovie"); await customerApi.Given.AnExistingMovie(movieUri, "The Matrix"); @@ -30,7 +38,7 @@ public async Task Valid_ReturnsOkWhenUsingEventStream() [Fact] public async Task Valid_ReturnsNotFoundWhenUsingSnapshotThatIsNotEnabled() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var movieUri = MovieUri.Parse("/movies/ExistingMovie"); await customerApi.Given.AnExistingMovie(movieUri, "The Matrix"); @@ -44,7 +52,7 @@ public async Task Valid_ReturnsNotFoundWhenUsingSnapshotThatIsNotEnabled() [Fact] public async Task Valid_ReturnsOkWhenUsingHybridAndSnapshotIsNotEnabled() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var movieUri = MovieUri.Parse("/movies/ExistingMovie"); await customerApi.Given.AnExistingMovie(movieUri, "The Matrix"); @@ -62,7 +70,7 @@ public async Task Valid_ReturnsOkWhenUsingHybridAndSnapshotIsNotEnabled() [Fact] public async Task Valid_SavesSnapshotWhenUsingHybridRepoToApply() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var client = customerApi.CreateClient(); var response = await client.PostAsJsonAsync("/movies/create-hybrid", new { name = "Hot Fuzz" }); @@ -80,7 +88,7 @@ public async Task Valid_SavesSnapshotWhenUsingHybridRepoToApply() [Fact] public async Task Valid_ReturnsOkWhenUsingHybridToQueryLatestChanges() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var movieUri = MovieUri.Parse("/movies/ExistingMovie"); await customerApi.Given.AnExistingMovieWithAProjectedSnapshot(movieUri, "The Matrix"); await customerApi.Given.AnExistingMovieNameIsChangedButNotProjected(movieUri, "The Matrix Reloaded"); @@ -99,7 +107,7 @@ public async Task Valid_ReturnsOkWhenUsingHybridToQueryLatestChanges() [Fact] public async Task Valid_ReturnsStreamChanges() { - using var customerApi = new TestCustomerApi(); + using var customerApi = new TestCustomerApi(_testOutputHelper); var movieUri = MovieUri.Parse("/movies/ExistingMovie"); await customerApi.Given.AnExistingMovie(movieUri, "The Matrix"); await customerApi.Given.AnExistingMovieNameIsChangedButNotProjected(movieUri, "The Matrix Reloaded"); diff --git a/sample/CustomerApi.Tests/TestApi/TestCustomerApi.cs b/sample/CustomerApi.Tests/TestApi/TestCustomerApi.cs index 648a514b..42b69f3f 100644 --- a/sample/CustomerApi.Tests/TestApi/TestCustomerApi.cs +++ b/sample/CustomerApi.Tests/TestApi/TestCustomerApi.cs @@ -8,6 +8,7 @@ using LogOtter.CosmosDb; using LogOtter.CosmosDb.EventStore; using LogOtter.CosmosDb.Testing; +using Meziantou.Extensions.Logging.Xunit; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; @@ -17,13 +18,14 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; +using Xunit.Abstractions; namespace CustomerApi.Tests; public class TestCustomerApi : IDisposable { private readonly TestApplicationFactory _hostedApi; - + private readonly ITestOutputHelper _testOutputHelper; private readonly bool _disableCosmosAutoProvisioning; public Uri BaseAddress => _hostedApi.Server.BaseAddress; @@ -31,13 +33,14 @@ public class TestCustomerApi : IDisposable public GivenSteps Given { get; } public ThenSteps Then { get; } - public TestCustomerApi() - : this(false) { } + public TestCustomerApi(ITestOutputHelper testOutputHelper) + : this(testOutputHelper, false) { } - public TestCustomerApi(bool disableCosmosAutoProvisioning) + public TestCustomerApi(ITestOutputHelper testOutputHelper, bool disableCosmosAutoProvisioning) { + _testOutputHelper = testOutputHelper; _disableCosmosAutoProvisioning = disableCosmosAutoProvisioning; - _hostedApi = new TestApplicationFactory(ConfigureTestServices, ConfigureServices); + _hostedApi = new TestApplicationFactory(_testOutputHelper, ConfigureTestServices, ConfigureServices); Given = _hostedApi.Services.GetRequiredService(); Then = _hostedApi.Services.GetRequiredService(); @@ -110,11 +113,17 @@ public HttpClient CreateClient(AuthenticationHeaderValue? authenticationHeaderVa private class TestApplicationFactory : WebApplicationFactory { + private readonly ITestOutputHelper _testOutputHelper; private readonly Action _configureServices; private readonly Action _configureTestServices; - public TestApplicationFactory(Action configureTestServices, Action configureServices) + public TestApplicationFactory( + ITestOutputHelper testOutputHelper, + Action configureTestServices, + Action configureServices + ) { + _testOutputHelper = testOutputHelper; _configureTestServices = configureTestServices; _configureServices = configureServices; } @@ -128,6 +137,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) { options.AddFilter(logLevel => logLevel >= LogLevel.Warning); options.AddFilter("Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware", logLevel => logLevel >= LogLevel.Error); + options.Services.AddSingleton(_ => new XUnitLoggerProvider(_testOutputHelper)); }); } }