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

Add support to ExecuteDelete and ExecuteUpdate #81

Merged
merged 1 commit into from
Sep 20, 2024

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
1 check passed
@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.

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.

4 participants