From 843b8834cb04bc96feecd6c7004831bdd6c2e49a Mon Sep 17 00:00:00 2001 From: Umberto Domenico Ciccia <108148943+umbertocicciaa@users.noreply.github.com> Date: Sun, 20 Oct 2024 16:26:42 +0200 Subject: [PATCH] init testing --- .../Services/GreeterServiceTest.cs | 28 +++++++++++++++++++ EsamiOnline.sln | 6 ++++ EsamiOnline/Dockerfile | 8 ++++++ EsamiOnline/Services/GreeterService.cs | 1 - 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 EsamiOnline.Tests/Services/GreeterServiceTest.cs diff --git a/EsamiOnline.Tests/Services/GreeterServiceTest.cs b/EsamiOnline.Tests/Services/GreeterServiceTest.cs new file mode 100644 index 0000000..930d622 --- /dev/null +++ b/EsamiOnline.Tests/Services/GreeterServiceTest.cs @@ -0,0 +1,28 @@ +using System.Threading.Tasks; +using EsamiOnline.Services; +using Grpc.Core; +using JetBrains.Annotations; +using Moq; +using Xunit; + +namespace EsamiOnline.Tests.Services; + +[TestSubject(typeof(GreeterService))] +public class GreeterServiceTest +{ + [Fact] + public async Task SayHelloTest() + { + // Arrange + var service = new GreeterService(); + var request = new HelloRequest { Name = "Alice" }; + var mockContext = new Mock(); + + // Act + var reply = await service.SayHello(request, mockContext.Object); + + // Assert + Assert.Equal("Hello Alice", reply.Message); + } +} + diff --git a/EsamiOnline.sln b/EsamiOnline.sln index 10b1ce8..9567d2e 100644 --- a/EsamiOnline.sln +++ b/EsamiOnline.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EsamiOnline", "EsamiOnline\EsamiOnline.csproj", "{FEFDA62C-5DD0-4E0B-9DAC-5513FF160772}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EsamiOnline.Tests", "EsamiOnline.Tests\EsamiOnline.Tests.csproj", "{146754BC-7B71-4388-9CF7-7D2E6D204174}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {FEFDA62C-5DD0-4E0B-9DAC-5513FF160772}.Debug|Any CPU.Build.0 = Debug|Any CPU {FEFDA62C-5DD0-4E0B-9DAC-5513FF160772}.Release|Any CPU.ActiveCfg = Release|Any CPU {FEFDA62C-5DD0-4E0B-9DAC-5513FF160772}.Release|Any CPU.Build.0 = Release|Any CPU + {146754BC-7B71-4388-9CF7-7D2E6D204174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {146754BC-7B71-4388-9CF7-7D2E6D204174}.Debug|Any CPU.Build.0 = Debug|Any CPU + {146754BC-7B71-4388-9CF7-7D2E6D204174}.Release|Any CPU.ActiveCfg = Release|Any CPU + {146754BC-7B71-4388-9CF7-7D2E6D204174}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/EsamiOnline/Dockerfile b/EsamiOnline/Dockerfile index c24ba51..f0f1875 100644 --- a/EsamiOnline/Dockerfile +++ b/EsamiOnline/Dockerfile @@ -13,6 +13,14 @@ COPY . . WORKDIR "/src/EsamiOnline" RUN dotnet build "EsamiOnline.csproj" -c $BUILD_CONFIGURATION -o /app/build +FROM build AS test +WORKDIR /src +COPY ["EsamiOnline.Tests/EsamiOnline.Tests.csproj", "EsamiOnline.Tests/"] +RUN dotnet restore "EsamiOnline.Tests/EsamiOnline.Tests.csproj" +COPY . . +WORKDIR "/src/EsamiOnline.Tests" +RUN dotnet test "EsamiOnline.Tests.csproj" --logger:trx + FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "EsamiOnline.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false diff --git a/EsamiOnline/Services/GreeterService.cs b/EsamiOnline/Services/GreeterService.cs index 4d44878..a49c5b6 100644 --- a/EsamiOnline/Services/GreeterService.cs +++ b/EsamiOnline/Services/GreeterService.cs @@ -1,5 +1,4 @@ using Grpc.Core; -using EsamiOnline; namespace EsamiOnline.Services;