Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading.Tasks;
using EvoMaster.Controller;
using EvoMaster.Controller.Api;
using EvoMaster.Controller.Problem;
using Npgsql;
using EvoMaster.Controller.Controllers.db;
using EvoMaster.DatabaseController;
using EvoMaster.DatabaseController.Abstractions;
using Testcontainers.PostgreSql;

namespace Menu {
public class EmbeddedEvoMasterController : EmbeddedSutController {
private bool _isSutRunning;
private static int _sutPort;
private NpgsqlConnection _connection;
private IDatabaseController _databaseController;
private DbConnection _connection;
private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder().Build();

private static void Main(string[] args) {
var embeddedEvoMasterController = new EmbeddedEvoMasterController();
Expand Down Expand Up @@ -57,34 +57,35 @@ public override IProblemInfo GetProblemInfo() =>
public override bool IsSutRunning() => _isSutRunning;

public override void ResetStateOfSut() {
DbCleaner.ClearDatabase_Postgres(_connection);
DbCleaner.ClearDatabase(_connection, null, DatabaseType.POSTGRES);
}

public override string StartSut() {

Task.Run(async () => {
// TODO why is this not taken from Docker???
var dbPort = GetEphemeralTcpPort();

await _postgreSqlContainer.StartAsync();

_databaseController = new PostgresDatabaseController("restaurant_menu_database", dbPort, "password123");
await using (DbConnection connection = new NpgsqlConnection(_postgreSqlContainer.GetConnectionString()))
{
_connection = connection;
API.Program.Main(new[] {$"{_sutPort}", connection.ConnectionString});

var (connectionString, dbConnection) = await _databaseController.StartAsync();

_connection = dbConnection as NpgsqlConnection;

API.Program.Main(new[] {$"{_sutPort}", connectionString});
}
});

WaitUntilSutIsRunning(_sutPort);
WaitUntilSutIsRunning(_sutPort, 45);

_isSutRunning = true;

return $"http://localhost:{_sutPort}";
}

public override void StopSut() {
public override async void StopSut() {
API.Program.Shutdown();
_databaseController.Stop();
await _postgreSqlContainer.StopAsync();
_isSutRunning = false;
}

Expand Down
11 changes: 6 additions & 5 deletions dotnet_3/em/embedded/rest/MenuAPIDriver/MenuAPIDriver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
</PropertyGroup>

<Import Project="../../../common.props" />

<ItemGroup>
<PackageReference Include="DotNet.Testcontainers" Version="1.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../../../cs/rest/Menu.API/Menu.API/Menu.API.csproj" />
Expand All @@ -37,6 +33,10 @@
<TempDirectory Include="$(ProjectDir)bin-temp" />
<InstrumentationRuntimeConfig Include="$(OutputPath)EvoMaster.Instrumentation.runtimeconfig.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TestContainers.postgresql" Version="3.1.0" />
</ItemGroup>

<Target Name="Instrument" AfterTargets="Build">

Expand All @@ -48,7 +48,8 @@
<Copy SourceFiles="@(CurrentRuntimeConfig)" DestinationFiles="@(InstrumentationRuntimeConfig)" />

<!-- Run the instrumentation and specify bin-temp as output directory -->
<Exec Command="cd $(OutputPath)&#xD;&#xA; dotnet EvoMaster.Instrumentation.dll @(Sut) @(TempDirectory)" />
<Exec Command="cd $(OutputPath)
dotnet EvoMaster.Instrumentation.dll @(Sut) @(TempDirectory)" />

</Target>

Expand Down