diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..38bece4
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,25 @@
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/.idea
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
\ No newline at end of file
diff --git a/PaymentsApi.Tests/GlobalUsings.cs b/PaymentsApi.Tests/GlobalUsings.cs
new file mode 100644
index 0000000..8c927eb
--- /dev/null
+++ b/PaymentsApi.Tests/GlobalUsings.cs
@@ -0,0 +1 @@
+global using Xunit;
\ No newline at end of file
diff --git a/PaymentsApi.Tests/PaymentsApi.Tests.csproj b/PaymentsApi.Tests/PaymentsApi.Tests.csproj
new file mode 100644
index 0000000..d5744c4
--- /dev/null
+++ b/PaymentsApi.Tests/PaymentsApi.Tests.csproj
@@ -0,0 +1,30 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
+
+
diff --git a/PaymentsApi.Tests/PaymentsApiShould.cs b/PaymentsApi.Tests/PaymentsApiShould.cs
new file mode 100644
index 0000000..e34de73
--- /dev/null
+++ b/PaymentsApi.Tests/PaymentsApiShould.cs
@@ -0,0 +1,56 @@
+using System.Net.Http.Headers;
+using dotNetTesting.Payments;
+using dotNetTesting.Payments.Model;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.AspNetCore.TestHost;
+using Microsoft.Extensions.Hosting;
+using Newtonsoft.Json;
+using JsonSerializer = System.Text.Json.JsonSerializer;
+
+namespace PaymentsApi.Tests;
+
+public class FakeCreatePaymentUseCase : ICreatePaymentUseCase
+{
+ public Task Invoke(CreatePaymentRequest request)
+ {
+ return new Task(() => new PaymentId("1234"));
+ }
+}
+
+public class PaymentsApiShould
+{
+ private readonly HttpClient _testClient;
+ public PaymentsApiShould()
+ {
+ var builder = WebApplication.CreateBuilder();
+ builder.AddDependencies();
+ builder.Services.Replace(new ServiceDescriptor(typeof(ICreatePaymentUseCase), new FakeCreatePaymentUseCase()));
+ builder.WebHost.UseTestServer();
+ var app = builder.Build();
+ app.UseEndpoints();
+ app.Start();
+ _testClient = app.GetTestClient();
+ _testClient.Timeout = TimeSpan.FromSeconds(10);
+ }
+
+ [Fact]
+ public async void Test1()
+ {
+ var request = new CreatePaymentRequest(
+ new MonetaryAmount(10, Currency.Eur), new EntityId("Halcon"), new EntityId("Hotel")
+ );
+ var jsonRequest = JsonSerializer.Serialize(request);
+ var content = new StringContent(jsonRequest);
+ content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
+ var response = await _testClient.PostAsync("/payments", content);
+ var responseContent = await response.Content.ReadAsStringAsync();
+ var paymentId = JsonConvert.DeserializeObject(responseContent);
+
+
+ //response.EnsureSuccessStatusCode();
+ Assert.Equal(new PaymentId("1234"), paymentId);
+
+ }
+}
\ No newline at end of file
diff --git a/PaymentsApi/DependencyInjection.cs b/PaymentsApi/DependencyInjection.cs
new file mode 100644
index 0000000..3b3f5b2
--- /dev/null
+++ b/PaymentsApi/DependencyInjection.cs
@@ -0,0 +1,21 @@
+using dotNetTesting.Payments;
+using dotNetTesting.Payments.DataAccess;
+using dotNetTesting.Services;
+using Microsoft.EntityFrameworkCore;
+
+namespace PaymentsApi;
+
+public static class DependencyInjection
+{
+ public static void AddDependencies(this WebApplicationBuilder builder)
+ {
+ builder.Services.AddDbContextPool(options =>
+ {
+ options.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres;");
+ });
+ builder.Services.AddScoped();
+ builder.Services.AddScoped();
+ builder.Services.AddScoped();
+ builder.Services.AddScoped();
+ }
+}
\ No newline at end of file
diff --git a/PaymentsApi/Dockerfile b/PaymentsApi/Dockerfile
new file mode 100644
index 0000000..5865eda
--- /dev/null
+++ b/PaymentsApi/Dockerfile
@@ -0,0 +1,20 @@
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
+WORKDIR /app
+EXPOSE 80
+EXPOSE 443
+
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+WORKDIR /src
+COPY ["PaymentsApi/PaymentsApi.csproj", "PaymentsApi/"]
+RUN dotnet restore "PaymentsApi/PaymentsApi.csproj"
+COPY . .
+WORKDIR "/src/PaymentsApi"
+RUN dotnet build "PaymentsApi.csproj" -c Release -o /app/build
+
+FROM build AS publish
+RUN dotnet publish "PaymentsApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
+
+FROM base AS final
+WORKDIR /app
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "PaymentsApi.dll"]
diff --git a/PaymentsApi/Endpoints.cs b/PaymentsApi/Endpoints.cs
new file mode 100644
index 0000000..9a6b57e
--- /dev/null
+++ b/PaymentsApi/Endpoints.cs
@@ -0,0 +1,17 @@
+using dotNetTesting.Payments;
+
+namespace PaymentsApi;
+
+public static class Endpoints
+{
+ public static void UseEndpoints(this WebApplication webApplication)
+ {
+ webApplication.MapPost("/payments", async (CreatePaymentRequest request, ICreatePaymentUseCase useCase) =>
+ {
+ var res = await useCase.Invoke(request);
+ return Results.Created($"/payments/{res.Value}", res.Value);
+ });
+
+ webApplication.MapGet("/", () => Results.Ok("Hello world"));
+ }
+}
\ No newline at end of file
diff --git a/PaymentsApi/PaymentsApi.csproj b/PaymentsApi/PaymentsApi.csproj
new file mode 100644
index 0000000..156bfc4
--- /dev/null
+++ b/PaymentsApi/PaymentsApi.csproj
@@ -0,0 +1,25 @@
+
+
+
+ net8.0
+ enable
+ enable
+ Linux
+
+
+
+
+
+
+
+
+
+ .dockerignore
+
+
+
+
+
+
+
+
diff --git a/PaymentsApi/PaymentsApi.http b/PaymentsApi/PaymentsApi.http
new file mode 100644
index 0000000..a2c5c2b
--- /dev/null
+++ b/PaymentsApi/PaymentsApi.http
@@ -0,0 +1,6 @@
+@PaymentsApi_HostAddress = http://localhost:5183
+
+POST {{PaymentsApi_HostAddress}}/payments/
+Accept: application/json
+
+###
diff --git a/PaymentsApi/Program.cs b/PaymentsApi/Program.cs
new file mode 100644
index 0000000..3b043d8
--- /dev/null
+++ b/PaymentsApi/Program.cs
@@ -0,0 +1,17 @@
+using PaymentsApi;
+
+var builder = WebApplication.CreateBuilder(args);
+
+// Add services to the container.
+// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
+builder.Services.AddEndpointsApiExplorer();
+
+
+builder.AddDependencies();
+var app = builder.Build();
+app.UseHttpsRedirection();
+
+app.UseEndpoints();
+
+
+app.Run();
\ No newline at end of file
diff --git a/PaymentsApi/Properties/launchSettings.json b/PaymentsApi/Properties/launchSettings.json
new file mode 100644
index 0000000..bd32e53
--- /dev/null
+++ b/PaymentsApi/Properties/launchSettings.json
@@ -0,0 +1,41 @@
+{
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:46945",
+ "sslPort": 44388
+ }
+ },
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "http://localhost:5183",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "https://localhost:7019;http://localhost:5183",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/PaymentsApi/appsettings.Development.json b/PaymentsApi/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/PaymentsApi/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/PaymentsApi/appsettings.json b/PaymentsApi/appsettings.json
new file mode 100644
index 0000000..10f68b8
--- /dev/null
+++ b/PaymentsApi/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/dotNetTesting.Tests/dotNetTesting.Tests.csproj b/dotNetTesting.Tests/dotNetTesting.Tests.csproj
index cb9473f..e16b74c 100644
--- a/dotNetTesting.Tests/dotNetTesting.Tests.csproj
+++ b/dotNetTesting.Tests/dotNetTesting.Tests.csproj
@@ -1,9 +1,10 @@
- net7.0
false
+
+ net8.0
diff --git a/dotNetTesting.sln b/dotNetTesting.sln
index b2f4846..418216f 100644
--- a/dotNetTesting.sln
+++ b/dotNetTesting.sln
@@ -4,6 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotNetTesting", "dotNetTest
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotNetTesting.Tests", "dotNetTesting.Tests\dotNetTesting.Tests.csproj", "{A36D0609-9572-44AF-95AD-01FECE04C0C8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaymentsApi", "PaymentsApi\PaymentsApi.csproj", "{4575AA41-DAE8-47F0-B90A-A6FDA0103DBB}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaymentsApi.Tests", "PaymentsApi.Tests\PaymentsApi.Tests.csproj", "{746D49C0-1EF3-4EB1-A8B8-B59F8439E2AE}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -18,5 +22,13 @@ Global
{A36D0609-9572-44AF-95AD-01FECE04C0C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A36D0609-9572-44AF-95AD-01FECE04C0C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A36D0609-9572-44AF-95AD-01FECE04C0C8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4575AA41-DAE8-47F0-B90A-A6FDA0103DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4575AA41-DAE8-47F0-B90A-A6FDA0103DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4575AA41-DAE8-47F0-B90A-A6FDA0103DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4575AA41-DAE8-47F0-B90A-A6FDA0103DBB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {746D49C0-1EF3-4EB1-A8B8-B59F8439E2AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {746D49C0-1EF3-4EB1-A8B8-B59F8439E2AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {746D49C0-1EF3-4EB1-A8B8-B59F8439E2AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {746D49C0-1EF3-4EB1-A8B8-B59F8439E2AE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
diff --git a/dotNetTesting.sln.DotSettings.user b/dotNetTesting.sln.DotSettings.user
index 688b81f..5338e5e 100644
--- a/dotNetTesting.sln.DotSettings.user
+++ b/dotNetTesting.sln.DotSettings.user
@@ -2,8 +2,9 @@
A36D0609-9572-44AF-95AD-01FECE04C0C8
d6790ab7-33c2-4425-b2c9-51480cd1a852
33ff99d8-b1ad-4ed5-a4fd-376b97c2c841
- <SessionState ContinuousTestingMode="0" IsActive="True" Name="CreatePaymentUseCaseTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
- <TestAncestor>
- <TestId>xUnit::A36D0609-9572-44AF-95AD-01FECE04C0C8::net7.0::dotNetTesting.Tests.Payments.DataAccess.EntitiesRepositoryTest</TestId>
- </TestAncestor>
-</SessionState>
\ No newline at end of file
+ <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from PaymentsApiShould.cs" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
+ <ProjectFile>746D49C0-1EF3-4EB1-A8B8-B59F8439E2AE/f:PaymentsApiShould.cs</ProjectFile>
+</SessionState>
+
+
+
\ No newline at end of file
diff --git a/dotNetTesting/Payments/Domain/CreatePaymentUseCase.cs b/dotNetTesting/Payments/Domain/CreatePaymentUseCase.cs
index 9da7dc6..6d15366 100644
--- a/dotNetTesting/Payments/Domain/CreatePaymentUseCase.cs
+++ b/dotNetTesting/Payments/Domain/CreatePaymentUseCase.cs
@@ -3,7 +3,9 @@
namespace dotNetTesting.Payments;
-public class CreatePaymentUseCase
+
+
+public class CreatePaymentUseCase : ICreatePaymentUseCase
{
private readonly IGuidGenerator _guidGenerator;
private readonly IPaymentsRepository _paymentsRepository;
@@ -37,6 +39,8 @@ public async Task Invoke(CreatePaymentRequest request)
}
}
+
+
public record CreatePaymentRequest(MonetaryAmount Amount, EntityId Payer, EntityId Payee);
public class PayerDoesNotExist : Exception
diff --git a/dotNetTesting/Payments/Domain/ICreatePaymentUseCase.cs b/dotNetTesting/Payments/Domain/ICreatePaymentUseCase.cs
new file mode 100644
index 0000000..c49dc2c
--- /dev/null
+++ b/dotNetTesting/Payments/Domain/ICreatePaymentUseCase.cs
@@ -0,0 +1,8 @@
+using dotNetTesting.Payments.Model;
+
+namespace dotNetTesting.Payments;
+
+public interface ICreatePaymentUseCase
+{
+ public Task Invoke(CreatePaymentRequest request);
+}
\ No newline at end of file
diff --git a/dotNetTesting/dotNetTesting.csproj b/dotNetTesting/dotNetTesting.csproj
index a247a7a..9ca29e0 100644
--- a/dotNetTesting/dotNetTesting.csproj
+++ b/dotNetTesting/dotNetTesting.csproj
@@ -1,7 +1,7 @@
- net7.0
+ net8.0
enable
enable
diff --git a/global.json b/global.json
new file mode 100644
index 0000000..b5b37b6
--- /dev/null
+++ b/global.json
@@ -0,0 +1,7 @@
+{
+ "sdk": {
+ "version": "8.0.0",
+ "rollForward": "latestMajor",
+ "allowPrerelease": false
+ }
+}
\ No newline at end of file