Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Tests error not showing with Moq #278

Closed
ivanjx opened this issue Jul 21, 2023 · 1 comment
Closed

[BUG] Tests error not showing with Moq #278

ivanjx opened this issue Jul 21, 2023 · 1 comment
Labels
area-test Test discovery, execution, debugging bug Something isn't working fixed-pending-release
Milestone

Comments

@ivanjx
Copy link

ivanjx commented Jul 21, 2023

Describe the Issue

when i use MockBehavior.Strict, vscode is not showing the error details. instead it shows this:

image

note that i am using linux so the path is not even valid.

here is what dotnet test gives me:

[xUnit.net 00:00:00.50]     server.Tests.Services.Registration.RegistrationServiceTest.SendOtpAsync_RateLimit [FAIL]
  Failed server.Tests.Services.Registration.RegistrationServiceTest.SendOtpAsync_RateLimit [39 ms]
  Error Message:
   Moq.MockException : ITimeService.Now invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.
  Stack Trace:
     at Moq.FailForStrictMock.Handle(Invocation invocation, Mock mock) in C:\projects\moq4\src\Moq\Interception\InterceptionAspects.cs:line 182
   at Moq.Mock.Moq.IInterceptor.Intercept(Invocation invocation) in C:\projects\moq4\src\Moq\Interception\Mock.cs:line 27
   at Moq.CastleProxyFactory.Interceptor.Intercept(IInvocation underlying) in C:\projects\moq4\src\Moq\Interception\CastleProxyFactory.cs:line 107
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.ITimeServiceProxy.get_Now()
   at server.Services.Registration.RegistrationService.SendOtpAsync(String email, String username) in /home/user/Documents/projects/server/server/Services/Registration/RegistrationService.cs:line 136
   at server.Tests.Services.Registration.RegistrationServiceTest.SendOtpAsync_RateLimit() in /home/user/Documents/projects/server/server.Tests/Services/Registration/RegistrationServiceTest.cs:line 118
--- End of stack trace from previous location ---

Steps To Reproduce

var service = new Mock<IService>(MockBehavior.Strict);

Expected Behavior

shows the error correctly

Environment Information

  • OS: Ubuntu 23.04
  • v2.0.283
@ivanjx ivanjx added the bug Something isn't working label Jul 21, 2023
@timheuer timheuer added area-test Test discovery, execution, debugging and removed area-project-cps labels Jul 21, 2023
@AbhitejJohn AbhitejJohn added this to the Dec2023 milestone Nov 29, 2023
@peterwald peterwald modified the milestones: Dec2023, Jan2024 Jan 11, 2024
@peterwald
Copy link
Member

The moq.dll that is packaged in the nuget package was built on a windows machine, and includes embedded symbols with file paths that reflect the code on that build machine. Note that your stack trace from the dotnet test command line also shows windows paths. When the test is run, C# Dev Kit finds the location at the top of the error stack and informs the VS Code test explorer the source location where the error was encountered. VS Code tries to open this file location, which if the source is not found locally gives the behavior you've reported.

I have made a change to not report the source location of the error when that source location does not exist locally. This will prevent the VS Code test explorer from trying to open the file locally in that case. This change will ship in the next preview build of C# Dev Kit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-test Test discovery, execution, debugging bug Something isn't working fixed-pending-release
Projects
None yet
Development

No branches or pull requests

4 participants