Skip to content
Merged

test #13

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
18 changes: 13 additions & 5 deletions ShowcaseProject/ShowcaseAPI/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Base image for running the .NET API
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# Development stage (voor dotnet watch)
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS dev
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dev
WORKDIR /app
COPY ./ShowcaseAPI ./ShowcaseAPI
WORKDIR /app/ShowcaseAPI
CMD ["dotnet", "watch", "run", "--no-launch-profile", "--urls", "http://+:80"]

# Build stage (voor productie)
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"]
RUN dotnet restore "ShowcaseAPI/ShowcaseAPI.csproj"
Expand All @@ -27,7 +27,15 @@ FROM build AS publish
RUN dotnet publish "ShowcaseAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false

# Final production stage
FROM base AS final
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app

# Kopieer wait script
COPY ShowcaseAPI/wait-for-sql.sh .
RUN chmod +x wait-for-sql.sh

# Kopieer build output
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ShowcaseAPI.dll"]

# Start script dat wacht op SQL Server
ENTRYPOINT ["./wait-for-sql.sh"]
2 changes: 1 addition & 1 deletion ShowcaseProject/ShowcaseAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
.AllowCredentials();
});
});

Env.Load();

// Add services to the container.
Expand Down
13 changes: 6 additions & 7 deletions ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-ShowcaseAPI-700326db-d48c-416d-95f7-7cfed2b3e725</UserSecretsId>
Expand All @@ -11,22 +11,21 @@
<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="JWT" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.1" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.1" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.15" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.6.2" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="3.6.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.6.0" />

</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions ShowcaseProject/ShowcaseAPI/wait-for-sql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
SQLSERVER_HOST=${SQLSERVER_HOST:-sqlserver}
SQLSERVER_PORT=${SQLSERVER_PORT:-1433}

echo "Wachten op SQL Server op $SQLSERVER_HOST:$SQLSERVER_PORT..."

while ! echo > /dev/tcp/$SQLSERVER_HOST/$SQLSERVER_PORT 2>/dev/null; do
echo "SQL Server nog niet bereikbaar..."
sleep 2
done

echo "SQL Server is beschikbaar, start API"
exec dotnet ShowcaseAPI.dll
13 changes: 13 additions & 0 deletions ShowcaseProject/ShowcaseApiTesting/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

COPY ["ShowcaseApiTesting/ShowcaseApiTesting.csproj", "ShowcaseApiTesting/"]
COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"]
RUN dotnet restore "ShowcaseApiTesting/ShowcaseApiTesting.csproj"

COPY . .
WORKDIR "/src/ShowcaseApiTesting"

RUN dotnet build "ShowcaseApiTesting.csproj" -c Release --no-restore

CMD ["dotnet", "test", "ShowcaseApiTesting.csproj", "-c", "Release", "--logger:trx;LogFileName=test_results.trx", "--results-directory", "./TestResults", "--verbosity", "normal"]
4 changes: 1 addition & 3 deletions ShowcaseProject/ShowcaseApiTesting/GameHubTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
namespace ShowcaseApiTesting
{
using Xunit;
using Moq;
using ShowcaseAPI.Hubs;
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using System.Collections.Generic;

[TestFixture]
public class GameHubTests
Expand All @@ -29,7 +27,7 @@ public async Task CreateGroup()
_mockClients.Setup(clients => clients.Caller).Returns(_mockClientProxy.Object);


var groupName = "123456";
var groupName = "123456";
var connectionId = "test-connection";
_mockContext.Setup(c => c.ConnectionId).Returns(connectionId);

Expand Down
10 changes: 10 additions & 0 deletions ShowcaseProject/ShowcaseApiTesting/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"ShowcaseApiTesting": {
"commandName": "Project"
},
"Container (Dockerfile)": {
"commandName": "Docker"
}
}
}
5 changes: 3 additions & 2 deletions ShowcaseProject/ShowcaseApiTesting/ShowcaseApiTesting.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="xunit" Version="2.9.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion ShowcaseProject/ShowcaseFrontend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

builder.Services.AddHttpClient("NoSSL", client =>
{
client.BaseAddress = new Uri("http://showcaseapi");
client.BaseAddress = new Uri("http://showcaseapi" );
})
.ConfigurePrimaryHttpMessageHandler(() =>
{
Expand Down
37 changes: 25 additions & 12 deletions ShowcaseProject/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ services:
volumes:
- sql_data:/var/opt/mssql

showcasefrontend:
build:
context: .
dockerfile: ShowcaseFrontend/Dockerfile
target: dev
container_name: showcasefrontend
ports:
- "8080:80"
depends_on:
- showcaseapi
environment:
- API_BASE_URL=http://showcaseapi
volumes:
- ./ShowcaseFrontend:/app/ShowcaseFrontend
- ~/.nuget/packages:/root/.nuget/packages:ro
command: ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"]

showcaseapi:
build:
context: .
Expand All @@ -23,23 +40,19 @@ services:
- sqlserver
env_file:
- .env
environment:
- SQLSERVER_HOST=sqlserver
- SQLSERVER_PORT=1433

showcasefrontend:
showcaseapitesting:
build:
context: .
dockerfile: ShowcaseFrontend/Dockerfile
target: dev
container_name: showcasefrontend
ports:
- "8080:80"
dockerfile: ShowcaseApiTesting/Dockerfile
container_name: showcaseapitesting
depends_on:
- showcaseapi
environment:
- API_BASE_URL=http://showcaseapi
volumes:
- ./ShowcaseFrontend:/app/ShowcaseFrontend
- ~/.nuget/packages:/root/.nuget/packages:ro
command: ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"]
- ./ShowcaseApiTesting/TestResults:/src/ShowcaseApiTesting/TestResults

volumes:
sql_data:
sql_data: