-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add dotnet * Add tests * Rename project * README * Add CI
- Loading branch information
1 parent
ecb4e04
commit f810270
Showing
14 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: .NET | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: | ||
- .github/workflows/dotnet.yml | ||
- dotnet/** | ||
pull_request: | ||
branches: [ "main" ] | ||
paths: | ||
- .github/workflows/dotnet.yml | ||
- dotnet/** | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
working-directory: dotnet | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8.0 | ||
cache: false | ||
|
||
- name: Test | ||
run: dotnet test -v quiet -l:"console;verbosity=normal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
*.swp | ||
*.*~ | ||
project.lock.json | ||
.DS_Store | ||
*.pyc | ||
nupkg/ | ||
|
||
# Visual Studio Code | ||
.vscode/ | ||
|
||
# Rider | ||
.idea/ | ||
|
||
# Visual Studio | ||
.vs/ | ||
|
||
# Fleet | ||
.fleet/ | ||
|
||
# Code Rush | ||
.cr/ | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
x64/ | ||
x86/ | ||
build/ | ||
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
[Oo]ut/ | ||
msbuild.log | ||
msbuild.err | ||
msbuild.wrn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Hello.Main; | ||
|
||
public class HelloApp | ||
{ | ||
private HelloMessage message; | ||
private HelloConsole console; | ||
|
||
public HelloApp(HelloMessage message, HelloConsole console) { | ||
this.message = message; | ||
this.console = console; | ||
} | ||
|
||
public void PrintHello() { | ||
console.Print(message.Text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Hello.Main; | ||
|
||
public interface HelloConsole { | ||
void Print(String text); | ||
} | ||
|
||
public class HelloSystemConsole : HelloConsole | ||
{ | ||
public void Print(String text) { | ||
Console.WriteLine(text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Hello.Main; | ||
|
||
public interface HelloMessage | ||
{ | ||
public String Text { | ||
get; | ||
} | ||
} | ||
|
||
public class HelloWorldMessage : HelloMessage | ||
{ | ||
public string Text { | ||
get { | ||
return "Hello World!"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Hello.Main; | ||
|
||
var message = new HelloWorldMessage(); | ||
var console = new HelloSystemConsole(); | ||
var app = new HelloApp(message, console); | ||
app.PrintHello(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using NUnit.Framework; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<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="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="Moq" Version="4.20.69" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Hello.Main\Hello.Main.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Hello.Main; | ||
using Moq; | ||
|
||
namespace Hello.Test; | ||
|
||
public class HelloAppTest | ||
{ | ||
[Test] | ||
public void ShouldPrintHelloMessage() | ||
{ | ||
var messageText = "Hello Test!"; | ||
var messageMock = new Mock<HelloMessage>(); | ||
messageMock.Setup(message => message.Text).Returns(messageText); | ||
var message = messageMock.Object; | ||
|
||
var consoleMock = new Mock<HelloConsole>(); | ||
var console = consoleMock.Object; | ||
|
||
var app = new HelloApp(message, console); | ||
app.PrintHello(); | ||
|
||
consoleMock.Verify(console => console.Print(messageText), Times.Once); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Hello.Main; | ||
|
||
namespace Hello.Test; | ||
|
||
public class HelloMessageTest | ||
{ | ||
[Test] | ||
public void ShouldReturnHelloWorld() | ||
{ | ||
var message = new HelloWorldMessage(); | ||
Assert.That(message.Text, Is.EqualTo("Hello World!")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello.Main", "Hello.Main\Hello.Main.csproj", "{A0D91AB6-E8CD-4023-BDC8-A5A4D54DC79B}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello.Test", "Hello.Test\Hello.Test.csproj", "{92B5ED7F-F84D-4467-AB5B-1B9BFEEDF240}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A0D91AB6-E8CD-4023-BDC8-A5A4D54DC79B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A0D91AB6-E8CD-4023-BDC8-A5A4D54DC79B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A0D91AB6-E8CD-4023-BDC8-A5A4D54DC79B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A0D91AB6-E8CD-4023-BDC8-A5A4D54DC79B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{92B5ED7F-F84D-4467-AB5B-1B9BFEEDF240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{92B5ED7F-F84D-4467-AB5B-1B9BFEEDF240}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{92B5ED7F-F84D-4467-AB5B-1B9BFEEDF240}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{92B5ED7F-F84D-4467-AB5B-1B9BFEEDF240}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[![CI](https://github.com/rogervinas/tests-everywhere/actions/workflows/dotnet.yml/badge.svg)](https://github.com/rogervinas/tests-everywhere/actions/workflows/dotnet.yml) | ||
![.NET](https://img.shields.io/badge/.NET-8.0-blue?labelColor=black) | ||
|
||
# .NET | ||
|
||
[.NET C#](https://learn.microsoft.com/dotnet/csharp) testing with [NUnit](https://nunit.org/) and [Moq](https://www.devlooped.com/moq/) | ||
|
||
## Run this project using 🐳 [docker](https://www.docker.com/) | ||
* Execute `./docker-run.sh` | ||
* Once inside the container: | ||
* Test with `dotnet test -v quiet -l:"console;verbosity=normal"` | ||
* Run with `dotnet run --project Hello.Main` | ||
* Build with `dotnet publish -c Release` | ||
|
||
## Run this project locally | ||
|
||
### Pre-requisites | ||
* Install [.NET](https://dotnet.microsoft.com/download) | ||
* Check [.NET CLI](https://learn.microsoft.com/dotnet/core/tools/) executing `dotnet --version` | ||
|
||
### Run locally | ||
* Test with `dotnet test -v quiet -l:"console;verbosity=normal"` | ||
* Run with `dotnet run --project Hello.Main` | ||
* Build with `dotnet publish -c Release` | ||
|
||
### Create project from scratch | ||
* Execute these commands: | ||
``` | ||
dotnet new sln --name Hello | ||
dotnet new console --language "C#" --framework net8.0 --name Hello.Main | ||
dotnet new nunit --language "C#" --framework net8.0 --name Hello.Test | ||
dotnet add ./Hello.Test reference ./Hello.Main | ||
dotnet add ./Hello.Test package Moq --version 4.20.69 | ||
dotnet sln Hello.sln add ./Hello.Main ./Hello.Test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
docker run -it --rm \ | ||
--name dotnet \ | ||
--volume $PWD:/project \ | ||
--workdir /project \ | ||
--entrypoint "/usr/bin/bash" \ | ||
mcr.microsoft.com/dotnet/sdk:8.0 |