Skip to content

Commit 21c2604

Browse files
committed
Update readme and add action
1 parent 1a48ba2 commit 21c2604

File tree

8 files changed

+215
-32
lines changed

8 files changed

+215
-32
lines changed

.github/workflows/.gitkeep

Whitespace-only changes.

.github/workflows/build.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
14+
env:
15+
BUILD_CONFIG: 'Release'
16+
SOLUTION: 'DotNet.Core.Runtime.Faker.sln'
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Install .NET 3.1 SDK
24+
uses: actions/setup-dotnet@v3
25+
with:
26+
dotnet-version: 3.1.x
27+
28+
- name: Install dependencies
29+
run: dotnet restore
30+
31+
- name: Build
32+
run: dotnet build $SOLUTION -c $BUILD_CONFIG --no-restore
33+
34+
- name: Run tests
35+
run: dotnet test --logger trx -c $BUILD_CONFIG --no-restore --no-build

.github/workflows/publish.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
packages: write
12+
contents: read
13+
env:
14+
BUILD_CONFIG: 'Release'
15+
SOLUTION: 'DotNet.Core.Runtime.Faker.sln'
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- uses: actions/setup-dotnet@v3
21+
with:
22+
dotnet-version: 3.1.x
23+
24+
- name: Install dependencies
25+
run: dotnet restore
26+
27+
- name: Build
28+
run: dotnet build $SOLUTION -c $BUILD_CONFIG --no-restore
29+
30+
- name: Tag name
31+
id: tag-name
32+
run: |
33+
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
34+
35+
- name: Create the package
36+
run: dotnet pack -p:PackageVersion=$SOURCE_TAG -c $BUILD_CONFIG src/DotNet.Core.Runtime.Faker.Moq --no-build --no-restore
37+
env:
38+
SOURCE_TAG: ${{ steps.tag-name.outputs.SOURCE_TAG }}
39+
40+
- name: Create the package
41+
run: dotnet pack -p:PackageVersion=$SOURCE_TAG -c $BUILD_CONFIG src/DotNet.Core.Runtime.Faker.FakeItEasy --no-build --no-restore
42+
env:
43+
SOURCE_TAG: ${{ steps.tag-name.outputs.SOURCE_TAG }}
44+
45+
- name: Publish the package to nuget.org
46+
run: dotnet nuget push **/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
47+
env:
48+
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
49+

Readme.en.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
[![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)
3+
4+
| Package | Version | Downloads |
5+
| ------------- | ------------- | -- |
6+
| 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/) |
7+
| 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/)
8+
| 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/)
9+
10+
11+
# DotNet.Core.Runtime.Faker
12+
13+
Lib to change runtime implementation by DI in integration tests
14+
15+
## Installation
16+
17+
### Using Moq
18+
```
19+
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.Moq
20+
```
21+
22+
### Using FakeItEasy
23+
```
24+
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
25+
```
26+
27+
### Manually
28+
```
29+
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker
30+
```
31+
32+
## Configuration
33+
34+
### Using [FakeItEasy](https://github.com/FakeItEasy/FakeItEasy)
35+
- Lib DotNet.Core.Runtime.Faker.FakeItEasy
36+
- Faker registering
37+
```c#
38+
var registeredValue = new DateTime();
39+
40+
var factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
41+
builder.ConfigureTestServices(services =>
42+
{
43+
services.AddServiceWithFaker<Clock>(faker => A.CallTo(() => faker.Now()).Returns(registeredValue));
44+
}));
45+
var serviceProvider = factory.Services;
46+
```
47+
48+
- Change implementation
49+
```c#
50+
serviceProvider.Change<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new DateTime()));
51+
```
52+
53+
- Set new value
54+
55+
```c#
56+
serviceProvider.GetService<Clock>().Now();
57+
```
58+
Should returns new value =)
59+
60+
- Clean implementation to avoid problems in anothers tests
61+
```c#
62+
serviceProvider.ResetAllChanges();
63+
```
64+
65+
### Using [Moq](https://github.com/Moq/moq4)
66+
- Lib DotNet.Core.Runtime.Faker.Moq
67+
68+
Very similar with FakeItEasy, but using moq syntax
69+
```c#
70+
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
71+
builder.ConfigureTestServices(services =>
72+
{
73+
services.AddServiceWithFaker<Clock>(mock => mock.Setup(x => x.Now()).Returns(registeredValue));
74+
}));
75+
```
76+
and
77+
```c#
78+
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
79+
```
80+
81+
### Manually
82+
- Lib DotNet.Core.Runtime.Faker
83+
84+
Without any libs
85+
```c#
86+
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
87+
builder.ConfigureTestServices(services =>
88+
{
89+
services.AddServiceWithFaker<Clock>(() => new FakeClock());
90+
}));
91+
```
92+
and
93+
```c#
94+
serviceProvider.Change<Clock>(() => new FakeClock());
95+
```
96+
97+
Completed samples:
98+
- [Com FakeItEasy](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs)
99+
- [Com Moq](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs)
100+
- [Manualmente](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs)

