Parece ser o mesmo problema do tópico anterior "Execução do teste com Visual Studio for Mac não passa no Verify" que o William reportou.
No entanto, também baixei a solução final do capítulo na Alura (zip) e atualizei o csproj com as seguintes bibliotecas na versão que estou:
De netcoreapp2.1 Para netcoreapp3.1De Microsoft.EntityFrameworkCore.InMemory Version2.2.6 Para 3.1.8De Microsoft.NET.Test.Sdk Version=15.9.0 Para 16.5.0De Moq Version=4.12.0 Para 4.14.6
Ou seja, com o projeto na versão atual não está passando o Verify.
Versão do meu Visual Studio e do .NET Framework: Microsoft Visual Studio Community 2019 Version 16.7.5 Microsoft .NET Framework Version 4.8.03752
Alura.CoisasAFazer.Tests.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.14.6" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Alura.CoisasAFazer.Core\Alura.CoisasAFazer.Core.csproj" />
<ProjectReference Include="..\..\src\Alura.CoisasAFazer.Services\Alura.CoisasAFazer.Services.csproj" />
</ItemGroup>
</Project>
Erro:
Alura.CoisasAFazer.Tests.CadastraTarefaHandlerExecute.QuandoExceptionForLancadaDeveLogarAMensagemDaExcecao
Source: CadastraTarefaHandlerExecute.cs line 72
Duration: 169 ms
Message:
Moq.MockException :
Expected invocation on the mock once, but was 0 times: l => l.Log<object>(LogLevel.Error, It.IsAny<EventId>(), It.IsAny<object>(), System.Exception: Houve um erro na inclusão de tarefas
at Moq.Behaviors.ThrowException.Execute(Invocation invocation)
at Moq.MethodCall.ExecuteCore(Invocation invocation)
at Moq.Setup.Execute(Invocation invocation)
at Moq.FindAndExecuteMatchingSetup.Handle(Invocation invocation, Mock mock)
at Moq.Mock.Moq.IInterceptor.Intercept(Invocation invocation)
at Moq.CastleProxyFactory.Interceptor.Intercept(IInvocation underlying)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IRepositorioTarefasProxy.IncluirTarefas(Tarefa[] tarefas)
at Alura.CoisasAFazer.Services.Handlers.CadastraTarefaHandler.Execute(CadastraTarefa comando) in C:\Users\afmor\Documents\Alexandre\Treinamento\Alura - Mocks\testes-integracao.projeto-inicial\testes-integracao\src\Alura.CoisasAFazer.Services\Handlers\CadastraTarefaHandler.cs:line 34, It.IsAny<Func<object, Exception, string>>())
Performed invocations:
Mock<ILogger<CadastraTarefaHandler>:1> (l):
ILogger.Log<FormattedLogValues>(LogLevel.Debug, 0, Persistindo a tarefa Estudar xUnit, null, Func<FormattedLogValues, Exception, string>)
ILogger.Log<FormattedLogValues>(LogLevel.Error, 0, Houve um erro na inclusão de tarefas, System.Exception: Houve um erro na inclusão de tarefas
at Moq.Behaviors.ThrowException.Execute(Invocation invocation)
at Moq.MethodCall.ExecuteCore(Invocation invocation)
at Moq.Setup.Execute(Invocation invocation)
at Moq.FindAndExecuteMatchingSetup.Handle(Invocation invocation, Mock mock)
at Moq.Mock.Moq.IInterceptor.Intercept(Invocation invocation)
at Moq.CastleProxyFactory.Interceptor.Intercept(IInvocation underlying)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IRepositorioTarefasProxy.IncluirTarefas(Tarefa[] tarefas)
at Alura.CoisasAFazer.Services.Handlers.CadastraTarefaHandler.Execute(CadastraTarefa comando) in C:\Users\afmor\Documents\Alexandre\Treinamento\Alura - Mocks\testes-integracao.projeto-inicial\testes-integracao\src\Alura.CoisasAFazer.Services\Handlers\CadastraTarefaHandler.cs:line 34, Func<FormattedLogValues, Exception, string>)
Stack Trace:
Mock.Verify(Mock mock, LambdaExpression expression, Times times, String failMessage)
Mock`1.Verify(Expression`1 expression, Times times)
CadastraTarefaHandlerExecute.QuandoExceptionForLancadaDeveLogarAMensagemDaExcecao() line 136