Skip to content

Commit

Permalink
init testing
Browse files Browse the repository at this point in the history
  • Loading branch information
umbertocicciaa committed Oct 20, 2024
1 parent 7610508 commit 843b883
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
28 changes: 28 additions & 0 deletions EsamiOnline.Tests/Services/GreeterServiceTest.cs
Original file line number Diff line number Diff line change
@@ -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<ServerCallContext>();

// Act
var reply = await service.SayHello(request, mockContext.Object);

// Assert
Assert.Equal("Hello Alice", reply.Message);
}
}

6 changes: 6 additions & 0 deletions EsamiOnline.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 8 additions & 0 deletions EsamiOnline/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion EsamiOnline/Services/GreeterService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grpc.Core;
using EsamiOnline;

namespace EsamiOnline.Services;

Expand Down

0 comments on commit 843b883

Please sign in to comment.