From 21c26041ca411512a080d0cbdad2a4093dcb63d4 Mon Sep 17 00:00:00 2001 From: William Rezende | Stone Date: Thu, 16 Mar 2023 10:56:29 -0300 Subject: [PATCH] Update readme and add action --- .github/workflows/.gitkeep | 0 .github/workflows/build.yaml | 35 ++++++ .github/workflows/publish.yaml | 49 +++++++++ Readme.en.md | 100 ++++++++++++++++++ Readme.md | 60 ++++++----- ...otNet.Core.Runtime.Faker.FakeItEasy.csproj | 1 - .../DotNet.Core.Runtime.Faker.Moq.csproj | 1 - .../DotNet.Core.Runtime.Faker.csproj | 1 - 8 files changed, 215 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/.gitkeep create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/publish.yaml create mode 100644 Readme.en.md diff --git a/.github/workflows/.gitkeep b/.github/workflows/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..28d04e4 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + + env: + BUILD_CONFIG: 'Release' + SOLUTION: 'DotNet.Core.Runtime.Faker.sln' + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Install .NET 3.1 SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 3.1.x + + - name: Install dependencies + run: dotnet restore + + - name: Build + run: dotnet build $SOLUTION -c $BUILD_CONFIG --no-restore + + - name: Run tests + run: dotnet test --logger trx -c $BUILD_CONFIG --no-restore --no-build diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..d36d4a8 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,49 @@ +name: Publish + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + env: + BUILD_CONFIG: 'Release' + SOLUTION: 'DotNet.Core.Runtime.Faker.sln' + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: 3.1.x + + - name: Install dependencies + run: dotnet restore + + - name: Build + run: dotnet build $SOLUTION -c $BUILD_CONFIG --no-restore + + - name: Tag name + id: tag-name + run: | + echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - name: Create the package + run: dotnet pack -p:PackageVersion=$SOURCE_TAG -c $BUILD_CONFIG src/DotNet.Core.Runtime.Faker.Moq --no-build --no-restore + env: + SOURCE_TAG: ${{ steps.tag-name.outputs.SOURCE_TAG }} + + - name: Create the package + run: dotnet pack -p:PackageVersion=$SOURCE_TAG -c $BUILD_CONFIG src/DotNet.Core.Runtime.Faker.FakeItEasy --no-build --no-restore + env: + SOURCE_TAG: ${{ steps.tag-name.outputs.SOURCE_TAG }} + + - name: Publish the package to nuget.org + run: dotnet nuget push **/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json + env: + NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }} + diff --git a/Readme.en.md b/Readme.en.md new file mode 100644 index 0000000..290fadb --- /dev/null +++ b/Readme.en.md @@ -0,0 +1,100 @@ + +[![Build status (DotNet.Core.Runtime.Faker)](https://img.shields.io/github/actions/workflow/status/Lambda3/DotNet.Core.Runtime.Faker/build.yaml)](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/actions/workflows/build.yaml) + +| Package | Version | Downloads | +| ------------- | ------------- | -- | +| Moq | [![NuGet version (DotNet.Core.Runtime.Faker.Moq)](https://img.shields.io/github/v/release/Lambda3/DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) | [![NuGet version (DotNet.Core.Runtime.Faker.Moq)](https://img.shields.io/nuget/dt/Lambda3.DotNet.Core.Runtime.Faker.Moq)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) | +| FakeItEasy | [![NuGet version (DotNet.Core.Runtime.Faker.FakeItEasy)](https://img.shields.io/github/v/release/Lambda3/DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) | [![NuGet version (DotNet.Core.Runtime.Faker.FakeItEasy)](https://img.shields.io/nuget/dt/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) +| Manually | [![NuGet version (DotNet.Core.Runtime.Faker)](https://img.shields.io/github/v/release/Lambda3/DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) | [![NuGet version (DotNet.Core.Runtime.Faker)](https://img.shields.io/nuget/dt/Lambda3.DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) + + +# DotNet.Core.Runtime.Faker + +Lib to change runtime implementation by DI in integration tests + +## Installation + +### Using Moq +``` +> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.Moq +``` + +### Using FakeItEasy +``` +> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy +``` + +### Manually +``` +> dotnet add package Lambda3.DotNet.Core.Runtime.Faker +``` + +## Configuration + +### Using [FakeItEasy](https://github.com/FakeItEasy/FakeItEasy) +- Lib DotNet.Core.Runtime.Faker.FakeItEasy +- Faker registering +```c# +var registeredValue = new DateTime(); + +var factory = new WebApplicationFactory().WithWebHostBuilder(builder => + builder.ConfigureTestServices(services => + { + services.AddServiceWithFaker(faker => A.CallTo(() => faker.Now()).Returns(registeredValue)); + })); +var serviceProvider = factory.Services; +``` + +- Change implementation +```c# +serviceProvider.Change(faker => A.CallTo(() => faker.Now()).Returns(new DateTime())); +``` + +- Set new value + +```c# +serviceProvider.GetService().Now(); +``` +Should returns new value =) + +- Clean implementation to avoid problems in anothers tests +```c# +serviceProvider.ResetAllChanges(); +``` + +### Using [Moq](https://github.com/Moq/moq4) +- Lib DotNet.Core.Runtime.Faker.Moq + +Very similar with FakeItEasy, but using moq syntax +```c# +factory = new WebApplicationFactory().WithWebHostBuilder(builder => +builder.ConfigureTestServices(services => +{ + services.AddServiceWithFaker(mock => mock.Setup(x => x.Now()).Returns(registeredValue)); +})); +``` +and +```c# + serviceProvider.Change(mock => mock.Setup(x => x.Now()).Returns(new DateTime())); +``` + +### Manually +- Lib DotNet.Core.Runtime.Faker + +Without any libs +```c# +factory = new WebApplicationFactory().WithWebHostBuilder(builder => +builder.ConfigureTestServices(services => +{ + services.AddServiceWithFaker(() => new FakeClock()); +})); +``` +and +```c# +serviceProvider.Change(() => new FakeClock()); +``` + +Completed samples: +- [Com FakeItEasy](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs) +- [Com Moq](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs) +- [Manualmente](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs) \ No newline at end of file diff --git a/Readme.md b/Readme.md index 4a44056..0f531b6 100644 --- a/Readme.md +++ b/Readme.md @@ -1,32 +1,32 @@ -# DotNet.Core.Runtime.Faker -Lib para trocar implementações injetadas via DI em tempo de execução nos testes integrados +[![Build status (DotNet.Core.Runtime.Faker)](https://img.shields.io/github/actions/workflow/status/Lambda3/DotNet.Core.Runtime.Faker/build.yaml)](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/actions/workflows/build.yaml) -## Instalação +| Pacote | Versão | Downloads | +| ------------- | ------------- | -- | +| Moq | [![NuGet version (DotNet.Core.Runtime.Faker.Moq)](https://img.shields.io/github/v/release/Lambda3/DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) | [![NuGet version (DotNet.Core.Runtime.Faker.Moq)](https://img.shields.io/nuget/dt/Lambda3.DotNet.Core.Runtime.Faker.Moq)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) | +| FakeItEasy | [![NuGet version (DotNet.Core.Runtime.Faker.FakeItEasy)](https://img.shields.io/github/v/release/Lambda3/DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) | [![NuGet version (DotNet.Core.Runtime.Faker.FakeItEasy)](https://img.shields.io/nuget/dt/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) +| Manual | [![NuGet version (DotNet.Core.Runtime.Faker)](https://img.shields.io/github/v/release/Lambda3/DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) | [![NuGet version (DotNet.Core.Runtime.Faker)](https://img.shields.io/nuget/dt/Lambda3.DotNet.Core.Runtime.Faker)](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) -### Com FakeItEasy +# DotNet.Core.Runtime.Faker -[![NuGet](https://img.shields.io/nuget/v/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy.svg?style=flat)](https://img.shields.io/nuget/v/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy.svg?style=flat) +## Read this in other language: [English](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/Readme.en.md) -[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) disponível: -``` -> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy -``` -### Com Moq +Lib para trocar implementações injetadas via DI em tempo de execução nos testes integrados -[![NuGet](https://img.shields.io/nuget/v/Lambda3.DotNet.Core.Runtime.Faker.Moq.svg?style=flat)](https://img.shields.io/nuget/v/Lambda3.DotNet.Core.Runtime.Faker.Moq.svg?style=flat) +## Instalação -[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) disponível: +### Com Moq ``` > dotnet add package Lambda3.DotNet.Core.Runtime.Faker.Moq ``` -### Manualmente - -[![NuGet](https://img.shields.io/nuget/v/Lambda3.DotNet.Core.Runtime.Faker.svg?style=flat)](https://img.shields.io/nuget/v/Lambda3.DotNet.Core.Runtime.Faker.svg?style=flat) +### Com FakeItEasy +``` +> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy +``` -[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) disponível: +### Manual ``` > dotnet add package Lambda3.DotNet.Core.Runtime.Faker ``` @@ -34,12 +34,12 @@ Lib para trocar implementações injetadas via DI em tempo de execução nos tes ## Configuração ### Através do [FakeItEasy](https://github.com/FakeItEasy/FakeItEasy) -- Lib Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy +- Lib DotNet.Core.Runtime.Faker.FakeItEasy - Registrar o faker ```c# var registeredValue = new DateTime(); -var factory = new WebApplicationFactory().WithWebHostBuilder(builder => +var factory = new WebApplicationFactory().WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { services.AddServiceWithFaker(faker => A.CallTo(() => faker.Now()).Returns(registeredValue)); @@ -49,7 +49,7 @@ var serviceProvider = factory.Services; - Mudar implementação ```c# -serviceProvider.ChangeFake(faker => A.CallTo(() => faker.Now()).Returns(new DateTime())); +serviceProvider.Change(faker => A.CallTo(() => faker.Now()).Returns(new DateTime())); ``` - Receber novo valor @@ -61,15 +61,15 @@ Deve retornar valor informado no change =) - Limpar implementação para não influenciar em outros testes ```c# -serviceProvider.ResetAllFakeChanges(); +serviceProvider.ResetAllChanges(); ``` ### Através do [Moq](https://github.com/Moq/moq4) -- Lib Lambda3.DotNet.Core.Runtime.Faker.Moq +- Lib DotNet.Core.Runtime.Faker.Moq Muito parecido com o FakeItEasy, mas com a sintaxe do moq ```c# -factory = new WebApplicationFactory().WithWebHostBuilder(builder => +factory = new WebApplicationFactory().WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { services.AddServiceWithFaker(mock => mock.Setup(x => x.Now()).Returns(registeredValue)); @@ -77,15 +77,15 @@ builder.ConfigureTestServices(services => ``` e ```c# - serviceProvider.ChangeFake(mock => mock.Setup(x => x.Now()).Returns(new DateTime())); + serviceProvider.Change(mock => mock.Setup(x => x.Now()).Returns(new DateTime())); ``` ### Manualmente -- Lib Lambda3.DotNet.Core.Runtime.Faker +- Lib DotNet.Core.Runtime.Faker Muito parecido com os anteriores, mas sem dependências das libs ```c# -factory = new WebApplicationFactory().WithWebHostBuilder(builder => +factory = new WebApplicationFactory().WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { services.AddServiceWithFaker(() => new FakeClock()); @@ -93,10 +93,12 @@ builder.ConfigureTestServices(services => ``` e ```c# -serviceProvider.ChangeFake(() => new FakeClock()); +serviceProvider.Change(() => new FakeClock()); ``` Exemplos completos: -- [Com FakeItEasy](https://github.com/willsbctm/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs) -- [Com Moq](https://github.com/willsbctm/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs) -- [Manualmente](https://github.com/willsbctm/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs) +- [Com FakeItEasy](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs) +- [Com Moq](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs) +- [Manualmente](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs) + + diff --git a/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj b/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj index 8a31b15..76dd342 100644 --- a/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj +++ b/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj @@ -3,7 +3,6 @@ netcoreapp3.1 Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy - 1.0.1 snupkg true William Espinosa de Rezende diff --git a/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj b/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj index 24553f4..cfa804c 100644 --- a/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj +++ b/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj @@ -3,7 +3,6 @@ netcoreapp3.1 Lambda3.DotNet.Core.Runtime.Faker.Moq - 1.0.1 snupkg true William Espinosa de Rezende diff --git a/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj b/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj index 0c76cae..2579468 100644 --- a/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj +++ b/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj @@ -4,7 +4,6 @@ netcoreapp3.1 true Lambda3.DotNet.Core.Runtime.Faker - 1.0.1 snupkg true William Espinosa de Rezende