From e5fbc8c770e6e31a628640779826019326c80e54 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 01:01:18 +0000 Subject: [PATCH 1/3] Initial plan From 85f770d7ce31f07c73622b3b3d553bb7fffb5458 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 01:19:06 +0000 Subject: [PATCH 2/3] Add xUnit tests for 17 async DISM API methods Agent-Logs-Url: https://github.com/Rolling2405/ManagedDism/sessions/d65e954e-2d3a-40a3-b2e6-9a60227a96c5 Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com> --- .../AddCapabilityAsyncTest.cs | 66 ++++++++ .../AddPackageAsyncTest.cs | 66 ++++++++ .../CheckImageHealthAsyncTest.cs | 68 ++++++++ .../CommitImageAsyncTest.cs | 64 +++++++ .../DisableFeatureAsyncTest.cs | 66 ++++++++ .../EnableFeatureAsyncTest.cs | 140 +++++++++++++++ .../MountImageAsyncTest.cs | 160 ++++++++++++++++++ .../RemoveCapabilityAsyncTest.cs | 66 ++++++++ .../RemovePackageAsyncTest.cs | 103 +++++++++++ .../RestoreImageHealthAsyncTest.cs | 66 ++++++++ .../SetEditionAsyncTest.cs | 103 +++++++++++ .../UnmountImageAsyncTest.cs | 84 +++++++++ 12 files changed, 1052 insertions(+) create mode 100644 src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/MountImageAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs create mode 100644 src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs diff --git a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs new file mode 100644 index 0000000..fe962e9 --- /dev/null +++ b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs @@ -0,0 +1,66 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class AddCapabilityAsyncTest : DismTestBase + { + public AddCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task AddCapabilityAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.AddCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", false, null, cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task AddCapabilityAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.AddCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", false, null, cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task AddCapabilityAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.AddCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", false, null, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs new file mode 100644 index 0000000..7733f33 --- /dev/null +++ b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs @@ -0,0 +1,66 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class AddPackageAsyncTest : DismTestBase + { + public AddPackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task AddPackageAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.AddPackageAsync(session, "nonexistent.cab", false, false, cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task AddPackageAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.AddPackageAsync(session, "nonexistent.cab", false, false, cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task AddPackageAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.AddPackageAsync(session, "nonexistent.cab", false, false, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs new file mode 100644 index 0000000..3b9cea8 --- /dev/null +++ b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs @@ -0,0 +1,68 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class CheckImageHealthAsyncTest : DismTestBase + { + public CheckImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task CheckImageHealthAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + DismImageHealthState result = await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: TestContext.Current.CancellationToken); + + result.ShouldBe(DismImageHealthState.Healthy); + } + + [Fact] + public async Task CheckImageHealthAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + await Should.ThrowAsync( + () => DismApi.CheckImageHealthAsync(session, scanImage: true, cancellationToken: cts.Token)); + } + + [Fact] + public async Task CheckImageHealthAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + bool progressReported = false; + var progress = new SynchronousProgress(_ => progressReported = true); + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1)); + + try + { + await DismApi.CheckImageHealthAsync(session, scanImage: true, progress: progress, cancellationToken: cts.Token); + } + catch (OperationCanceledException) + { + } + + progressReported.ShouldBeTrue(); + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs new file mode 100644 index 0000000..71e4dc1 --- /dev/null +++ b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs @@ -0,0 +1,64 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class CommitImageAsyncTest : DismInstallWimTestBase + { + public CommitImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task CommitImageAsync_CompletesSuccessfully() + { + await DismApi.CommitImageAsync(Session, discardChanges: true, cancellationToken: TestContext.Current.CancellationToken); + } + + [Fact] + public async Task CommitImageAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.CommitImageAsync(Session, discardChanges: true, cancellationToken: cts.Token)); + + // The commit with discard may complete before cancellation fires + if (ex != null) + { + ex.ShouldBeAssignableTo(); + } + } + + [Fact] + public async Task CommitImageAsync_ReportsProgress() + { + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.CommitImageAsync(Session, discardChanges: true, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (OperationCanceledException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs new file mode 100644 index 0000000..205ef2e --- /dev/null +++ b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs @@ -0,0 +1,66 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class DisableFeatureAsyncTest : DismTestBase + { + public DisableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task DisableFeatureAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.DisableFeatureAsync(session, "NonExistentFeature", "NonExistentPackage", false, cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task DisableFeatureAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.DisableFeatureAsync(session, "NonExistentFeature", "NonExistentPackage", false, cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task DisableFeatureAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.DisableFeatureAsync(session, "NonExistentFeature", "NonExistentPackage", false, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs new file mode 100644 index 0000000..ae7391a --- /dev/null +++ b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs @@ -0,0 +1,140 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class EnableFeatureAsyncTest : DismTestBase + { + public EnableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task EnableFeatureAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.EnableFeatureAsync(session, "NonExistentFeature", false, false, cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task EnableFeatureAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.EnableFeatureAsync(session, "NonExistentFeature", false, false, cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task EnableFeatureAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.EnableFeatureAsync(session, "NonExistentFeature", false, false, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + [Fact] + public async Task EnableFeatureByPackageNameAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.EnableFeatureByPackageNameAsync(session, "NonExistentFeature", "NonExistentPackage", false, false, cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task EnableFeatureByPackageNameAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.EnableFeatureByPackageNameAsync(session, "NonExistentFeature", "NonExistentPackage", false, false, cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task EnableFeatureByPackageNameAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.EnableFeatureByPackageNameAsync(session, "NonExistentFeature", "NonExistentPackage", false, false, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + [Fact] + public async Task EnableFeatureByPackagePathAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.EnableFeatureByPackagePathAsync(session, "NonExistentFeature", "nonexistent.cab", false, false, cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task EnableFeatureByPackagePathAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.EnableFeatureByPackagePathAsync(session, "NonExistentFeature", "nonexistent.cab", false, false, cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task EnableFeatureByPackagePathAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.EnableFeatureByPackagePathAsync(session, "NonExistentFeature", "nonexistent.cab", false, false, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs new file mode 100644 index 0000000..365ac29 --- /dev/null +++ b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs @@ -0,0 +1,160 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class MountImageAsyncTest : DismTestBase + { + public MountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + public override void Dispose() + { + try + { + DismApi.UnmountImage(MountPath.FullName, commitChanges: false); + } + catch + { + } + + base.Dispose(); + } + + [Fact] + public async Task MountImageAsync_ByIndex_CompletesSuccessfully() + { + await DismApi.MountImageAsync( + InstallWimPath.FullName, + MountPath.FullName, + imageIndex: 1, + readOnly: true, + options: DismMountImageOptions.None, + progress: null, + cancellationToken: TestContext.Current.CancellationToken); + } + + [Fact] + public async Task MountImageAsync_ByIndex_WithCancelledToken_ThrowsOperationCanceledException() + { + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.MountImageAsync( + InstallWimPath.FullName, + MountPath.FullName, + imageIndex: 1, + readOnly: true, + options: DismMountImageOptions.None, + progress: null, + cancellationToken: cts.Token)); + + // The mount may complete before cancellation, or be cancelled + if (ex != null) + { + ex.ShouldBeAssignableTo(); + } + } + + [Fact] + public async Task MountImageAsync_ByIndex_ReportsProgress() + { + bool progressReported = false; + var progress = new SynchronousProgress(_ => progressReported = true); + + try + { + await DismApi.MountImageAsync( + InstallWimPath.FullName, + MountPath.FullName, + imageIndex: 1, + readOnly: true, + options: DismMountImageOptions.None, + progress: progress, + cancellationToken: TestContext.Current.CancellationToken); + } + catch (OperationCanceledException) + { + } + + progressReported.ShouldBeTrue(); + } + + [Fact] + public async Task MountImageAsync_ByName_CompletesSuccessfully() + { + await DismApi.MountImageAsync( + InstallWimPath.FullName, + MountPath.FullName, + imageName: "Test Image 1", + readOnly: true, + options: DismMountImageOptions.None, + progress: null, + cancellationToken: TestContext.Current.CancellationToken); + } + + [Fact] + public async Task MountImageAsync_ByName_WithCancelledToken_ThrowsOperationCanceledException() + { + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.MountImageAsync( + InstallWimPath.FullName, + MountPath.FullName, + imageName: "Test Image 1", + readOnly: true, + options: DismMountImageOptions.None, + progress: null, + cancellationToken: cts.Token)); + + // The mount may complete before cancellation, or be cancelled + if (ex != null) + { + ex.ShouldBeAssignableTo(); + } + } + + [Fact] + public async Task MountImageAsync_ByName_ReportsProgress() + { + bool progressReported = false; + var progress = new SynchronousProgress(_ => progressReported = true); + + try + { + await DismApi.MountImageAsync( + InstallWimPath.FullName, + MountPath.FullName, + imageName: "Test Image 1", + readOnly: true, + options: DismMountImageOptions.None, + progress: progress, + cancellationToken: TestContext.Current.CancellationToken); + } + catch (OperationCanceledException) + { + } + + progressReported.ShouldBeTrue(); + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs new file mode 100644 index 0000000..923eda1 --- /dev/null +++ b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs @@ -0,0 +1,66 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class RemoveCapabilityAsyncTest : DismTestBase + { + public RemoveCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task RemoveCapabilityAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.RemoveCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task RemoveCapabilityAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.RemoveCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task RemoveCapabilityAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.RemoveCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs new file mode 100644 index 0000000..a32f152 --- /dev/null +++ b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs @@ -0,0 +1,103 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class RemovePackageAsyncTest : DismTestBase + { + public RemovePackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task RemovePackageByNameAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.RemovePackageByNameAsync(session, "NonExistentPackage", cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task RemovePackageByNameAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.RemovePackageByNameAsync(session, "NonExistentPackage", cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task RemovePackageByNameAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.RemovePackageByNameAsync(session, "NonExistentPackage", progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + [Fact] + public async Task RemovePackageByPathAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.RemovePackageByPathAsync(session, "nonexistent.cab", cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task RemovePackageByPathAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.RemovePackageByPathAsync(session, "nonexistent.cab", cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task RemovePackageByPathAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.RemovePackageByPathAsync(session, "nonexistent.cab", progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs new file mode 100644 index 0000000..3cb0d16 --- /dev/null +++ b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs @@ -0,0 +1,66 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class RestoreImageHealthAsyncTest : DismTestBase + { + public RestoreImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task RestoreImageHealthAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await DismApi.RestoreImageHealthAsync(session, limitAccess: true, cancellationToken: TestContext.Current.CancellationToken); + } + + [Fact] + public async Task RestoreImageHealthAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + await Should.ThrowAsync( + () => DismApi.RestoreImageHealthAsync(session, limitAccess: true, cancellationToken: cts.Token)); + } + + [Fact] + public async Task RestoreImageHealthAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + bool progressReported = false; + var progress = new SynchronousProgress(_ => progressReported = true); + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1)); + + try + { + await DismApi.RestoreImageHealthAsync(session, limitAccess: true, progress: progress, cancellationToken: cts.Token); + } + catch (OperationCanceledException) + { + } + + progressReported.ShouldBeTrue(); + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs new file mode 100644 index 0000000..2864f0a --- /dev/null +++ b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs @@ -0,0 +1,103 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class SetEditionAsyncTest : DismTestBase + { + public SetEditionAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + [Fact] + public async Task SetEditionAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.SetEditionAsync(session, "NonExistentEdition", cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task SetEditionAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.SetEditionAsync(session, "NonExistentEdition", cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task SetEditionAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.SetEditionAsync(session, "NonExistentEdition", progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + [Fact] + public async Task SetEditionAndProductKeyAsync_CompletesSuccessfully() + { + using DismSession session = DismApi.OpenOnlineSession(); + + await Should.ThrowAsync( + () => DismApi.SetEditionAndProductKeyAsync(session, "NonExistentEdition", "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", cancellationToken: TestContext.Current.CancellationToken)); + } + + [Fact] + public async Task SetEditionAndProductKeyAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + using DismSession session = DismApi.OpenOnlineSession(); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.SetEditionAndProductKeyAsync(session, "NonExistentEdition", "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", cancellationToken: cts.Token)); + + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(); + } + + [Fact] + public async Task SetEditionAndProductKeyAsync_ReportsProgress() + { + using DismSession session = DismApi.OpenOnlineSession(); + var progress = new SynchronousProgress(_ => { }); + + try + { + await DismApi.SetEditionAndProductKeyAsync(session, "NonExistentEdition", "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (DismException) + { + } + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} diff --git a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs new file mode 100644 index 0000000..a6462ae --- /dev/null +++ b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs @@ -0,0 +1,84 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using Shouldly; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Dism.Tests +{ + public class UnmountImageAsyncTest : DismTestBase + { + public UnmountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput) + : base(template, testOutput) + { + } + + public override void Dispose() + { + try + { + DismApi.UnmountImage(MountPath.FullName, commitChanges: false); + } + catch + { + } + + base.Dispose(); + } + + [Fact] + public async Task UnmountImageAsync_CompletesSuccessfully() + { + DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1); + + await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, cancellationToken: TestContext.Current.CancellationToken); + } + + [Fact] + public async Task UnmountImageAsync_WithCancelledToken_ThrowsOperationCanceledException() + { + DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1); + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + Exception? ex = await Record.ExceptionAsync( + () => DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, cancellationToken: cts.Token)); + + // The unmount may complete before cancellation fires, or be cancelled + if (ex != null) + { + ex.ShouldBeAssignableTo(); + } + } + + [Fact] + public async Task UnmountImageAsync_ReportsProgress() + { + DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1); + bool progressReported = false; + var progress = new SynchronousProgress(_ => progressReported = true); + + try + { + await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, progress: progress, cancellationToken: TestContext.Current.CancellationToken); + } + catch (OperationCanceledException) + { + } + + progressReported.ShouldBeTrue(); + } + + private sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } + } +} From 647efae2495f1da9b2bd138533809e0b35f91831 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 01:22:32 +0000 Subject: [PATCH 3/3] Remove duplicate SynchronousProgress and rename misleading test methods - Remove private nested SynchronousProgress 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, keeping the name accurate Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com> --- .../AddCapabilityAsyncTest.cs | 11 +---------- src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs | 11 +---------- .../CheckImageHealthAsyncTest.cs | 9 --------- .../CommitImageAsyncTest.cs | 9 --------- .../DisableFeatureAsyncTest.cs | 11 +---------- .../EnableFeatureAsyncTest.cs | 15 +++------------ src/Microsoft.Dism.Tests/MountImageAsyncTest.cs | 9 --------- .../RemoveCapabilityAsyncTest.cs | 11 +---------- .../RemovePackageAsyncTest.cs | 13 ++----------- .../RestoreImageHealthAsyncTest.cs | 9 --------- src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs | 13 ++----------- src/Microsoft.Dism.Tests/SynchronousProgress.cs | 17 +++++++++++++++++ .../UnmountImageAsyncTest.cs | 9 --------- 13 files changed, 28 insertions(+), 119 deletions(-) create mode 100644 src/Microsoft.Dism.Tests/SynchronousProgress.cs diff --git a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs index fe962e9..af01c74 100644 --- a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs @@ -18,7 +18,7 @@ public AddCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOu } [Fact] - public async Task AddCapabilityAsync_CompletesSuccessfully() + public async Task AddCapabilityAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -53,14 +53,5 @@ public async Task AddCapabilityAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs index 7733f33..efd6d39 100644 --- a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs @@ -18,7 +18,7 @@ public AddPackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutpu } [Fact] - public async Task AddPackageAsync_CompletesSuccessfully() + public async Task AddPackageAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -53,14 +53,5 @@ public async Task AddPackageAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs index 3b9cea8..bdb6a0e 100644 --- a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs @@ -55,14 +55,5 @@ public async Task CheckImageHealthAsync_ReportsProgress() progressReported.ShouldBeTrue(); } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs index 71e4dc1..c963499 100644 --- a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs @@ -51,14 +51,5 @@ public async Task CommitImageAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs index 205ef2e..56ae980 100644 --- a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs @@ -18,7 +18,7 @@ public DisableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testO } [Fact] - public async Task DisableFeatureAsync_CompletesSuccessfully() + public async Task DisableFeatureAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -53,14 +53,5 @@ public async Task DisableFeatureAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs index ae7391a..7b15eca 100644 --- a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs @@ -18,7 +18,7 @@ public EnableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOu } [Fact] - public async Task EnableFeatureAsync_CompletesSuccessfully() + public async Task EnableFeatureAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -55,7 +55,7 @@ public async Task EnableFeatureAsync_ReportsProgress() } [Fact] - public async Task EnableFeatureByPackageNameAsync_CompletesSuccessfully() + public async Task EnableFeatureByPackageNameAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -92,7 +92,7 @@ public async Task EnableFeatureByPackageNameAsync_ReportsProgress() } [Fact] - public async Task EnableFeatureByPackagePathAsync_CompletesSuccessfully() + public async Task EnableFeatureByPackagePathAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -127,14 +127,5 @@ public async Task EnableFeatureByPackagePathAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs index 365ac29..8c8e89d 100644 --- a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs @@ -147,14 +147,5 @@ await DismApi.MountImageAsync( progressReported.ShouldBeTrue(); } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs index 923eda1..0c299c6 100644 --- a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs @@ -18,7 +18,7 @@ public RemoveCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper tes } [Fact] - public async Task RemoveCapabilityAsync_CompletesSuccessfully() + public async Task RemoveCapabilityAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -53,14 +53,5 @@ public async Task RemoveCapabilityAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs index a32f152..f0242b4 100644 --- a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs @@ -18,7 +18,7 @@ public RemovePackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOu } [Fact] - public async Task RemovePackageByNameAsync_CompletesSuccessfully() + public async Task RemovePackageByNameAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -55,7 +55,7 @@ public async Task RemovePackageByNameAsync_ReportsProgress() } [Fact] - public async Task RemovePackageByPathAsync_CompletesSuccessfully() + public async Task RemovePackageByPathAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -90,14 +90,5 @@ public async Task RemovePackageByPathAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs index 3cb0d16..3e70346 100644 --- a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs @@ -53,14 +53,5 @@ public async Task RestoreImageHealthAsync_ReportsProgress() progressReported.ShouldBeTrue(); } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs index 2864f0a..f812cae 100644 --- a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs @@ -18,7 +18,7 @@ public SetEditionAsyncTest(TestWimTemplate template, ITestOutputHelper testOutpu } [Fact] - public async Task SetEditionAsync_CompletesSuccessfully() + public async Task SetEditionAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -55,7 +55,7 @@ public async Task SetEditionAsync_ReportsProgress() } [Fact] - public async Task SetEditionAndProductKeyAsync_CompletesSuccessfully() + public async Task SetEditionAndProductKeyAsync_ThrowsDismException() { using DismSession session = DismApi.OpenOnlineSession(); @@ -90,14 +90,5 @@ public async Task SetEditionAndProductKeyAsync_ReportsProgress() { } } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } } diff --git a/src/Microsoft.Dism.Tests/SynchronousProgress.cs b/src/Microsoft.Dism.Tests/SynchronousProgress.cs new file mode 100644 index 0000000..8418fa4 --- /dev/null +++ b/src/Microsoft.Dism.Tests/SynchronousProgress.cs @@ -0,0 +1,17 @@ +// Copyright (c). All rights reserved. +// +// Licensed under the MIT license. + +using System; + +namespace Microsoft.Dism.Tests +{ + internal sealed class SynchronousProgress : IProgress + { + private readonly Action _handler; + + public SynchronousProgress(Action handler) => _handler = handler; + + public void Report(T value) => _handler(value); + } +} diff --git a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs index a6462ae..6ea517e 100644 --- a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs +++ b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs @@ -71,14 +71,5 @@ public async Task UnmountImageAsync_ReportsProgress() progressReported.ShouldBeTrue(); } - - private sealed class SynchronousProgress : IProgress - { - private readonly Action _handler; - - public SynchronousProgress(Action handler) => _handler = handler; - - public void Report(T value) => _handler(value); - } } }