Readme.md

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
# DotNet.Core.Runtime.Faker
21

3-
Lib para trocar implementações injetadas via DI em tempo de execução nos testes integrados
2+
[![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)
43

5-
## Instalação
4+
| Pacote | Versão | Downloads |
5+
| ------------- | ------------- | -- |
6+
| 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/) |
7+
| 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/)
8+
| 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/)
69

7-
### Com FakeItEasy
10+
# DotNet.Core.Runtime.Faker
811

9-
[![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)
12+
## Read this in other language: [English](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/Readme.en.md)
1013

11-
[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) disponível:
12-
```
13-
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
14-
```
1514

16-
### Com Moq
15+
Lib para trocar implementações injetadas via DI em tempo de execução nos testes integrados
1716

18-
[![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)
17+
## Instalação
1918

20-
[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) disponível:
19+
### Com Moq
2120
```
2221
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.Moq
2322
```
2423

25-
### Manualmente
26-
27-
[![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)
24+
### Com FakeItEasy
25+
```
26+
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
27+
```
2828

29-
[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) disponível:
29+
### Manual
3030
```
3131
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker
3232
```
3333

3434
## Configuração
3535

3636
### Através do [FakeItEasy](https://github.com/FakeItEasy/FakeItEasy)
37-
- Lib Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
37+
- Lib DotNet.Core.Runtime.Faker.FakeItEasy
3838
- Registrar o faker
3939
```c#
4040
var registeredValue = new DateTime();
4141

42-
var factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
42+
var factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
4343
builder.ConfigureTestServices(services =>
4444
{
4545
services.AddServiceWithFaker<Clock>(faker => A.CallTo(() => faker.Now()).Returns(registeredValue));
@@ -49,7 +49,7 @@ var serviceProvider = factory.Services;
4949

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

5555
- Receber novo valor
@@ -61,42 +61,44 @@ Deve retornar valor informado no change =)
6161

6262
- Limpar implementação para não influenciar em outros testes
6363
```c#
64-
serviceProvider.ResetAllFakeChanges();
64+
serviceProvider.ResetAllChanges();
6565
```
6666

6767
### Através do [Moq](https://github.com/Moq/moq4)
68-
- Lib Lambda3.DotNet.Core.Runtime.Faker.Moq
68+
- Lib DotNet.Core.Runtime.Faker.Moq
6969

7070
Muito parecido com o FakeItEasy, mas com a sintaxe do moq
7171
```c#
72-
factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
72+
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
7373
builder.ConfigureTestServices(services =>
7474
{
7575
services.AddServiceWithFaker<Clock>(mock => mock.Setup(x => x.Now()).Returns(registeredValue));
7676
}));
7777
```
7878
e
7979
```c#
80-
serviceProvider.ChangeFake<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
80+
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
8181
```
8282

8383
### Manualmente
84-
- Lib Lambda3.DotNet.Core.Runtime.Faker
84+
- Lib DotNet.Core.Runtime.Faker
8585

8686
Muito parecido com os anteriores, mas sem dependências das libs
8787
```c#
88-
factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
88+
factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
8989
builder.ConfigureTestServices(services =>
9090
{
9191
services.AddServiceWithFaker<Clock>(() => new FakeClock());
9292
}));
9393
```
9494
e
9595
```c#
96-
serviceProvider.ChangeFake<Clock>(() => new FakeClock());
96+
serviceProvider.Change<Clock>(() => new FakeClock());
9797
```
9898

9999
Exemplos completos:
100-
- [Com FakeItEasy](https://github.com/willsbctm/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs)
101-
- [Com Moq](https://github.com/willsbctm/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs)
102-
- [Manualmente](https://github.com/willsbctm/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs)
100+
- [Com FakeItEasy](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs)
101+
- [Com Moq](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs)
102+
- [Manualmente](https://github.com/Lambda3/DotNet.Core.Runtime.Faker/blob/main/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs)
103+
104+

src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<PackageId>Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy</PackageId>
6-
<PackageVersion>1.0.1</PackageVersion>
76
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
87
<IncludeSymbols>true</IncludeSymbols>
98
<Authors>William Espinosa de Rezende</Authors>

src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<PackageId>Lambda3.DotNet.Core.Runtime.Faker.Moq</PackageId>
6-
<PackageVersion>1.0.1</PackageVersion>
76
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
87
<IncludeSymbols>true</IncludeSymbols>
98
<Authors>William Espinosa de Rezende</Authors>

src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
66
<PackageId>Lambda3.DotNet.Core.Runtime.Faker</PackageId>
7-
<PackageVersion>1.0.1</PackageVersion>
87
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
98
<IncludeSymbols>true</IncludeSymbols>
109
<Authors>William Espinosa de Rezende</Authors>

0 commit comments

Comments
 (0)