Skip to content

Commit

Permalink
Fix the remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moattarwork committed Feb 13, 2024
1 parent ee1708c commit 6b53b47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using Microsoft.AspNetCore;

namespace LittleBlocks.Testing.Integration;

public class IntegrationTestApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
protected override IHostBuilder CreateHostBuilder()

protected override IWebHostBuilder CreateWebHostBuilder()
{
var builder = Host
.CreateDefaultBuilder()
.ConfigureWebHostDefaults(host =>
var hostBuilder = WebHost.CreateDefaultBuilder()
.ConfigureAppConfiguration((context, builder) =>
{
host.UseStartup<TStartup>().UseTestServer();
});
return builder;
var env = context.HostingEnvironment;
env.EnvironmentName = "Development";

builder.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", false, true);
})
.UseStartup<TStartup>()
.UseTestServer();

return hostBuilder;
}
}
15 changes: 3 additions & 12 deletions src/LittleBlocks.Testing.Integration/IntegrationTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,11 @@ public ClientAppPair<T, TStartup> CreateClientFromServer<T>(Action<IServiceProvi
var client = server.CreateClient<TStartup, T>();
return new ClientAppPair<T, TStartup>(client, server);
}



protected virtual WebApplicationFactory<TStartup> CreateApplicationFactory()
{
return new IntegrationTestApplicationFactory<TStartup>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
env.EnvironmentName = "Development";

config.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", false, true);
});
});
return new IntegrationTestApplicationFactory<TStartup>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task ForPostShouldReturn200Ok(string operation)
new Document()
}
};
using var fixture = TestApplicationFactory<StartupForIntegration>.Create();
await using var fixture = TestApplicationFactory<StartupForIntegration>.Create();

// Act
var response = await fixture.CreateClient().PostAsync("api/Validation", new JsonContent(request));
Expand All @@ -53,7 +53,7 @@ public async Task ForPostShouldReturn200Ok(string operation)
public async Task ForPostShouldReturnErrorWithMissingArguments()
{
// Arrange
using var fixture = TestApplicationFactory<StartupForIntegration>.Create();
await using var fixture = TestApplicationFactory<StartupForIntegration>.Create();

// Act
var response = await fixture.CreateClient().PostAsync("api/Validation",
Expand Down

0 comments on commit 6b53b47

Please sign in to comment.