Skip to content

Commit

Permalink
added user getall and integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
umbertocicciaa committed Nov 7, 2024
1 parent 67a4aa5 commit 37434de
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
23 changes: 23 additions & 0 deletions ExamFrontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ExamFrontend/ExamFrontend.csproj", "ExamFrontend/"]
RUN dotnet restore "ExamFrontend/ExamFrontend.csproj"
COPY . .
WORKDIR "/src/ExamFrontend"
RUN dotnet build "ExamFrontend.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "ExamFrontend.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ExamFrontend.dll"]
23 changes: 23 additions & 0 deletions UserFrontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["UserFrontend/UserFrontend.csproj", "UserFrontend/"]
RUN dotnet restore "UserFrontend/UserFrontend.csproj"
COPY . .
WORKDIR "/src/UserFrontend"
RUN dotnet build "UserFrontend.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "UserFrontend.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "UserFrontend.dll"]
2 changes: 1 addition & 1 deletion UserService/Protos/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package user;

service User{
rpc SaveUser (UserDto) returns (google.protobuf.Empty);
/*
rpc GetUsers(google.protobuf.Empty) returns (stream UserDto);
/*
rpc GetUserByGovId (UserGovIdRequest) returns (stream UserDto);
rpc GetUserByStudentId (UserStudentIdRequest) returns (stream UserDto);
*/
Expand Down
7 changes: 7 additions & 0 deletions UserService/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ public override Task<Empty> SaveUser(UserDto request, ServerCallContext context)
repository.AddAsync(user);
return Task.FromResult(new Empty());
}

public override async Task GetUsers(Empty request, IServerStreamWriter<UserDto> responseStream, ServerCallContext context)
{
var users = await repository.GetAllAsync();
foreach (var userDto in users.Select(mapper.Map<UserDto>))
await responseStream.WriteAsync(userDto);
}
}
18 changes: 18 additions & 0 deletions UserService/Tests/Integration/UserRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ public async void Should_Add_User()
};

await _repository.AddAsync(user);
}

[Fact]
public async void Should_Get_All_Users()
{
var user = new UserEntity
{
Name = "John Doe",
};
var user2 = new UserEntity
{
Name = "psdsa Doe",
};
await _repository.AddAsync(user);
await _repository.AddAsync(user2);

var users = await _repository.GetAllAsync();

Assert.Equal(2, users.Count);
}
}

0 comments on commit 37434de

Please sign in to comment.