Skip to content

feat: add FakeXrmEasy mocked tests for BulkOperationExecutor (Phase 3)#97

Merged
joshsmithxrm merged 4 commits intomainfrom
feature/integration-tests-phase3
Jan 2, 2026
Merged

feat: add FakeXrmEasy mocked tests for BulkOperationExecutor (Phase 3)#97
joshsmithxrm merged 4 commits intomainfrom
feature/integration-tests-phase3

Conversation

@joshsmithxrm
Copy link
Copy Markdown
Owner

Summary

  • Add comprehensive FakeXrmEasy-based integration tests for BulkOperationExecutor
  • Implement custom message executors for CreateMultiple, UpdateMultiple, UpsertMultiple, and DeleteMultiple
  • Add ElasticTable mode coverage (Microsoft's Cosmos DB-backed high-throughput tables)
  • Add partial success and error handling tests

Test Coverage Added (105 tests)

Test Class Tests Coverage
CreateMultipleTests 12 Create operations, batching, progress
UpdateMultipleTests 11 Update operations, persistence verification
UpsertMultipleTests 10 Upsert existing records, attribute preservation
DeleteMultipleTests 5 Delete operations with standard tables
BatchingBehaviorTests 14 Batch size, parallel batches, cancellation
ElasticTableTests 24 All CRUD ops with ElasticTable=true
PartialSuccessTests 7 Error handling, failure simulation
DataverseClientCrudTests 22 Basic CRUD via DataverseClient

Implementation Details

  • FakeXrmEasy v9 3.8.0: In-memory Dataverse mock
  • Custom Message Executors: Handle bulk operation messages not natively supported
  • DeleteMultiple: Implemented as unbound message (not typed SDK class)
  • Failure Simulation: Static predicates for testing error scenarios

Part of Issue #55 - Integration Testing Infrastructure

🤖 Generated with Claude Code

joshsmithxrm and others added 2 commits January 2, 2026 14:14
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>
Copilot AI review requested due to automatic review settings January 2, 2026 20:42
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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 BulkOperationExecutor by leveraging FakeXrmEasy. The primary goal is to ensure the reliability and correctness of bulk Dataverse operations under various conditions, including specific behaviors related to ElasticTable mode and scenarios involving partial successes or failures. The changes introduce custom message executors to accurately mock Dataverse responses, providing a robust and isolated testing environment for critical bulk processing logic.

Highlights

  • Integration Test Coverage: Added comprehensive FakeXrmEasy-based integration tests for the BulkOperationExecutor, covering CreateMultiple, UpdateMultiple, UpsertMultiple, and DeleteMultiple operations.
  • Custom Message Executors: Implemented custom FakeXrmEasy message executors to accurately simulate the behavior of CreateMultiple, UpdateMultiple, UpsertMultiple, and DeleteMultiple requests, which are not natively supported by FakeXrmEasy.
  • ElasticTable Mode Testing: Introduced specific test coverage for bulk operations when ElasticTable mode is enabled, addressing the distinct APIs and partial success behaviors of Cosmos DB-backed high-throughput tables.
  • Partial Success and Error Handling: Included tests for partial success scenarios and robust error handling, verifying how the BulkOperationExecutor manages failures within batches and collects error details.
  • Testing Infrastructure: This pull request completes Phase 3 of the integration testing infrastructure, building upon previous work to establish a solid testing foundation.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +158 to +165
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

This foreach loop immediately
maps its iteration variable to another variable
- consider mapping the sequence explicitly using '.Select(...)'.

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) with foreach (var query in idsToDelete.Select(id => new QueryExpression(EntityName) { ... })).
  • Move the initialization of query into the Select lambda.
  • Inside the loop body, remove the separate var query = ... statement and keep only the assertion using the query iteration variable.
  • No new imports are required; System.Linq is typically already available in test projects, but since we cannot alter unseen imports, we rely on it already being present (which is common when ToList, Take, and Skip are 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.

Suggested changeset 1
tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs b/tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs
--- a/tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs
+++ b/tests/PPDS.Dataverse.IntegrationTests/BulkOperations/ElasticTableTests.cs
@@ -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();
         }
 
EOF
@@ -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();
}

Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining - Same as above, foreach is clearer for verification tests.

- 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>
@joshsmithxrm joshsmithxrm merged commit 96f693d into main Jan 2, 2026
8 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in PPDS Roadmap Jan 2, 2026
@joshsmithxrm joshsmithxrm deleted the feature/integration-tests-phase3 branch January 3, 2026 18:03
joshsmithxrm added a commit that referenced this pull request Jan 8, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants