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
98 changes: 98 additions & 0 deletions MSStore.CLI.UnitTests/PublishCommandUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.CommandLine;
using System.Globalization;
using MSStore.API.Packaged.Models;
using MSStore.CLI.Commands;
using MSStore.CLI.ProjectConfigurators;

Expand Down Expand Up @@ -308,6 +309,103 @@ public async Task PublishCommandShouldSucceedForFlights()
result.Error.Should().Contain("Submission commit success! Here is some data:");
result.Error.Should().Contain("test.msix");
}

[TestMethod]
public async Task PublishCommandShouldApplyPackageRolloutPercentageWhenSubmissionHasNoRolloutConfigured()
{
// Regression: the rollout was only applied when the submission already carried a
// PackageDeliveryOptions.PackageRollout object. A newly created submission has neither,
// so --packageRolloutPercentage was silently dropped and the app shipped to 100%.
var path = CopyFilesRecursively("MSIXProject");

var msixPath = Path.Combine(path, "test.msix");

AddDefaultFakeSuccessfulSubmission();

await ParseAndInvokeAsync(
[
"publish",
msixPath,
"--appId",
FakeApps[0].Id!,
"--packageRolloutPercentage",
"5"
]);

FakeStorePackagedAPI
.Verify(
x => x.UpdateSubmissionAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.Is<DevCenterSubmission>(s =>
s.PackageDeliveryOptions!.PackageRollout!.IsPackageRollout &&
s.PackageDeliveryOptions.PackageRollout.PackageRolloutPercentage == 5),
It.IsAny<CancellationToken>()),
Times.Once);
}

[TestMethod]
public async Task PublishCommandShouldApplyPackageRolloutPercentageForFlights()
{
var path = CopyFilesRecursively("MSIXProject");

var msixPath = Path.Combine(path, "test.msix");

AddFakeFlights();
AddDefaultFakeSuccessfulFlightSubmission();

await ParseAndInvokeAsync(
[
"publish",
msixPath,
"--appId",
FakeApps[0].Id!,
"--flightId",
FakeFlights[0].FlightId!,
"--packageRolloutPercentage",
"5"
]);

FakeStorePackagedAPI
.Verify(
x => x.UpdateFlightSubmissionAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.Is<DevCenterFlightSubmissionUpdate>(s =>
s.PackageDeliveryOptions!.PackageRollout!.IsPackageRollout &&
s.PackageDeliveryOptions.PackageRollout.PackageRolloutPercentage == 5),
It.IsAny<CancellationToken>()),
Times.Once);
}

[TestMethod]
public async Task PublishCommandShouldNotEnableRolloutWhenPercentageIsNotProvided()
{
var path = CopyFilesRecursively("MSIXProject");

var msixPath = Path.Combine(path, "test.msix");

AddDefaultFakeSuccessfulSubmission();

await ParseAndInvokeAsync(
[
"publish",
msixPath,
"--appId",
FakeApps[0].Id!
]);

FakeStorePackagedAPI
.Verify(
x => x.UpdateSubmissionAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.Is<DevCenterSubmission>(s => s.PackageDeliveryOptions == null),
It.IsAny<CancellationToken>()),
Times.Once);
}

private static ParseResult ParsePublish(params string[] args) =>
new PublishCommand().Parse(args);

Expand Down
7 changes: 6 additions & 1 deletion MSStore.CLI/Helpers/IStorePackagedAPIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,13 @@ public static async Task<int> PublishAsync(
return -1;
}

if (submission.PackageDeliveryOptions?.PackageRollout != null && packageRolloutPercentage != null)
if (packageRolloutPercentage != null)
{
// A freshly created submission usually comes back with no rollout configured at all,
// so these objects have to be materialized rather than assumed. Guarding on
// PackageRollout being non-null silently dropped --packageRolloutPercentage.
submission.PackageDeliveryOptions ??= new PackageDeliveryOptions();
submission.PackageDeliveryOptions.PackageRollout ??= new PackageRollout();
submission.PackageDeliveryOptions.PackageRollout.IsPackageRollout = true;
submission.PackageDeliveryOptions.PackageRollout.PackageRolloutPercentage = packageRolloutPercentage.Value;
}
Expand Down