-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
215 additions
and
32 deletions.
There are no files selected for viewing
Empty file.
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,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 |
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,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 }} | ||
|
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,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) |
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
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
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
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