question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocking context-Procedures

See original GitHub issue

We have setup database-first with exports for Stored Procedures. This creates an export class that contains an method Procedures in our partial context.

Currently we’re trying to mock a Stored Procedure in our unit tests, but we’re failing because the Procedures property is neither part of an interface, nor is the property marked as virtual.

We would like to propose one line of code change in the generation of the Procedures property here: https://github.com/ErikEJ/EFCorePowerTools/blob/f35ad68c31cc2a1c1dd5fdd38c08c9a6bd6966a0/src/GUI/RevEng.Core/Procedures/SqlServerStoredProcedureScaffolder.cs#L96

-                    _sb.AppendLine($"public {procedureScaffolderOptions.ContextName}Procedures Procedures");
+                    _sb.AppendLine($"public virtual {procedureScaffolderOptions.ContextName}Procedures Procedures");

Just like all DbSets are virtual, this property needs to be virtual too.

Surprisingly the generated methods in the context-procedures class are all virtual.

We also tried to work-around this issue with Handlebars, but it looks like there are no templates available for Stored Procedures. Separate issue?!

Steps to reproduce

  • Database-first
  • Enable and export Stored Procedures
  • Try to mock (Moq) an Stored Procedure

Further technical details

EF Core Power Tools version: 2.5.758.

Database engine: SQL Server.

Visual Studio version: Visual Studio Professional 2019 16.11.3.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jeronecommented, Jul 7, 2022

Finally had time to officially test the extension (version 2.5.1041) and the interface changes are working great 👍

1reaction
ErikEJcommented, May 30, 2022

fixed in latest daily build

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mock and unit test Stored Procedures in EF
I am using a generic repository pattern Repository<TEntity> where repositories access the entities through a context. Then I have a service ...
Read more >
Mocking Context with React Testing Library
There is no need to mock your contexts in order to test them. jest.mock and friends are extremely helpful for many test scenarios,...
Read more >
Testing with a mocking framework - EF6
The following test uses Moq to create a context. It then creates a DbSet<Blog> and wires it up to be returned from the...
Read more >
How to Mock EF Core DbContext
This library will help us to mock EF Core contexts and we can test methods that are using the DbContext , DbSet ,...
Read more >
Mocking React Context in Consumer Component
I just mocked the contexts my component dependent on using jest.spyOn. With this, I don't have to import the contexts one by one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found