Lambda3.DotNet.Core.Runtime.Faker
1.0.1
Prefix Reserved
dotnet add package Lambda3.DotNet.Core.Runtime.Faker --version 1.0.1
NuGet\Install-Package Lambda3.DotNet.Core.Runtime.Faker -Version 1.0.1
<PackageReference Include="Lambda3.DotNet.Core.Runtime.Faker" Version="1.0.1" />
paket add Lambda3.DotNet.Core.Runtime.Faker --version 1.0.1
#r "nuget: Lambda3.DotNet.Core.Runtime.Faker, 1.0.1"
// Install Lambda3.DotNet.Core.Runtime.Faker as a Cake Addin #addin nuget:?package=Lambda3.DotNet.Core.Runtime.Faker&version=1.0.1 // Install Lambda3.DotNet.Core.Runtime.Faker as a Cake Tool #tool nuget:?package=Lambda3.DotNet.Core.Runtime.Faker&version=1.0.1
DotNet.Core.Runtime.Faker
Lib para trocar implementações injetadas via DI em tempo de execução nos testes integrados
Instalação
Com FakeItEasy
NuGet package disponível:
PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy -Version 1.0.0
Com Moq
NuGet package disponível:
PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker.Moq -Version 1.0.0
Manualmente
NuGet package disponível:
PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker -Version 1.0.0
Configuração
Através do FakeItEasy
- Lib DotNet.Core.Runtime.Faker.FakeItEasy
- Registrar o faker
var registeredValue = new DateTime();
var factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(faker => A.CallTo(() => faker.Now()).Returns(registeredValue));
}));
var serviceProvider = factory.Services;
- Mudar implementação
serviceProvider.Change<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new DateTime()));
- Receber novo valor
serviceProvider.GetService<Clock>().Now();
Deve retornar valor informado no change =)
- Limpar implementação para não influenciar em outros testes
serviceProvider.ResetAllChanges();
Através do Moq
- Lib DotNet.Core.Runtime.Faker.Moq
Muito parecido com o FakeItEasy, mas com a sintaxe do moq
factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(mock => mock.Setup(x => x.Now()).Returns(registeredValue));
}));
e
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
Manualmente
- Lib DotNet.Core.Runtime.Faker
Muito parecido com os anteriores, mas sem dependências das libs
factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker<Clock>(() => new FakeClock());
}));
e
serviceProvider.Change<Clock>(() => new FakeClock());
Exemplos completos:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Lambda3.DotNet.Core.Runtime.Faker:
Package | Downloads |
---|---|
Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
Biblioteca para troca de dependências em tempo de execução dos testes com FakeItEasy |
|
Lambda3.DotNet.Core.Runtime.Faker.Moq
Biblioteca para troca de dependências em tempo de execução dos testes com Moq |
GitHub repositories
This package is not used by any popular GitHub repositories.