Skip to content

Conversation

@lazaro-ansaldi
Copy link

@lazaro-ansaldi lazaro-ansaldi commented Sep 19, 2024

PR Details

Add Support for ExecuteDelete, ExecuteUpdate, ExecuteDeleteAsync, and ExecuteUpdateAsync in MockQueryable Library

Description

This PR introduces support for mocking the ExecuteDelete, ExecuteUpdate, ExecuteDeleteAsync, and ExecuteUpdateAsync methods in the MockQueryable library. These methods allow for both synchronous and asynchronous deletion and updating of entities using expressions, now fully integrated into the mocking process for EF Core's IQueryable-based testing.

Changes include:

  • Adding functionality to mock ExecuteDelete and ExecuteDeleteAsync, returning the number of rows affected based on the provided predicate.
  • Adding functionality to mock ExecuteUpdate and ExecuteUpdateAsync, which apply the provided update expression and return the number of rows that would be affected.

Related Issue

This PR addresses the need to support EF Core 7’s new ExecuteDelete/ExecuteDeleteAsync and ExecuteUpdate/ExecuteUpdateAsync methods in unit tests, enabling developers to simulate bulk delete and update operations without direct access to the database.

Related Issue: #66

How Has This Been Tested

  • Added unit tests covering ExecuteDelete/ExecuteDeleteAsync and ExecuteUpdate/ExecuteUpdateAsync mock scenarios.
  • Tested using expressions that target specific rows based on Where filters.
  • Verified that both methods (sync and async) correctly return the count of affected rows in different scenarios.
  • Ensured all new unit tests passed and that existing tests remained unaffected.

Checklist

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@romantitov romantitov changed the base branch from master to feature/ExecuteAsync September 20, 2024 14:34
@romantitov romantitov self-assigned this Sep 20, 2024
@romantitov
Copy link
Owner

Hello @lazaro-ansaldi thanks for your effort. I will merge the PR to a temporary branch, but I will need some time to move these changes into the master and create a new release. Thanks for understanding.

@romantitov romantitov merged commit 534d79f into romantitov:feature/ExecuteAsync Sep 20, 2024
@lazaro-ansaldi
Copy link
Author

Hi @romantitov ,

Thank you for the prompt response!

I fully understand the workflow of this feature. If any test code adjustments are needed, I’d be happy to help. Additionally, please feel free to reach out if you'd like me to perform any validations against a beta version.

Thanks again!

Best regards,
Lazaro

@icnocop
Copy link

icnocop commented Sep 24, 2024

Hi.

Thank you @romantitov for MockQueryable.

Thank you @lazaro-ansaldi for this PR.

When running the new unit test DbSetCreatedFromCollectionExecuteUpdateAsync, I expected the user's first name to be updated to Unit Test as a result of the call to .ExecuteUpdateAsync(opt => opt.SetProperty(x => x.FirstName, firstName)), but that isn't happening.

image

Is my assumption correct?

Thank you.

@lazaro-ansaldi
Copy link
Author

Hi @icnocop,

Thank you for testing the change and providing your valuable feedback!

To simplify the scope of this update, the mock for ExecuteUpdate and ExecuteDelete will now only return the number of affected rows based on the query, without actually performing the data modifications. While this isn’t the ideal behavior for a mock, it helps avoid a breaking change, which is our current priority.

If you'd like, feel free to extend this functionality to support actual updates and deletions within the mocked collection. I’d be happy to assist if you need any help along the way.

Thanks again!

@techtoniq
Copy link

I'd be interested in the updated ExecuteUpdate and ExecuteDelete too.

@lazaro-ansaldi
Copy link
Author

Hi @romantitov,
Are there any outstanding issues that need to be resolved before we proceed? Or are we good to move forward with generating the new version?

Thanks!

@DPIDNB
Copy link

DPIDNB commented Jan 17, 2025

Hello, @romantitov, @lazaro-ansaldi, any updates on when this will be released? My team and I are also waiting on this feature :)

@SerhiyBalan
Copy link

Works perfectly. Looking forward to seeing a non-beta version with these awesome changes!

Thank you @lazaro-ansaldi !

