Skip to content

Add xUnit tests for async DISM API methods#3

Closed
Copilot wants to merge 3 commits intocopilot/add-async-await-support-dism-operationsfrom
copilot/add-xunit-tests-for-async-dism-methods
Closed

Add xUnit tests for async DISM API methods#3
Copilot wants to merge 3 commits intocopilot/add-async-await-support-dism-operationsfrom
copilot/add-xunit-tests-for-async-dism-methods

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 30, 2026

Adds test coverage for all 17 async DISM API methods introduced in this branch. 51 test methods across 12 test files, plus a shared helper.

Test structure

Each async method gets three tests:

  • Happy path / error propagation — methods that can succeed with an online session (e.g. CheckImageHealthAsync, RestoreImageHealthAsync, MountImageAsync) assert successful completion; methods requiring unavailable resources (packages, features, editions) assert DismException propagation through the async wrapper
  • Cancellation — uses CancellationTokenSource(TimeSpan.FromMilliseconds(100)) to verify the CancellationToken is wired through to the native DISM call
  • Progress reporting — passes IProgress<DismProgress> to verify the parameter is accepted and callbacks fire for long-running operations

Files added

File Methods covered
CheckImageHealthAsyncTest.cs CheckImageHealthAsync
AddPackageAsyncTest.cs AddPackageAsync
AddCapabilityAsyncTest.cs AddCapabilityAsync
CommitImageAsyncTest.cs CommitImageAsync
DisableFeatureAsyncTest.cs DisableFeatureAsync
EnableFeatureAsyncTest.cs EnableFeatureAsync, EnableFeatureByPackageNameAsync, EnableFeatureByPackagePathAsync
MountImageAsyncTest.cs MountImageAsync (by index + by name)
RemoveCapabilityAsyncTest.cs RemoveCapabilityAsync
RemovePackageAsyncTest.cs RemovePackageByNameAsync, RemovePackageByPathAsync
RestoreImageHealthAsyncTest.cs RestoreImageHealthAsync
SetEditionAsyncTest.cs SetEditionAsync, SetEditionAndProductKeyAsync
UnmountImageAsyncTest.cs UnmountImageAsync
SynchronousProgress.cs Shared IProgress<T> helper that invokes callbacks synchronously (avoids Progress<T>'s SynchronizationContext posting)

Conventions

  • Inherits DismTestBase / DismInstallWimTestBase per existing patterns
  • Uses Shouldly assertions, [Fact] attributes
  • Compliant with xUnit v3 TestContext.Current.CancellationToken requirement (xUnit1051)
  • CommitImageAsyncTest uses DismInstallWimTestBase for a mounted offline session; MountImageAsyncTest / UnmountImageAsyncTest handle mount cleanup in Dispose()
// Example: CheckImageHealthAsync cancellation test
[Fact]
public async Task CheckImageHealthAsync_WithCancelledToken_ThrowsOperationCanceledException()
{
    using DismSession session = DismApi.OpenOnlineSession();
    using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));

    await Should.ThrowAsync<OperationCanceledException>(
        () => DismApi.CheckImageHealthAsync(session, scanImage: true, cancellationToken: cts.Token));
}
Original prompt

Pull Request: #2

Extend this existing PR by adding unit test do not open another PR

Task: Add xUnit tests for the new async DISM API methods

The branch copilot/add-async-await-support-dism-operations in Rolling2405/ManagedDism already has 17 new async methods added to src/Microsoft.Dism/. Your job is to add tests for them.

Test project details

  • Location: src/Microsoft.Dism.Tests/
  • Framework: xUnit
  • Base classes: DismTestBase (in DismTestBase.cs) and TestBase (in TestBase.cs)
  • The tests are integration tests using a real install.wim file included in the project
  • Existing examples to follow: CheckImageHealthTest.cs, DismInitializeTest.cs, DismSessionTest.cs

Naming conventions

  • File: AddPackageAsyncTest.cs, MountImageAsyncTest.cs, etc.
  • Class: matches file name
  • Methods: [Fact] attributed, descriptive names like AddPackageAsync_CompletesSuccessfully()

What to test for each async method (minimum coverage)

  1. Happy path — the async method returns a completed Task without throwing
  2. Cancellation — passing an already-cancelled CancellationToken throws OperationCanceledException or TaskCanceledException
  3. Progress reporting — when an IProgress<DismProgress> is provided, Report() is called at least once

Async methods to cover (all in src/Microsoft.Dism/)

  • AddPackageAsync (DismApi.AddPackage.cs)
  • AddCapabilityAsync (DismApi.AddCapability.cs)
  • CheckImageHealthAsync (DismApi.CheckImageHealth.cs) — returns Task<DismImageHealthState>
  • CommitImageAsync (DismApi.CommitImage.cs)
  • DisableFeatureAsync (DismApi.DisableFeature.cs)
  • EnableFeatureAsync, EnableFeatureByPackageNameAsync, EnableFeatureByPackagePathAsync (DismApi.EnableFeature.cs)
  • MountImageAsync x2 overloads (DismApi.MountImage.cs)
  • RemoveCapabilityAsync (DismApi.RemoveCapability.cs)
  • RemovePackageByNameAsync, RemovePackageByPathAsync (DismApi.RemovePackage.cs)
  • RestoreImageHealthAsync (DismApi.RestoreImageHealth.cs)
  • SetEditionAsync, SetEditionAndProductKeyAsync (DismApi.SetEdition.cs)
  • UnmountImageAsync (DismApi.UnmountImage.cs)

After adding tests

Run: dotnet test src/Microsoft.Dism.Tests/Microsoft.Dism.Tests.csproj
Verify tests build and pass. Do NOT mark the PR as ready for review.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@Rolling2405
Copy link
Copy Markdown
Owner

Once you’re done with the tests, please also merge your changes into the branch copilot/add-async-await-support-dism-operations (PR #2) so everything is in one branch, then I will close this PR.

Copilot AI and others added 2 commits March 30, 2026 01:19
Agent-Logs-Url: https://github.com/Rolling2405/ManagedDism/sessions/d65e954e-2d3a-40a3-b2e6-9a60227a96c5

Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
…thods

- Remove private nested SynchronousProgress<T> class from all 12 async test
  files (a shared SynchronousProgress.cs already exists)
- Rename _CompletesSuccessfully to _ThrowsDismException for 11 test methods
  that assert Should.ThrowAsync<DismException>, keeping the name accurate

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
Copilot AI changed the title [WIP] Add xUnit tests for async DISM API methods Add xUnit tests for async DISM API methods Mar 30, 2026
Copilot AI requested a review from Rolling2405 March 30, 2026 01:27
@Rolling2405 Rolling2405 deleted the copilot/add-xunit-tests-for-async-dism-methods branch March 30, 2026 01:40
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.

2 participants