feat: add FakeXrmEasy mocked tests for BulkOperationExecutor (Phase 3)#97
feat: add FakeXrmEasy mocked tests for BulkOperationExecutor (Phase 3)#97joshsmithxrm merged 4 commits intomainfrom
Conversation
Add comprehensive FakeXrmEasy-based integration tests for bulk operations: ## Infrastructure - FakePooledClient: Wraps IOrganizationService for IPooledClient interface - FakeConnectionPool: Mock connection pool returning FakePooledClient - FakeThrottleTracker: Mock throttle tracker for testing - Custom message executors for CreateMultiple, UpdateMultiple, UpsertMultiple ## Tests Added - CreateMultipleTests (10 tests): Basic batch, progress, attributes, batching - UpdateMultipleTests (10 tests): Single/multiple entities, persistence, progress - UpsertMultipleTests (9 tests): Existing entities, persistence, batching - DeleteMultipleTests (5 tests): Empty collection, progress, options - BatchingBehaviorTests (14 tests): Batch size verification, progress tracking - DataverseClientCrudTests (28 tests): CRUD operations, FetchXML, QueryExpression ## Notes - FakeXrmEasy has limitations with upsert on new entities (requires metadata) - Standard delete uses ExecuteMultiple which has limited FakeXrmEasy support - Tests designed to work within FakeXrmEasy constraints Total: 76 new tests across 6 test classes Issue: #55 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extends Phase 3 FakeXrmEasy integration tests with ElasticTable coverage: ## New Tests (29 additional) ### ElasticTableTests.cs (24 tests) - DeleteMultiple with ElasticTable mode: single/multiple/large batches - CreateMultiple with ElasticTable mode: batching, progress reporting - UpdateMultiple with ElasticTable mode: persistence, batching - UpsertMultiple with ElasticTable mode: updates, batching - ContinueOnError behavior verification - Bypass options (CustomLogic, PowerAutomate, Tag) with ElasticTable ### PartialSuccessTests.cs (5 tests) - Delete with non-existent records (standard tables) - Delete with simulated failures (elastic tables) - Update with non-existent records - Error details collection verification - Batch failure isolation ## Infrastructure - DeleteMultipleRequestExecutor: Handles unbound DeleteMultiple message - FailurePredicate support for simulating per-record failures ## Notes - ElasticTable mode uses native DeleteMultiple API (not ExecuteMultiple) - Per-record partial success response parsing requires live Dataverse - Tests verify the code paths are exercised correctly Total integration tests: 105 (was 76) Issue: #55 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @joshsmithxrm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the integration test suite for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a comprehensive suite of integration tests for the BulkOperationExecutor using FakeXrmEasy. The coverage is extensive, including tests for create, update, upsert, and delete operations, as well as batching behavior, elastic table scenarios, and partial success handling. The use of custom message executors and mock objects for dependencies like the connection pool is well-executed. My feedback focuses on making some tests more robust by strengthening assertions, improving test isolation with [ThreadStatic], clarifying test names, and addressing a dependency version. Overall, this is an excellent contribution that significantly improves the project's test infrastructure and reliability.
tests/PPDS.Dataverse.IntegrationTests/FakeMessageExecutors/DeleteMultipleRequestExecutor.cs
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/CreateMultipleTests.cs
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/PartialSuccessTests.cs
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/Client/DataverseClientCrudTests.cs
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/Client/DataverseClientCrudTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/PPDS.Dataverse.IntegrationTests.csproj
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive FakeXrmEasy-based integration tests for the BulkOperationExecutor component as Phase 3 of the integration testing infrastructure initiative. The implementation includes custom message executors to mock Dataverse bulk operation APIs (CreateMultiple, UpdateMultiple, UpsertMultiple, DeleteMultiple) and provides extensive test coverage across standard and Elastic Table scenarios.
Key Changes:
- Custom message executors enabling FakeXrmEasy to handle bulk operations not natively supported
- Mock implementations for connection pooling and throttle tracking test infrastructure
- 105 tests covering CRUD operations, batching behavior, ElasticTable mode, and partial success scenarios
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| PPDS.Dataverse.IntegrationTests.csproj | Adds Moq and Microsoft.Extensions.Logging.Abstractions package dependencies |
| Mocks/FakeThrottleTracker.cs | Implements fake throttle tracker for testing throttling scenarios |
| Mocks/FakePooledClient.cs | Wraps FakeXrmEasy IOrganizationService to implement IPooledClient interface |
| Mocks/FakeConnectionPool.cs | Provides fake connection pool returning FakePooledClient instances |
| FakeXrmEasyTestsBase.cs | Registers custom bulk operation message executors in FakeXrmEasy middleware |
| FakeMessageExecutors/CreateMultipleRequestExecutor.cs | Implements CreateMultiple message handling for FakeXrmEasy |
| FakeMessageExecutors/UpdateMultipleRequestExecutor.cs | Implements UpdateMultiple message handling for FakeXrmEasy |
| FakeMessageExecutors/UpsertMultipleRequestExecutor.cs | Implements UpsertMultiple message handling for FakeXrmEasy |
| FakeMessageExecutors/DeleteMultipleRequestExecutor.cs | Implements unbound DeleteMultiple message with configurable failure simulation |
| BulkOperations/BulkOperationExecutorTestsBase.cs | Provides base class with configured BulkOperationExecutor and test helpers |
| BulkOperations/CreateMultipleTests.cs | Tests for CreateMultipleAsync operations (12 tests) |
| BulkOperations/UpdateMultipleTests.cs | Tests for UpdateMultipleAsync operations (11 tests) |
| BulkOperations/UpsertMultipleTests.cs | Tests for UpsertMultipleAsync operations (10 tests) |
| BulkOperations/DeleteMultipleTests.cs | Tests for DeleteMultipleAsync with standard tables (5 tests) |
| BulkOperations/BatchingBehaviorTests.cs | Tests batch size handling and progress reporting (14 tests) |
| BulkOperations/ElasticTableTests.cs | Tests all CRUD operations with ElasticTable mode enabled (24 tests) |
| BulkOperations/PartialSuccessTests.cs | Tests error handling and failure scenarios (7 tests) |
| Client/DataverseClientCrudTests.cs | Tests basic CRUD operations via FakePooledClient wrapper (22 tests) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/PartialSuccessTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/Client/DataverseClientCrudTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/PartialSuccessTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/Mocks/FakeConnectionPool.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/FakeMessageExecutors/DeleteMultipleRequestExecutor.cs
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/FakeMessageExecutors/UpsertMultipleRequestExecutor.cs
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/CreateMultipleTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/DeleteMultipleTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/UpdateMultipleTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/UpsertMultipleTests.cs
Outdated
Show resolved
Hide resolved
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/CreateMultipleTests.cs
Fixed
Show fixed
Hide fixed
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/DeleteMultipleTests.cs
Fixed
Show fixed
Hide fixed
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/UpdateMultipleTests.cs
Fixed
Show fixed
Hide fixed
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/UpsertMultipleTests.cs
Fixed
Show fixed
Hide fixed
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs
Dismissed
Show dismissed
Hide dismissed
| foreach (var id in idsToDelete) | ||
| { | ||
| var query = new QueryExpression(EntityName) | ||
| { | ||
| Criteria = { Conditions = { new ConditionExpression(EntityName + "id", ConditionOperator.Equal, id) } } | ||
| }; | ||
| Service.RetrieveMultiple(query).Entities.Should().BeEmpty(); | ||
| } |
Check notice
Code scanning / CodeQL
Missed opportunity to use Select Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
In general, to address this kind of issue you extract the transformation that happens at the top of the loop into a LINQ Select projection, so you iterate directly over the transformed sequence instead of over the original sequence plus a per-iteration mapping. You still keep any assertions or side effects, but they now operate on the transformed elements.
For this specific case in tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs, the loop currently iterates over idsToDelete, builds a QueryExpression from each id, and immediately uses it. We can refactor by projecting idsToDelete into QueryExpression instances via .Select, and then iterate over those queries. Since everything after var query = ... uses only the query variable, the refactor does not change the test’s semantics. Concretely:
- Replace the loop header
foreach (var id in idsToDelete)withforeach (var query in idsToDelete.Select(id => new QueryExpression(EntityName) { ... })). - Move the initialization of
queryinto theSelectlambda. - Inside the loop body, remove the separate
var query = ...statement and keep only the assertion using thequeryiteration variable. - No new imports are required;
System.Linqis typically already available in test projects, but since we cannot alter unseen imports, we rely on it already being present (which is common whenToList,Take, andSkipare used elsewhere, as shown in the snippet).
This preserves existing functionality: the same queries are executed in the same order, and the same assertions run, while making the mapping from IDs to queries explicit via Select.
| @@ -155,12 +155,11 @@ | ||
| await Executor.DeleteMultipleAsync(EntityName, idsToDelete, options); | ||
|
|
||
| // Assert - Deleted records should be gone | ||
| foreach (var id in idsToDelete) | ||
| foreach (var query in idsToDelete.Select(id => new QueryExpression(EntityName) | ||
| { | ||
| var query = new QueryExpression(EntityName) | ||
| { | ||
| Criteria = { Conditions = { new ConditionExpression(EntityName + "id", ConditionOperator.Equal, id) } } | ||
| }; | ||
| Criteria = { Conditions = { new ConditionExpression(EntityName + "id", ConditionOperator.Equal, id) } } | ||
| })) | ||
| { | ||
| Service.RetrieveMultiple(query).Entities.Should().BeEmpty(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Declining - Same as above, foreach is clearer for verification tests.
tests/PPDS.Dataverse.IntegrationTests/FakeMessageExecutors/CreateMultipleRequestExecutor.cs
Dismissed
Show dismissed
Hide dismissed
tests/PPDS.Dataverse.IntegrationTests/FakeMessageExecutors/UpsertMultipleRequestExecutor.cs
Dismissed
Show dismissed
Hide dismissed
- Add [Collection] attribute to PartialSuccessTests for test isolation - Fix Dispose shadowing (new -> override) - Rename misleading test name (ContinueOnErrorFalse -> WithDefaultOptions) - Remove duplicate upsert test - Fix nullable annotation in FakeConnectionPool - Add using to CancellationTokenSource in 4 test files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Bot Usernames section with exact user.login values - Note that CodeQL comes through github-advanced-security[bot] - Highlight that CodeQL and Copilot often report duplicate findings - Add "Use .Select()" to common false positives 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add settings.json, /fix-tests command, streamline configuration - Add settings.json with team permissions - Add /fix-tests command for iterative test fixing - Add specific gh api permission for PR comment replies - Remove overly broad gh api:* permission from ask - Delete settings.local.example.json and settings.local.json (no longer needed) Based on Boris Cherny's recommendations for Claude Code configuration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add FUNDING.yml and remove deprecated symlink hooks - Add GitHub sponsorship configuration - Remove .githooks/post-checkout (symlink creation no longer needed) - Remove .githooks/README.md (symlink documentation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Test Coverage Added (105 tests)
Implementation Details
Part of Issue #55 - Integration Testing Infrastructure
🤖 Generated with Claude Code