Skip to content

Commit

Permalink
Update names
Browse files Browse the repository at this point in the history
  • Loading branch information
willsbctm committed Apr 16, 2021
1 parent f660fba commit 1a48ba2
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 42 deletions.
20 changes: 10 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Lib para trocar implementações injetadas via DI em tempo de execução nos tes

[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy/) disponível:
```
PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy -Version 1.0.0
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
```

### Com Moq
Expand All @@ -19,7 +19,7 @@ PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy -Version 1.0.0

[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker.Moq/) disponível:
```
PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker.Moq -Version 1.0.0
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker.Moq
```

### Manualmente
Expand All @@ -28,13 +28,13 @@ PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker.Moq -Version 1.0.0

[NuGet package](https://www.nuget.org/packages/Lambda3.DotNet.Core.Runtime.Faker/) disponível:
```
PM> Install-Package Lambda3.DotNet.Core.Runtime.Faker -Version 1.0.0
> dotnet add package Lambda3.DotNet.Core.Runtime.Faker
```

## Configuração

### Através do [FakeItEasy](https://github.com/FakeItEasy/FakeItEasy)
- Lib DotNet.Core.Runtime.Faker.FakeItEasy
- Lib Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy
- Registrar o faker
```c#
var registeredValue = new DateTime();
Expand All @@ -49,7 +49,7 @@ var serviceProvider = factory.Services;

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

- Receber novo valor
Expand All @@ -61,11 +61,11 @@ Deve retornar valor informado no change =)

- Limpar implementação para não influenciar em outros testes
```c#
serviceProvider.ResetAllChanges();
serviceProvider.ResetAllFakeChanges();
```

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

Muito parecido com o FakeItEasy, mas com a sintaxe do moq
```c#
Expand All @@ -77,11 +77,11 @@ builder.ConfigureTestServices(services =>
```
e
```c#
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
serviceProvider.ChangeFake<Clock>(mock => mock.Setup(x => x.Now()).Returns(new DateTime()));
```

### Manualmente
- Lib DotNet.Core.Runtime.Faker
- Lib Lambda3.DotNet.Core.Runtime.Faker

Muito parecido com os anteriores, mas sem dependências das libs
```c#
Expand All @@ -93,7 +93,7 @@ builder.ConfigureTestServices(services =>
```
e
```c#
serviceProvider.Change<Clock>(() => new FakeClock());
serviceProvider.ChangeFake<Clock>(() => new FakeClock());
```

Exemplos completos:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy</PackageId>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>1.0.1</PackageVersion>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
<Authors>William Espinosa de Rezende</Authors>
<Company>Lambda3</Company>
<PackageDescription>Biblioteca para troca de dependências em tempo de execução dos testes com FakeItEasy</PackageDescription>
<PackageTags>dotnet core; tests</PackageTags>
<PackageTags>dotnet core; tests; fakeiteasy;</PackageTags>
<RepositoryUrl>https://github.com/Lambda3/DotNet.Core.Runtime.Faker</RepositoryUrl>
<RepositoryBranch>main</RepositoryBranch>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FakeItEasy" Version="6.2.1" />
<PackageReference Include="FakeItEasy" Version="6.*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace DotNet.Core.Runtime.Faker.FakeItEasy
{
public static class ServiceProviderExtensions
{
public static void Change<T>(this IServiceProvider services, Action<T> configure) where T : class
public static void ChangeFake<T>(this IServiceProvider services, Action<T> configure) where T : class
{
var fake = A.Fake<T>();
configure.Invoke(fake);
services.Change(fake);
services.ChangeFake(fake);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>Lambda3.DotNet.Core.Runtime.Faker.Moq</PackageId>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>1.0.1</PackageVersion>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
<Authors>William Espinosa de Rezende</Authors>
Expand All @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.16.0" />
<PackageReference Include="Moq" Version="4.*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace DotNet.Core.Runtime.Faker.Moq
{
public static class ServiceProviderExtensions
{
public static void Change<T>(this IServiceProvider services, Action<Mock<T>> configure) where T : class
public static void ChangeFake<T>(this IServiceProvider services, Action<Mock<T>> configure) where T : class
{
var mock = new Mock<T>();
configure.Invoke(mock);
services.Change(mock.Object);
services.ChangeFake(mock.Object);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<PackageId>Lambda3.DotNet.Core.Runtime.Faker</PackageId>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>1.0.1</PackageVersion>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
<Authors>William Espinosa de Rezende</Authors>
<Company>Lambda3</Company>
<PackageDescription>Biblioteca para troca de dependências em tempo de execução dos testes</PackageDescription>
<PackageTags>dotnet core; tests; fakeiteasy</PackageTags>
<PackageTags>dotnet core; tests;</PackageTags>
<RepositoryUrl>https://github.com/Lambda3/DotNet.Core.Runtime.Faker</RepositoryUrl>
<RepositoryBranch>main</RepositoryBranch>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.*" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/DotNet.Core.Runtime.Faker/ServiceProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ private static RuntimeFaker GetRuntimeFaker<T>(this IServiceProvider services) w
return faker;
}

public static void ResetAllChanges(this IServiceProvider services) =>
public static void ResetAllFakeChanges(this IServiceProvider services) =>
services.GetRequiredService<RuntimeFaker>().ResetAllChanges();

public static void ResetChange<T>(this IServiceProvider services) where T : class =>
public static void ResetFakeChange<T>(this IServiceProvider services) where T : class =>
services.GetRequiredService<RuntimeFaker>().ResetChange<T>();

public static void Change<T>(this IServiceProvider services, T fake) where T : class =>
public static void ChangeFake<T>(this IServiceProvider services, T fake) where T : class =>
services.GetRuntimeFaker<T>().Change(fake);

public static T Get<T>(this IServiceProvider services) where T : class =>
public static T GetFake<T>(this IServiceProvider services) where T : class =>
services.GetRuntimeFaker<T>().Get<T>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public void OneTimeSetUp()
public void TearDown()
{
cliente.Dispose();
serviceProvider.ResetAllChanges();
serviceProvider.ResetAllFakeChanges();
}

[Test]
public async Task ShouldChangeClockImplementation()
{
serviceProvider.Change<Clock>(new MyClock());
serviceProvider.ChangeFake<Clock>(new MyClock());

var result = await cliente.GetAsync("time");
result.StatusCode.Should().Be(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void OneTimeSetUp()
public void TearDown()
{
cliente.Dispose();
serviceProvider.ResetAllChanges();
serviceProvider.ResetAllFakeChanges();
}

[Test]
Expand All @@ -61,7 +61,7 @@ public async Task ShouldGetRegisteredValueForClock()
public async Task ShouldChangeClockImplementation()
{
var now = new Bogus.Faker().Date.Past();
serviceProvider.Change<Clock>(faker => A.CallTo(() => faker.Now()).Returns(now));
serviceProvider.ChangeFake<Clock>(faker => A.CallTo(() => faker.Now()).Returns(now));

var result = await cliente.GetAsync("time");
result.StatusCode.Should().Be(200);
Expand All @@ -74,8 +74,8 @@ public async Task ShouldChangeClockImplementation()
[Test]
public async Task ShouldCleanChangesAndRestoreRegisteredValue()
{
serviceProvider.Change<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new Bogus.Faker().Date.Past()));
serviceProvider.ResetAllChanges();
serviceProvider.ChangeFake<Clock>(faker => A.CallTo(() => faker.Now()).Returns(new Bogus.Faker().Date.Past()));
serviceProvider.ResetAllFakeChanges();

var result = await cliente.GetAsync("time");
result.StatusCode.Should().Be(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void OneTimeSetUp()
public void TearDown()
{
cliente.Dispose();
serviceProvider.ResetAllChanges();
serviceProvider.ResetAllFakeChanges();
}

[Test]
Expand All @@ -60,7 +60,7 @@ public async Task ShouldGetRegisteredValueForClock()
public async Task ShouldChangeClockImplementation()
{
var now = new Bogus.Faker().Date.Past();
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(now));
serviceProvider.ChangeFake<Clock>(mock => mock.Setup(x => x.Now()).Returns(now));

var result = await cliente.GetAsync("time");
result.StatusCode.Should().Be(200);
Expand All @@ -73,8 +73,8 @@ public async Task ShouldChangeClockImplementation()
[Test]
public async Task ShouldCleanChangesAndRestoreRegisteredValue()
{
serviceProvider.Change<Clock>(mock => mock.Setup(x => x.Now()).Returns(new Bogus.Faker().Date.Past()));
serviceProvider.ResetAllChanges();
serviceProvider.ChangeFake<Clock>(mock => mock.Setup(x => x.Now()).Returns(new Bogus.Faker().Date.Past()));
serviceProvider.ResetAllFakeChanges();

var result = await cliente.GetAsync("time");
result.StatusCode.Should().Be(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public void ShouldResetAllChanges()
service.AddServiceWithFaker(() => new MyClass());

using var serviceProvider = service.BuildServiceProvider();
serviceProvider.Change<MyClass>(new MyClass2());
serviceProvider.ChangeFake<MyClass>(new MyClass2());

serviceProvider.ResetAllChanges();
serviceProvider.ResetAllFakeChanges();
serviceProvider.GetService<MyClass>().Should().BeOfType<MyClass>();
}

Expand All @@ -26,9 +26,9 @@ public void ShouldResetChanges()
service.AddServiceWithFaker(() => new MyClass());

using var serviceProvider = service.BuildServiceProvider();
serviceProvider.Change<MyClass>(new MyClass2());
serviceProvider.ChangeFake<MyClass>(new MyClass2());

serviceProvider.ResetChange<MyClass>();
serviceProvider.ResetFakeChange<MyClass>();
serviceProvider.GetService<MyClass>().Should().BeOfType<MyClass>();
}

Expand All @@ -39,7 +39,7 @@ public void ShouldChange()
service.AddServiceWithFaker(() => new MyClass());

using var serviceProvider = service.BuildServiceProvider();
serviceProvider.Change<MyClass>(new MyClass2());
serviceProvider.ChangeFake<MyClass>(new MyClass2());

serviceProvider.GetService<MyClass>().Should().BeOfType<MyClass2>();
}
Expand All @@ -52,7 +52,7 @@ public void ShouldGet()
service.AddServiceWithFaker(() => registeredFake);

using var serviceProvider = service.BuildServiceProvider();
var fake = serviceProvider.Get<MyClass>();
var fake = serviceProvider.GetFake<MyClass>();

fake.Should().Be(registeredFake);
}
Expand Down

0 comments on commit 1a48ba2

Please sign in to comment.