renebentes pushed a commit to renebentes/3054 that referenced this pull request Aug 5, 2025
Updated
[MockQueryable.NSubstitute](https://github.com/romantitov/MockQueryable)
from 7.0.3 to 8.0.0.

<details>
<summary>Release notes</summary>

_Sourced from [MockQueryable.NSubstitute's
releases](https://github.com/romantitov/MockQueryable/releases)._

## 8.0.0


## What's Changed
#​81 Add support to ExecuteDelete and ExecuteUpdate - Thanks
@​lazaro-ansaldi and @​Catlandor
#​82 Update versions of Moq, NSubstitute and FakeItEasy to newer
versions without known vulnerabilities - Thanks @​Catlandor
#​73 Supporting EF.Functions.Like and/or prossibility to provide cusotm
ExpressionVisitor - Thanks @​Catlandor
#​66 Not suported with EF7: ExecuteDeleteAsync and ExecuteUpdateAsync -
Thanks @​Catlandor

## New Contributors
* @​lazaro-ansaldi made their first contribution in
romantitov/MockQueryable#81
* @​Catlandor made their first contribution in
romantitov/MockQueryable#84

**Full Changelog**:
romantitov/MockQueryable@v7.0.3...v8.0.0

## 7.0.4-beta

## What's Changed
* Altered namespace for extension method to revert a breaking change wi…
by @​StevePy in romantitov/MockQueryable#80

## New Contributors
* @​StevePy made their first contribution in
romantitov/MockQueryable#80

**Full Changelog**:
romantitov/MockQueryable@v7.0.2...7.0.4-beta

Commits viewable in [compare
view](romantitov/MockQueryable@v7.0.3...v8.0.0).
</details>

Updated [Roslynator.Analyzers](https://github.com/dotnet/roslynator)
from 4.13.1 to 4.14.0.

<details>
<summary>Release notes</summary>

_Sourced from [Roslynator.Analyzers's
releases](https://github.com/dotnet/roslynator/releases)._

## 4.14.0

### Added

- [CLI] Add support for GitLab analyzer reports
([PR](dotnet/roslynator#1633))

### Fixed

- Fix analyzer
[RCS1264](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1264)
([PR](dotnet/roslynator#1666))
- Fix analyzer
[RCS1229](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1229)
([PR](dotnet/roslynator#1667))
- Fix analyzer
[RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250)
([PR](dotnet/roslynator#1652) by @​aihnatiuk)
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
([PR](dotnet/roslynator#1668))
- Fix analyzer
[RCS1105](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1105)
([PR](dotnet/roslynator#1669))
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
([PR](dotnet/roslynator#1672))

### Changed

- Disable analyzer
[RCS1036](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1036)
by default ([PR](dotnet/roslynator#1671))
- Use analyzer
[RCS0063](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0063)
instead

### Removed

- Remove legacy config options
([PR](dotnet/roslynator#1304))


Commits viewable in [compare
view](dotnet/roslynator@v4.13.1...v4.14.0).
</details>

Updated
[Roslynator.CodeAnalysis.Analyzers](https://github.com/dotnet/roslynator)
from 4.13.1 to 4.14.0.

<details>
<summary>Release notes</summary>

_Sourced from [Roslynator.CodeAnalysis.Analyzers's
releases](https://github.com/dotnet/roslynator/releases)._

## 4.14.0

### Added

- [CLI] Add support for GitLab analyzer reports
([PR](dotnet/roslynator#1633))

### Fixed

- Fix analyzer
[RCS1264](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1264)
([PR](dotnet/roslynator#1666))
- Fix analyzer
[RCS1229](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1229)
([PR](dotnet/roslynator#1667))
- Fix analyzer
[RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250)
([PR](dotnet/roslynator#1652) by @​aihnatiuk)
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
([PR](dotnet/roslynator#1668))
- Fix analyzer
[RCS1105](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1105)
([PR](dotnet/roslynator#1669))
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
([PR](dotnet/roslynator#1672))

### Changed

- Disable analyzer
[RCS1036](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1036)
by default ([PR](dotnet/roslynator#1671))
- Use analyzer
[RCS0063](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0063)
instead

### Removed

- Remove legacy config options
([PR](dotnet/roslynator#1304))


Commits viewable in [compare
view](dotnet/roslynator@v4.13.1...v4.14.0).
</details>

Updated
[Roslynator.Formatting.Analyzers](https://github.com/dotnet/roslynator)
from 4.13.1 to 4.14.0.

<details>
<summary>Release notes</summary>

_Sourced from [Roslynator.Formatting.Analyzers's
releases](https://github.com/dotnet/roslynator/releases)._

## 4.14.0

### Added

- [CLI] Add support for GitLab analyzer reports
([PR](dotnet/roslynator#1633))

### Fixed

- Fix analyzer
[RCS1264](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1264)
([PR](dotnet/roslynator#1666))
- Fix analyzer
[RCS1229](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1229)
([PR](dotnet/roslynator#1667))
- Fix analyzer
[RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250)
([PR](dotnet/roslynator#1652) by @​aihnatiuk)
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
([PR](dotnet/roslynator#1668))
- Fix analyzer
[RCS1105](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1105)
([PR](dotnet/roslynator#1669))
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
([PR](dotnet/roslynator#1672))

### Changed

- Disable analyzer
[RCS1036](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1036)
by default ([PR](dotnet/roslynator#1671))
- Use analyzer
[RCS0063](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0063)
instead

### Removed

- Remove legacy config options
([PR](dotnet/roslynator#1304))


Commits viewable in [compare
view](dotnet/roslynator@v4.13.1...v4.14.0).
</details>

Updated
[xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit)
from 3.1.2 to 3.1.3.

<details>
<summary>Release notes</summary>

_Sourced from [xunit.runner.visualstudio's
releases](https://github.com/xunit/visualstudio.xunit/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/xunit/visualstudio.xunit/commits).
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants