Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy 1.0.2

Prefix Reserved
dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy --version 1.0.2                
NuGet\Install-Package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy --version 1.0.2                
#r "nuget: Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy as a Cake Addin
#addin nuget:?package=Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy&version=1.0.2

// Install Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy as a Cake Tool
#tool nuget:?package=Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy&version=1.0.2                

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

NuGet package disponível:

> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy

Com Moq

NuGet

NuGet package disponível:

> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.Moq

Manualmente

NuGet

NuGet package disponível:

> dotnet add package Lambda3.DotNet.Core.Runtime.Faker

Configuração

Através do FakeItEasy

  • Lib Lambda3.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.ChangeFake<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.ResetAllFakeChanges();

Através do Moq

  • Lib Lambda3.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.ChangeFake<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));

Manualmente

  • Lib Lambda3.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.ChangeFake<Clock>(() => new FakeClock());

Exemplos completos:

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 9,183 4/16/2021
1.0.1 737 4/16/2021
1.0.0 787 4/15/2021