Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize HelloWorldMongoDb project with Docker support and tests #12

Merged
merged 2 commits into from
Aug 3, 2024
Merged
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
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*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
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
39 changes: 39 additions & 0 deletions HelloWorldMongoDb.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35125.118
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldMongoDb", "Src\HelloWorldMongoDb\HelloWorldMongoDb.csproj", "{4DC7A2B1-5EE5-4CB5-A506-9CB03C6CDF55}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{7ACF3968-951C-4742-B76F-CDF3A1862A6B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{6A8AA32E-AA77-430D-9853-F6B689BA6F06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldMongoDb.Tests", "Tests\HelloWorldMongoDb.Tests\HelloWorldMongoDb.Tests.csproj", "{C6B2C984-D975-4C2B-866C-D28417334DDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4DC7A2B1-5EE5-4CB5-A506-9CB03C6CDF55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4DC7A2B1-5EE5-4CB5-A506-9CB03C6CDF55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DC7A2B1-5EE5-4CB5-A506-9CB03C6CDF55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DC7A2B1-5EE5-4CB5-A506-9CB03C6CDF55}.Release|Any CPU.Build.0 = Release|Any CPU
{C6B2C984-D975-4C2B-866C-D28417334DDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6B2C984-D975-4C2B-866C-D28417334DDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6B2C984-D975-4C2B-866C-D28417334DDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6B2C984-D975-4C2B-866C-D28417334DDA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4DC7A2B1-5EE5-4CB5-A506-9CB03C6CDF55} = {7ACF3968-951C-4742-B76F-CDF3A1862A6B}
{C6B2C984-D975-4C2B-866C-D28417334DDA} = {6A8AA32E-AA77-430D-9853-F6B689BA6F06}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0907E77B-B32E-40CA-9517-102D3F055C62}
EndGlobalSection
EndGlobal
28 changes: 28 additions & 0 deletions Src/HelloWorldMongoDb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER app
WORKDIR /app


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["HelloWorldMongoDb/HelloWorldMongoDb.csproj", "HelloWorldMongoDb/"]
RUN dotnet restore "./HelloWorldMongoDb/HelloWorldMongoDb.csproj"
COPY . .
WORKDIR "/src/HelloWorldMongoDb"
RUN dotnet build "./HelloWorldMongoDb.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./HelloWorldMongoDb.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HelloWorldMongoDb.dll"]
16 changes: 16 additions & 0 deletions Src/HelloWorldMongoDb/HelloWorldMongoDb.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="MongoDB.Driver" Version="2.28.0" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions Src/HelloWorldMongoDb/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Diagnostics.CodeAnalysis;

namespace HelloWorldMongoDb;

[ExcludeFromCodeCoverage]
internal static class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
10 changes: 10 additions & 0 deletions Src/HelloWorldMongoDb/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"HelloWorldMongoDb": {
"commandName": "Project"
},
"Container (Dockerfile)": {
"commandName": "Docker"
}
}
}
9 changes: 9 additions & 0 deletions Src/HelloWorldMongoDb/Testable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace HelloWorldMongoDb;

public class Testable
{
public bool TestableMethod()
{
return true;
}
}
34 changes: 34 additions & 0 deletions Tests/HelloWorldMongoDb.Tests/HelloWorldMongoDb.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\HelloWorldMongoDb\HelloWorldMongoDb.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions Tests/HelloWorldMongoDb.Tests/TestableTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentAssertions;

namespace HelloWorldMongoDb.Tests;

public class TestableTests
{
[Fact]
public void TestableMethod_StateUnderTest_ExpectedBehavior()
{
// Arrange
var testable = new Testable();

// Act
var result = testable.TestableMethod();

// Assert
result.Should().BeTrue();
}
}
19 changes: 19 additions & 0 deletions Tests/HelloWorldMongoDb.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentAssertions;

namespace HelloWorldMongoDb.Tests;

public class UnitTest1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

The test class name 'UnitTest1' is too generic. It's recommended to use more descriptive names for test classes that indicate what functionality or component is being tested. This improves code readability and makes it easier to maintain your test suite. Consider renaming this class to something more specific that reflects the actual tests it contains.

{
[Fact]
public void Test1()
{
// Arrange
const bool expected = true;

// Act
var value = true;

// Assert
value.Should().Be(expected);
}
Comment on lines +7 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Readability and Maintainability

The test method name 'Test1' is not very descriptive. It would be helpful to rename it to something that clearly states what the test is verifying. This will make it easier for other developers to understand the purpose of the test.

Comment on lines +5 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Tests

The test case in the UnitTest1 class is currently just asserting that true is true. This doesn't provide any value in terms of verifying the correctness of the code. Please update the test case to test actual functionality of the code. This could involve calling a method from the HelloWorldMongoDb project and asserting that it behaves as expected.

}
Loading