Skip to content

Commit

Permalink
Update readme and add action
Browse files Browse the repository at this point in the history
  • Loading branch information
willsbctm committed Mar 16, 2023
1 parent 1a48ba2 commit 21c2604
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 32 deletions.
Empty file removed .github/workflows/.gitkeep
Empty file.
35 changes: 35 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

100 changes: 100 additions & 0 deletions Readme.en.md
Original file line number Diff line number Diff line change
@@ -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<Program>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(faker => A.CallTo(() => faker.Now()).Returns(registeredValue));
}));
var serviceProvider = factory.Services;
```

- Change implementation
```c#
serviceProvider.Change<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new DateTime()));
```

- Set new value

```c#
serviceProvider.GetService<Clock>().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<Program>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(mock => mock.Setup(x => x.Now()).Returns(registeredValue));
}));
```
and
```c#
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
```

### Manually
- Lib DotNet.Core.Runtime.Faker

Without any libs
```c#
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(() => new FakeClock());
}));
```
and
```c#
serviceProvider.Change<Clock>(() => 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)
60 changes: 31 additions & 29 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# 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
```

## 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<Startup>().WithWebHostBuilder(builder =>
var factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(faker => A.CallTo(() => faker.Now()).Returns(registeredValue));
Expand All @@ -49,7 +49,7 @@ var serviceProvider = factory.Services;

- Mudar implementação
```c#
serviceProvider.ChangeFake<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new DateTime()));
serviceProvider.Change<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new DateTime()));
```

- Receber novo valor
Expand All @@ -61,42 +61,44 @@ 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<Startup>().WithWebHostBuilder(builder =>
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(mock => mock.Setup(x => x.Now()).Returns(registeredValue));
}));
```
e
```c#
serviceProvider.ChangeFake<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
serviceProvider.Change<Clock>(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<Startup>().WithWebHostBuilder(builder =>
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(() => new FakeClock());
}));
```
e
```c#
serviceProvider.ChangeFake<Clock>(() => new FakeClock());
serviceProvider.Change<Clock>(() => 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)


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy</PackageId>
<PackageVersion>1.0.1</PackageVersion>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
<Authors>William Espinosa de Rezende</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>Lambda3.DotNet.Core.Runtime.Faker.Moq</PackageId>
<PackageVersion>1.0.1</PackageVersion>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
<Authors>William Espinosa de Rezende</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<PackageId>Lambda3.DotNet.Core.Runtime.Faker</PackageId>
<PackageVersion>1.0.1</PackageVersion>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
<Authors>William Espinosa de Rezende</Authors>
Expand Down

0 comments on commit 21c2604

Please sign in to comment.