diff --git a/Readme.md b/Readme.md index e877ca5..4a44056 100644 --- a/Readme.md +++ b/Readme.md @@ -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 @@ -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 @@ -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(); @@ -49,7 +49,7 @@ var serviceProvider = factory.Services; - Mudar implementação ```c# -serviceProvider.Change(faker => A.CallTo(() => faker.Now()).Returns(new DateTime())); +serviceProvider.ChangeFake(faker => A.CallTo(() => faker.Now()).Returns(new DateTime())); ``` - Receber novo valor @@ -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# @@ -77,11 +77,11 @@ builder.ConfigureTestServices(services => ``` e ```c# - serviceProvider.Change(mock => mock.Setup(x => x.Now()).Returns(new DateTime())); + serviceProvider.ChangeFake(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# @@ -93,7 +93,7 @@ builder.ConfigureTestServices(services => ``` e ```c# -serviceProvider.Change(() => new FakeClock()); +serviceProvider.ChangeFake(() => new FakeClock()); ``` Exemplos completos: diff --git a/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj b/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj index d5d4bae..8a31b15 100644 --- a/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj +++ b/src/DotNet.Core.Runtime.Faker.FakeItEasy/DotNet.Core.Runtime.Faker.FakeItEasy.csproj @@ -3,20 +3,20 @@ netcoreapp3.1 Lambda3.DotNet.Core.Runtime.Faker.FakeItEasy - 1.0.0 + 1.0.1 snupkg true William Espinosa de Rezende Lambda3 Biblioteca para troca de dependências em tempo de execução dos testes com FakeItEasy - dotnet core; tests + dotnet core; tests; fakeiteasy; https://github.com/Lambda3/DotNet.Core.Runtime.Faker main MIT - + diff --git a/src/DotNet.Core.Runtime.Faker.FakeItEasy/ServiceProviderExtensions.cs b/src/DotNet.Core.Runtime.Faker.FakeItEasy/ServiceProviderExtensions.cs index ed3434d..8a3a5bc 100644 --- a/src/DotNet.Core.Runtime.Faker.FakeItEasy/ServiceProviderExtensions.cs +++ b/src/DotNet.Core.Runtime.Faker.FakeItEasy/ServiceProviderExtensions.cs @@ -5,11 +5,11 @@ namespace DotNet.Core.Runtime.Faker.FakeItEasy { public static class ServiceProviderExtensions { - public static void Change(this IServiceProvider services, Action configure) where T : class + public static void ChangeFake(this IServiceProvider services, Action configure) where T : class { var fake = A.Fake(); configure.Invoke(fake); - services.Change(fake); + services.ChangeFake(fake); } } } diff --git a/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj b/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj index 0986271..24553f4 100644 --- a/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj +++ b/src/DotNet.Core.Runtime.Faker.Moq/DotNet.Core.Runtime.Faker.Moq.csproj @@ -3,7 +3,7 @@ netcoreapp3.1 Lambda3.DotNet.Core.Runtime.Faker.Moq - 1.0.0 + 1.0.1 snupkg true William Espinosa de Rezende @@ -16,7 +16,7 @@ - + diff --git a/src/DotNet.Core.Runtime.Faker.Moq/ServiceProviderExtensions.cs b/src/DotNet.Core.Runtime.Faker.Moq/ServiceProviderExtensions.cs index 0ad7267..7e57477 100644 --- a/src/DotNet.Core.Runtime.Faker.Moq/ServiceProviderExtensions.cs +++ b/src/DotNet.Core.Runtime.Faker.Moq/ServiceProviderExtensions.cs @@ -5,11 +5,11 @@ namespace DotNet.Core.Runtime.Faker.Moq { public static class ServiceProviderExtensions { - public static void Change(this IServiceProvider services, Action> configure) where T : class + public static void ChangeFake(this IServiceProvider services, Action> configure) where T : class { var mock = new Mock(); configure.Invoke(mock); - services.Change(mock.Object); + services.ChangeFake(mock.Object); } } } diff --git a/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj b/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj index 59b3c76..0c76cae 100644 --- a/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj +++ b/src/DotNet.Core.Runtime.Faker/DotNet.Core.Runtime.Faker.csproj @@ -4,20 +4,20 @@ netcoreapp3.1 true Lambda3.DotNet.Core.Runtime.Faker - 1.0.0 + 1.0.1 snupkg true William Espinosa de Rezende Lambda3 Biblioteca para troca de dependências em tempo de execução dos testes - dotnet core; tests; fakeiteasy + dotnet core; tests; https://github.com/Lambda3/DotNet.Core.Runtime.Faker main MIT - + diff --git a/src/DotNet.Core.Runtime.Faker/ServiceProviderExtensions.cs b/src/DotNet.Core.Runtime.Faker/ServiceProviderExtensions.cs index a74cc9f..fb14d34 100644 --- a/src/DotNet.Core.Runtime.Faker/ServiceProviderExtensions.cs +++ b/src/DotNet.Core.Runtime.Faker/ServiceProviderExtensions.cs @@ -12,16 +12,16 @@ private static RuntimeFaker GetRuntimeFaker(this IServiceProvider services) w return faker; } - public static void ResetAllChanges(this IServiceProvider services) => + public static void ResetAllFakeChanges(this IServiceProvider services) => services.GetRequiredService().ResetAllChanges(); - public static void ResetChange(this IServiceProvider services) where T : class => + public static void ResetFakeChange(this IServiceProvider services) where T : class => services.GetRequiredService().ResetChange(); - public static void Change(this IServiceProvider services, T fake) where T : class => + public static void ChangeFake(this IServiceProvider services, T fake) where T : class => services.GetRuntimeFaker().Change(fake); - public static T Get(this IServiceProvider services) where T : class => + public static T GetFake(this IServiceProvider services) where T : class => services.GetRuntimeFaker().Get(); } } diff --git a/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs b/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs index 66812bc..b80eae7 100644 --- a/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs +++ b/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingCustomFakerTests.cs @@ -41,13 +41,13 @@ public void OneTimeSetUp() public void TearDown() { cliente.Dispose(); - serviceProvider.ResetAllChanges(); + serviceProvider.ResetAllFakeChanges(); } [Test] public async Task ShouldChangeClockImplementation() { - serviceProvider.Change(new MyClock()); + serviceProvider.ChangeFake(new MyClock()); var result = await cliente.GetAsync("time"); result.StatusCode.Should().Be(200); diff --git a/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs b/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs index 57c0443..6fa440b 100644 --- a/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs +++ b/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingFakeItEasyTests.cs @@ -43,7 +43,7 @@ public void OneTimeSetUp() public void TearDown() { cliente.Dispose(); - serviceProvider.ResetAllChanges(); + serviceProvider.ResetAllFakeChanges(); } [Test] @@ -61,7 +61,7 @@ public async Task ShouldGetRegisteredValueForClock() public async Task ShouldChangeClockImplementation() { var now = new Bogus.Faker().Date.Past(); - serviceProvider.Change(faker => A.CallTo(() => faker.Now()).Returns(now)); + serviceProvider.ChangeFake(faker => A.CallTo(() => faker.Now()).Returns(now)); var result = await cliente.GetAsync("time"); result.StatusCode.Should().Be(200); @@ -74,8 +74,8 @@ public async Task ShouldChangeClockImplementation() [Test] public async Task ShouldCleanChangesAndRestoreRegisteredValue() { - serviceProvider.Change(faker => A.CallTo(() => faker.Now()).Returns(new Bogus.Faker().Date.Past())); - serviceProvider.ResetAllChanges(); + serviceProvider.ChangeFake(faker => A.CallTo(() => faker.Now()).Returns(new Bogus.Faker().Date.Past())); + serviceProvider.ResetAllFakeChanges(); var result = await cliente.GetAsync("time"); result.StatusCode.Should().Be(200); diff --git a/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs b/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs index a093b9a..9568d19 100644 --- a/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs +++ b/test/DotNet.Core.Runtime.Faker.Integration.Tests/RuntimeFakerUsingMoqTests.cs @@ -42,7 +42,7 @@ public void OneTimeSetUp() public void TearDown() { cliente.Dispose(); - serviceProvider.ResetAllChanges(); + serviceProvider.ResetAllFakeChanges(); } [Test] @@ -60,7 +60,7 @@ public async Task ShouldGetRegisteredValueForClock() public async Task ShouldChangeClockImplementation() { var now = new Bogus.Faker().Date.Past(); - serviceProvider.Change(mock => mock.Setup(x => x.Now()).Returns(now)); + serviceProvider.ChangeFake(mock => mock.Setup(x => x.Now()).Returns(now)); var result = await cliente.GetAsync("time"); result.StatusCode.Should().Be(200); @@ -73,8 +73,8 @@ public async Task ShouldChangeClockImplementation() [Test] public async Task ShouldCleanChangesAndRestoreRegisteredValue() { - serviceProvider.Change(mock => mock.Setup(x => x.Now()).Returns(new Bogus.Faker().Date.Past())); - serviceProvider.ResetAllChanges(); + serviceProvider.ChangeFake(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); diff --git a/test/DotNet.Core.Runtime.Faker.Unit.Tests/ServiceProviderExtensionsTests.cs b/test/DotNet.Core.Runtime.Faker.Unit.Tests/ServiceProviderExtensionsTests.cs index aae0481..74db94e 100644 --- a/test/DotNet.Core.Runtime.Faker.Unit.Tests/ServiceProviderExtensionsTests.cs +++ b/test/DotNet.Core.Runtime.Faker.Unit.Tests/ServiceProviderExtensionsTests.cs @@ -13,9 +13,9 @@ public void ShouldResetAllChanges() service.AddServiceWithFaker(() => new MyClass()); using var serviceProvider = service.BuildServiceProvider(); - serviceProvider.Change(new MyClass2()); + serviceProvider.ChangeFake(new MyClass2()); - serviceProvider.ResetAllChanges(); + serviceProvider.ResetAllFakeChanges(); serviceProvider.GetService().Should().BeOfType(); } @@ -26,9 +26,9 @@ public void ShouldResetChanges() service.AddServiceWithFaker(() => new MyClass()); using var serviceProvider = service.BuildServiceProvider(); - serviceProvider.Change(new MyClass2()); + serviceProvider.ChangeFake(new MyClass2()); - serviceProvider.ResetChange(); + serviceProvider.ResetFakeChange(); serviceProvider.GetService().Should().BeOfType(); } @@ -39,7 +39,7 @@ public void ShouldChange() service.AddServiceWithFaker(() => new MyClass()); using var serviceProvider = service.BuildServiceProvider(); - serviceProvider.Change(new MyClass2()); + serviceProvider.ChangeFake(new MyClass2()); serviceProvider.GetService().Should().BeOfType(); } @@ -52,7 +52,7 @@ public void ShouldGet() service.AddServiceWithFaker(() => registeredFake); using var serviceProvider = service.BuildServiceProvider(); - var fake = serviceProvider.Get(); + var fake = serviceProvider.GetFake(); fake.Should().Be(registeredFake); }