Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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_ThrowsDismException()
{
using DismSession session = DismApi.OpenOnlineSession();

await Should.ThrowAsync<DismException>(
() => 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<Exception>();
}

[Fact]
public async Task AddCapabilityAsync_ReportsProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
var progress = new SynchronousProgress<DismProgress>(_ => { });

try
{
await DismApi.AddCapabilityAsync(session, "NonExistent.Capability~~~~0.0.1.0", false, null, progress: progress, cancellationToken: TestContext.Current.CancellationToken);
}
catch (DismException)
{
}
}
}
}
57 changes: 57 additions & 0 deletions src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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_ThrowsDismException()
{
using DismSession session = DismApi.OpenOnlineSession();

await Should.ThrowAsync<DismException>(
() => 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<Exception>();
}

[Fact]
public async Task AddPackageAsync_ReportsProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
var progress = new SynchronousProgress<DismProgress>(_ => { });

try
{
await DismApi.AddPackageAsync(session, "nonexistent.cab", false, false, progress: progress, cancellationToken: TestContext.Current.CancellationToken);
}
catch (DismException)
{
}
}
}
}
59 changes: 59 additions & 0 deletions src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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<OperationCanceledException>(
() => 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<DismProgress>(_ => 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();
}
}
}
55 changes: 55 additions & 0 deletions src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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<Exception>();
}
}

[Fact]
public async Task CommitImageAsync_ReportsProgress()
{
var progress = new SynchronousProgress<DismProgress>(_ => { });

try
{
await DismApi.CommitImageAsync(Session, discardChanges: true, progress: progress, cancellationToken: TestContext.Current.CancellationToken);
}
catch (OperationCanceledException)
{
}
}
}
}
57 changes: 57 additions & 0 deletions src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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_ThrowsDismException()
{
using DismSession session = DismApi.OpenOnlineSession();

await Should.ThrowAsync<DismException>(
() => 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<Exception>();
}

[Fact]
public async Task DisableFeatureAsync_ReportsProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
var progress = new SynchronousProgress<DismProgress>(_ => { });

try
{
await DismApi.DisableFeatureAsync(session, "NonExistentFeature", "NonExistentPackage", false, progress: progress, cancellationToken: TestContext.Current.CancellationToken);
}
catch (DismException)
{
}
}
}
}
Loading