Repository navigation
test: let the fixture create the containers of a scenario - #71
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No blocking defects were identified; the remaining documentation clarification is minor.
1 open issue
What changed in this PR
Moves scenario container creation into the test fixture, leaving scenarios responsible for seeding data. The library is unchanged.
Changes:
- Creates declared containers before seeding and derives the default partition budget from their count.
- Shares operation-test container definitions across fixtures and scenarios.
- Updates the test-data-seeding guidance.
| File | Description |
|---|---|
| tests/Cosmos.Tests/Scenarios/SingleItemScenario.fs | Seeds through the shared operation fixture. |
| tests/Cosmos.Tests/Scenarios/MultipleItemsScenario.fs | Removes scenario-owned container creation. |
| tests/Cosmos.Tests/OperationTestInfrastructure.fs | Adds the operation fixture and shared container constants. |
| tests/Cosmos.Tests.Infrastructure/IntegrationInfrastructure.fs | Creates declared containers during initialization. |
| .github/skills/test-data-seeding/SKILL.md | Documents fixture-owned containers and updates examples. |
Review effort: Balanced
xperiandri
force-pushed
the
test/scenario-containers
branch
from
October 18, 2026 15:04
1360497 to
7ef914f
Compare
xperiandri
commented
Oct 18, 2026
xperiandri
force-pushed
the
test/scenario-containers
branch
from
October 18, 2026 15:43
7ef914f to
7530868
Compare
xperiandri
commented
Oct 18, 2026
A scenario created its container in SeedDataAsync. The scenarios also repeated the identifier and the partition key path of the container of OperationTestBase. The review of #67 asked why the fixture does not make sure that all containers exist. Add the virtual member Containers to DatabaseTestApplicationFactory. A scenario overrides it to declare its containers. InitializeAsync creates them before SeedDataAsync runs. By default, ContainerCount is the number of declared containers, and at least one. Thus a test that creates its containers itself works as before. Containers is a ContainerSet, a set of container definitions with the identifier as key. It throws when a scenario declares a container twice. CreateContainerIfNotExistsAsync would hide the second declaration. It returns the container that exists already and ignores all of its other settings, except the partition key path. Add OperationTestApplicationFactory, the base class of the scenarios of the operation tests. It declares the container of OperationTestBase and gives it to a scenario as Container. SingleItemScenario and MultipleItemsScenario use it, and OperationTestBase uses its constants. Update the test-data-seeding skill and its examples. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
test/scenario-containers
branch
from
October 18, 2026 16:53
7530868 to
ee020a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Proposed Changes
A scenario created its container itself, in
SeedDataAsync. The review of #67 asked: "whyTestApplicationFactorydo not insures all containers are created? delegate it to a virtual method on it". This pull request moves the creation of the containers into the fixture.DatabaseTestApplicationFactoryhas the new virtual memberContainers, aContainerSet. A scenario overrides it to declare the containers that it writes into.InitializeAsynccreates them beforeSeedDataAsyncruns. By default,ContainerCountis the number of declared containers, and at least one. Thus a test that creates its containers itself works as before.ContainerSetis a set of container definitions with the identifier as key. It throws ArgumentException when a scenario declares a container twice. The reason:CreateContainerIfNotExistsAsyncreturns a container that exists already and ignores all of its other settings, except the partition key path, so a second declaration would be lost without a message (measured with SDK 3.62.0 and 3.63.2). A plainImmutableHashSetwould hide it too, because it keeps the first of two equal items without a message. The unit tests of the set need no emulator.OperationTestApplicationFactoryis the base class of the scenarios of the operation tests. It declares the container ofOperationTestBase(operation-tests) and gives it to a scenario asContainer. A scenario that writes with another serializer gets the container of its own client withGetContainerOf client.SingleItemScenarioandMultipleItemsScenariouse it. They do not create a container and do not repeat its identifier.OperationTestBaseuses the same constants.test-data-seedingskill says how to declare containers. Its two examples compile, and the example test passes on the emulator.The test classes that do not use a scenario are not changed.
ReadExtensionsTestscreates a second container, andQuerySemanticsTests(#44) creates its containers itself. They keep the defaultContainers, which is empty.Types of changes
What types of changes does your code introduce to FSharp.Azure.Cosmos?
Put an
xin the boxes that applyThe change has no effect on the library. It changes only tests and the skill.
Checklist
ContainerSetand the 79 tests of the categories "Create", "Read", "Read many", "Replace", "Upsert", "Patch", "Delete", "Read extensions" and "Iteration extensions" pass on the Windows emulator.Further comments
The scenarios are the tests of the new member: a scenario can write to its container only if
InitializeAsynccreated it.#67 builds on this pull request. Its scenario
DurationsScenariousesOperationTestApplicationFactory.🤖 Generated with Claude Code