From 1a5a5a36ec55cd18ec3ea735455a51c90764d2b4 Mon Sep 17 00:00:00 2001 From: vitor Date: Sun, 22 Oct 2023 21:26:37 -0300 Subject: [PATCH 1/4] =?UTF-8?q?add=20testes=20unit=C3=A1rios=20para=20fila?= =?UTF-8?q?=20pedidos=20worker=20e=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/FilaPedidoAggregateTest.cs | 80 +++++++++++++++++++ .../TechLanches.UnitTests.csproj | 1 + .../Worker/FilaPedidoWorkerTest.cs | 75 +++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 test/TechLanches.UnitTests/Services/FilaPedidoAggregateTest.cs create mode 100644 test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs diff --git a/test/TechLanches.UnitTests/Services/FilaPedidoAggregateTest.cs b/test/TechLanches.UnitTests/Services/FilaPedidoAggregateTest.cs new file mode 100644 index 00000000..a318dcc9 --- /dev/null +++ b/test/TechLanches.UnitTests/Services/FilaPedidoAggregateTest.cs @@ -0,0 +1,80 @@ +using NSubstitute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TechLanches.Application.DTOs; +using TechLanches.Application.Ports.Repositories; +using TechLanches.Application; +using TechLanches.Domain.Enums; +using TechLanches.Domain.Repositories; +using TechLanches.Domain.Aggregates; +using TechLanches.Domain.ValueObjects; + +namespace TechLanches.UnitTests.Services +{ + public class FilaPedidoAggregateTest + { + [Fact] + public async Task RetornarPrimeiroPedidoDaFila_ComPedidosNaFila_DeveRetornarPedido() + { + // Arrange + var mockFilaPedidoRepository = Substitute.For(); + var mockPedidoRepository = Substitute.For(); + + mockFilaPedidoRepository.RetornarFilaPedidos().Returns(Task.FromResult(new List + { + new FilaPedido { PedidoId = 1 }, + new FilaPedido { PedidoId = 2 } + })); + + mockPedidoRepository.BuscarPorId(1).Returns(Task.FromResult(new Pedido(1, new List { new ItemPedido(1, 1, 1) }))); + + var filaPedidoService = new FilaPedidoService(mockPedidoRepository, mockFilaPedidoRepository); + + // Act + var pedido = await filaPedidoService.RetornarPrimeiroPedidoDaFila(); + + // Assert + Assert.NotNull(pedido); + } + + [Fact] + public async Task RetornarPrimeiroPedidoDaFila_ComFilaVazia_DeveRetornarNull() + { + // Arrange + var mockFilaPedidoRepository = Substitute.For(); + var mockPedidoRepository = Substitute.For(); + + mockFilaPedidoRepository.RetornarFilaPedidos().Returns(Task.FromResult(new List())); + + var filaPedidoService = new FilaPedidoService(mockPedidoRepository, mockFilaPedidoRepository); + + // Act + var result = await filaPedidoService.RetornarPrimeiroPedidoDaFila(); + + // Assert + Assert.Null(result); + } + + [Fact] + public async Task TrocarStatus_DeveAtualizarStatusDoPedidoECommit() + { + // Arrange + var mockFilaPedidoRepository = Substitute.For(); + var mockPedidoRepository = Substitute.For(); + + var pedido = new Pedido(1, new List { new ItemPedido(1, 1, 1) }); + + var filaPedidoService = new FilaPedidoService(mockPedidoRepository, mockFilaPedidoRepository); + + // Act + await filaPedidoService.TrocarStatus(pedido, StatusPedido.PedidoEmPreparacao); + + // Assert + Assert.Equal(StatusPedido.PedidoEmPreparacao, pedido.StatusPedido); + await mockPedidoRepository.Received(1).UnitOfWork.Commit(); + } + } +} diff --git a/test/TechLanches.UnitTests/TechLanches.UnitTests.csproj b/test/TechLanches.UnitTests/TechLanches.UnitTests.csproj index 6773d798..5233a884 100644 --- a/test/TechLanches.UnitTests/TechLanches.UnitTests.csproj +++ b/test/TechLanches.UnitTests/TechLanches.UnitTests.csproj @@ -23,6 +23,7 @@ + diff --git a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs new file mode 100644 index 00000000..75b07a52 --- /dev/null +++ b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs @@ -0,0 +1,75 @@ +using Microsoft.Extensions.Logging; +using NSubstitute; +using NSubstitute.ExceptionExtensions; +using TechLanches.Adapter.FilaPedidos; +using TechLanches.Application.Ports.Services; +using TechLanches.Domain.Aggregates; +using TechLanches.Domain.Enums; +using TechLanches.Domain.ValueObjects; + +namespace TechLanches.UnitTests.Worker +{ + public class FilaPedidoWorkerTest + { + [Fact] + public async Task ExecuteAsync_ComProximoPedido_DeveProcessarPedido() + { + // Arrange + var mockFilaPedidoService = Substitute.For(); + mockFilaPedidoService.RetornarPrimeiroPedidoDaFila().Returns(new Pedido(1, new List { new ItemPedido(1, 1, 1) })); + var mockLogger = Substitute.For>(); + + var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService); + + // Act + await workerService.StartAsync(CancellationToken.None); + await Task.Delay(1000 * 21); // Aguardando um período para permitir que o método ExecuteAsync seja executado + + // Assert + await mockFilaPedidoService.Received(1).RetornarPrimeiroPedidoDaFila(); + await mockFilaPedidoService.Received(1).TrocarStatus(Arg.Any(), StatusPedido.PedidoEmPreparacao); + await mockFilaPedidoService.Received(1).TrocarStatus(Arg.Any(), StatusPedido.PedidoPronto); + } + + [Fact] + public async Task ExecuteAsync_SemProximoPedido_NaoDeveProcessar() + { + // Arrange + var mockFilaPedidoService = Substitute.For(); + mockFilaPedidoService.RetornarPrimeiroPedidoDaFila().Returns(Task.FromResult(null)); + + var mockLogger = Substitute.For>(); + + var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService); + + // Act + await workerService.StartAsync(CancellationToken.None); + await Task.Delay(100); + + // Assert + await mockFilaPedidoService.Received(1).RetornarPrimeiroPedidoDaFila(); + await mockFilaPedidoService.DidNotReceive().TrocarStatus(Arg.Any(), Arg.Any()); + } + + [Fact] + public async Task ExecuteAsync_ComExcecao_NoCatch_DeveLogarErro() + { + // Arrange + var mockFilaPedidoService = Substitute.For(); + mockFilaPedidoService.RetornarPrimeiroPedidoDaFila().Throws(x => throw new Exception("Simulando erro")); + + var mockLogger = Substitute.For>(); + + var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService); + + // Act + await workerService.StartAsync(CancellationToken.None); + await Task.Delay(100); + + // Assert + await mockFilaPedidoService.Received(1).RetornarPrimeiroPedidoDaFila(); + await mockFilaPedidoService.DidNotReceive().TrocarStatus(Arg.Any(), Arg.Any()); + } + + } +} From 3275da280975586ea263cf4dd2843e1618f900ac Mon Sep 17 00:00:00 2001 From: vitor Date: Mon, 23 Oct 2023 09:41:14 -0300 Subject: [PATCH 2/4] =?UTF-8?q?corre=C3=A7=C3=A3o=20teste=20worker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs index 75b07a52..a92a43ca 100644 --- a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs +++ b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs @@ -69,7 +69,8 @@ public async Task ExecuteAsync_ComExcecao_NoCatch_DeveLogarErro() // Assert await mockFilaPedidoService.Received(1).RetornarPrimeiroPedidoDaFila(); await mockFilaPedidoService.DidNotReceive().TrocarStatus(Arg.Any(), Arg.Any()); + mockLogger.Received(1).Log(LogLevel.Error, Arg.Any(), Arg.Any(), Arg.Any(), + Arg.Any>()); } - - } + } } From 62ad42957c84f2c07988004191bb59b76097a453 Mon Sep 17 00:00:00 2001 From: vitor Date: Mon, 23 Oct 2023 15:15:34 -0300 Subject: [PATCH 3/4] =?UTF-8?q?utilizando=20o=20padr=C3=A3o=20ioptions=20n?= =?UTF-8?q?o=20worker=20para=20parametrizar=20tempo=20de=20espera=20da=20f?= =?UTF-8?q?ila=20e=20melhorias=20nos=20testes=20unit=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FilaPedidosHostedService.cs | 11 ++++-- .../Options/WorkerOptions.cs | 8 +++++ .../Program.cs | 3 ++ .../appsettings.Development.json | 4 +++ .../appsettings.json | 4 +++ .../Worker/FilaPedidoWorkerTest.cs | 35 ++++++++++++++++--- 6 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs index 7a3d385f..12d2f5fa 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Options; +using TechLanches.Adapter.FilaPedidos.Options; using TechLanches.Application.Ports.Services; using TechLanches.Domain.Enums; @@ -7,13 +9,16 @@ public class FilaPedidosHostedService : BackgroundService { private readonly IFilaPedidoService _filaPedidoService; private readonly ILogger _logger; + private readonly WorkerOptions _workerOptions; public FilaPedidosHostedService( ILogger logger, - IFilaPedidoService filaPedidoService) + IFilaPedidoService filaPedidoService, + IOptions workerOptions) { _logger = logger; _filaPedidoService = filaPedidoService; + _workerOptions = workerOptions.Value; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) @@ -34,7 +39,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) _logger.LogInformation($"Pedido {proximoPedido.Id} em preparação."); - await Task.Delay(1000 * 20, stoppingToken); + await Task.Delay(1000 * _workerOptions.DelayPreparacaoPedido, stoppingToken); _logger.LogInformation($"Pedido {proximoPedido.Id} preparação finalizada."); @@ -52,7 +57,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) _logger.LogError(ex, "Erro ao processar fila de pedidos."); } - await Task.Delay(5000, stoppingToken); + await Task.Delay(_workerOptions.DelayVerificacaoFila * 1000, stoppingToken); } } } diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs new file mode 100644 index 00000000..b1722f7f --- /dev/null +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs @@ -0,0 +1,8 @@ +namespace TechLanches.Adapter.FilaPedidos.Options +{ + public class WorkerOptions + { + public int DelayPreparacaoPedido { get; set; } + public int DelayVerificacaoFila { get; set; } + } +} \ No newline at end of file diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Program.cs b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Program.cs index 34dc1c82..9181a406 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Program.cs +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Program.cs @@ -1,5 +1,7 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using TechLanches.Adapter.FilaPedidos; +using TechLanches.Adapter.FilaPedidos.Options; using TechLanches.Adapter.SqlServer; using TechLanches.Adapter.SqlServer.Repositories; using TechLanches.Application; @@ -17,6 +19,7 @@ .Build(); services.AddDatabaseConfiguration(settingsConfig, ServiceLifetime.Singleton); + services.Configure(settingsConfig.GetSection("Worker")); services.AddSingleton(); services.AddSingleton(); diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json index 42cdddff..409e4a79 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json @@ -2,6 +2,10 @@ "ConnectionStrings": { "DefaultConnection": "Server=127.0.0.1,1433;Database=techlanches;User=sa;Password=Qwert@12345" }, + "Worker": { + "DelayPreparacaoPedido": 20, + "DelayVerificacaoFila": 5 + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json index 42cdddff..409e4a79 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json @@ -2,6 +2,10 @@ "ConnectionStrings": { "DefaultConnection": "Server=127.0.0.1,1433;Database=techlanches;User=sa;Password=Qwert@12345" }, + "Worker": { + "DelayPreparacaoPedido": 20, + "DelayVerificacaoFila": 5 + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs index a92a43ca..dd64edf2 100644 --- a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs +++ b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs @@ -1,7 +1,9 @@ using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using NSubstitute; using NSubstitute.ExceptionExtensions; using TechLanches.Adapter.FilaPedidos; +using TechLanches.Adapter.FilaPedidos.Options; using TechLanches.Application.Ports.Services; using TechLanches.Domain.Aggregates; using TechLanches.Domain.Enums; @@ -19,11 +21,20 @@ public async Task ExecuteAsync_ComProximoPedido_DeveProcessarPedido() mockFilaPedidoService.RetornarPrimeiroPedidoDaFila().Returns(new Pedido(1, new List { new ItemPedido(1, 1, 1) })); var mockLogger = Substitute.For>(); - var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService); + var mockOptions = Substitute.For>(); + var workerOptions = new WorkerOptions + { + DelayPreparacaoPedido = 1, + DelayVerificacaoFila = 5 + }; + + mockOptions.Value.Returns(workerOptions); + + var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService, mockOptions); // Act await workerService.StartAsync(CancellationToken.None); - await Task.Delay(1000 * 21); // Aguardando um período para permitir que o método ExecuteAsync seja executado + await Task.Delay(1000 * (workerOptions.DelayPreparacaoPedido + 1)); // Aguardando um período para permitir que o método ExecuteAsync seja executado // Assert await mockFilaPedidoService.Received(1).RetornarPrimeiroPedidoDaFila(); @@ -40,7 +51,16 @@ public async Task ExecuteAsync_SemProximoPedido_NaoDeveProcessar() var mockLogger = Substitute.For>(); - var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService); + var mockOptions = Substitute.For>(); + var workerOptions = new WorkerOptions + { + DelayPreparacaoPedido = 1, + DelayVerificacaoFila = 1 + }; + + mockOptions.Value.Returns(workerOptions); + + var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService, mockOptions); // Act await workerService.StartAsync(CancellationToken.None); @@ -59,8 +79,15 @@ public async Task ExecuteAsync_ComExcecao_NoCatch_DeveLogarErro() mockFilaPedidoService.RetornarPrimeiroPedidoDaFila().Throws(x => throw new Exception("Simulando erro")); var mockLogger = Substitute.For>(); + var mockOptions = Substitute.For>(); + var workerOptions = new WorkerOptions + { + DelayPreparacaoPedido = 1, + DelayVerificacaoFila = 1 + }; - var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService); + mockOptions.Value.Returns(workerOptions); + var workerService = new FilaPedidosHostedService(mockLogger, mockFilaPedidoService, mockOptions); // Act await workerService.StartAsync(CancellationToken.None); From 7f314df08e913de05a371f1d285c7dc65864aab0 Mon Sep 17 00:00:00 2001 From: vitor Date: Mon, 23 Oct 2023 17:32:21 -0300 Subject: [PATCH 4/4] acrescentando sufixo no worker options para melhor legibildade --- .../FilaPedidosHostedService.cs | 4 ++-- .../Options/WorkerOptions.cs | 4 ++-- .../appsettings.Development.json | 4 ++-- .../appsettings.json | 4 ++-- .../Worker/FilaPedidoWorkerTest.cs | 14 +++++++------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs index 12d2f5fa..1202ec20 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/FilaPedidosHostedService.cs @@ -39,7 +39,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) _logger.LogInformation($"Pedido {proximoPedido.Id} em preparação."); - await Task.Delay(1000 * _workerOptions.DelayPreparacaoPedido, stoppingToken); + await Task.Delay(1000 * _workerOptions.DelayPreparacaoPedidoEmSegundos, stoppingToken); _logger.LogInformation($"Pedido {proximoPedido.Id} preparação finalizada."); @@ -57,7 +57,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) _logger.LogError(ex, "Erro ao processar fila de pedidos."); } - await Task.Delay(_workerOptions.DelayVerificacaoFila * 1000, stoppingToken); + await Task.Delay(_workerOptions.DelayVerificacaoFilaEmSegundos * 1000, stoppingToken); } } } diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs index b1722f7f..5c85c608 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/Options/WorkerOptions.cs @@ -2,7 +2,7 @@ { public class WorkerOptions { - public int DelayPreparacaoPedido { get; set; } - public int DelayVerificacaoFila { get; set; } + public int DelayPreparacaoPedidoEmSegundos { get; set; } + public int DelayVerificacaoFilaEmSegundos { get; set; } } } \ No newline at end of file diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json index 409e4a79..f849cd16 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.Development.json @@ -3,8 +3,8 @@ "DefaultConnection": "Server=127.0.0.1,1433;Database=techlanches;User=sa;Password=Qwert@12345" }, "Worker": { - "DelayPreparacaoPedido": 20, - "DelayVerificacaoFila": 5 + "DelayPreparacaoPedidoEmSegundos": 20, + "DelayVerificacaoFilaEmSegundos": 5 }, "Logging": { "LogLevel": { diff --git a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json index 409e4a79..f849cd16 100644 --- a/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json +++ b/src/TechLanches/Adapter/Driver/TechLanches.Adapter.FilaPedidos/appsettings.json @@ -3,8 +3,8 @@ "DefaultConnection": "Server=127.0.0.1,1433;Database=techlanches;User=sa;Password=Qwert@12345" }, "Worker": { - "DelayPreparacaoPedido": 20, - "DelayVerificacaoFila": 5 + "DelayPreparacaoPedidoEmSegundos": 20, + "DelayVerificacaoFilaEmSegundos": 5 }, "Logging": { "LogLevel": { diff --git a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs index dd64edf2..d09d3b27 100644 --- a/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs +++ b/test/TechLanches.UnitTests/Worker/FilaPedidoWorkerTest.cs @@ -24,8 +24,8 @@ public async Task ExecuteAsync_ComProximoPedido_DeveProcessarPedido() var mockOptions = Substitute.For>(); var workerOptions = new WorkerOptions { - DelayPreparacaoPedido = 1, - DelayVerificacaoFila = 5 + DelayPreparacaoPedidoEmSegundos = 1, + DelayVerificacaoFilaEmSegundos = 5 }; mockOptions.Value.Returns(workerOptions); @@ -34,7 +34,7 @@ public async Task ExecuteAsync_ComProximoPedido_DeveProcessarPedido() // Act await workerService.StartAsync(CancellationToken.None); - await Task.Delay(1000 * (workerOptions.DelayPreparacaoPedido + 1)); // Aguardando um período para permitir que o método ExecuteAsync seja executado + await Task.Delay(1000 * (workerOptions.DelayPreparacaoPedidoEmSegundos + 1)); // Aguardando um período para permitir que o método ExecuteAsync seja executado // Assert await mockFilaPedidoService.Received(1).RetornarPrimeiroPedidoDaFila(); @@ -54,8 +54,8 @@ public async Task ExecuteAsync_SemProximoPedido_NaoDeveProcessar() var mockOptions = Substitute.For>(); var workerOptions = new WorkerOptions { - DelayPreparacaoPedido = 1, - DelayVerificacaoFila = 1 + DelayPreparacaoPedidoEmSegundos = 1, + DelayVerificacaoFilaEmSegundos = 1 }; mockOptions.Value.Returns(workerOptions); @@ -82,8 +82,8 @@ public async Task ExecuteAsync_ComExcecao_NoCatch_DeveLogarErro() var mockOptions = Substitute.For>(); var workerOptions = new WorkerOptions { - DelayPreparacaoPedido = 1, - DelayVerificacaoFila = 1 + DelayPreparacaoPedidoEmSegundos = 1, + DelayVerificacaoFilaEmSegundos = 1 }; mockOptions.Value.Returns(workerOptions);