From 1e575b09b171a81447bbffc7198e5ed46f1649ab Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Sun, 26 Nov 2023 16:31:11 +0500 Subject: [PATCH 1/5] Improvements to replace argument --- src/WingetCreateCLI/Commands/SubmitCommand.cs | 22 ++++++++++++++----- src/WingetCreateCLI/Commands/UpdateCommand.cs | 16 ++++++++++++++ .../Properties/Resources.Designer.cs | 9 ++++++++ src/WingetCreateCLI/Properties/Resources.resx | 7 ++++++ src/WingetCreateCore/Common/GitHub.cs | 10 ++++++++- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/WingetCreateCLI/Commands/SubmitCommand.cs b/src/WingetCreateCLI/Commands/SubmitCommand.cs index 9d7bbd84..804dae83 100644 --- a/src/WingetCreateCLI/Commands/SubmitCommand.cs +++ b/src/WingetCreateCLI/Commands/SubmitCommand.cs @@ -44,10 +44,16 @@ public static IEnumerable Examples public string Path { get; set; } /// - /// Gets or sets the GitHub token used to submit a pull request on behalf of the user. + /// Gets or sets the previous version to replace from the Windows Package Manager repository. /// - [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] - public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + [Value(1, MetaName = "ReplaceVersion", Required = false, HelpText = "ReplaceVersion_HelpText", ResourceType = typeof(Resources))] + public string ReplaceVersion { get; set; } + + /// + /// Gets or sets a value indicating whether or not to replace a previous version of the manifest with the update. + /// + [Option('r', "replace", Required = false, HelpText = "ReplacePrevious_HelpText", ResourceType = typeof(Resources))] + public bool Replace { get; set; } /// /// Gets or sets the title for the pull request. @@ -55,6 +61,12 @@ public static IEnumerable Examples [Option('p', "prtitle", Required = false, HelpText = "PullRequestTitle_HelpText", ResourceType = typeof(Resources))] public override string PRTitle { get => base.PRTitle; set => base.PRTitle = value; } + /// + /// Gets or sets the GitHub token used to submit a pull request on behalf of the user. + /// + [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] + public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + /// /// Gets or sets the unbound arguments that exist after the first positional parameter. /// @@ -101,13 +113,13 @@ private async Task SubmitManifest() { Manifests manifests = new Manifests(); manifests.SingletonManifest = Serialization.DeserializeFromPath(this.Path); - return await this.GitHubSubmitManifests(manifests, this.PRTitle); + return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion); } else if (Directory.Exists(this.Path) && ValidateManifest(this.Path)) { List manifestContents = Directory.GetFiles(this.Path).Select(f => File.ReadAllText(f)).ToList(); Manifests manifests = Serialization.DeserializeManifestContents(manifestContents); - return await this.GitHubSubmitManifests(manifests, this.PRTitle); + return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion); } else { diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index a9961457..7c2beabf 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -138,6 +138,22 @@ public override async Task Execute() return false; } + var argumentsRequiringSubmit = new List { nameof(this.PRTitle), nameof(this.Replace) }; + bool submissionArguments = !string.IsNullOrEmpty(this.PRTitle) || this.Replace; + + if (submissionArguments && !this.SubmitToGitHub) + { + Logger.ErrorLocalized(nameof(Resources.SubmitFlagRequired_ErrorMessage)); + Console.WriteLine(); + + foreach (string argument in argumentsRequiringSubmit) + { + Logger.Error($"--{argument.ToLower()}"); + } + + return false; + } + Logger.DebugLocalized(nameof(Resources.RetrievingManifest_Message), this.Id); string exactId; diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index 4fed488c..ddf3ae25 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -2760,6 +2760,15 @@ public static string SubmitCommand_HelpText { } } + /// + /// Looks up a localized string similar to Submission arguments used without submit flag. The following options require passing in '-s' / '--submit':. + /// + public static string SubmitFlagRequired_ErrorMessage { + get { + return ResourceManager.GetString("SubmitFlagRequired_ErrorMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Submitting pull request for manifest.... /// diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index 5548ba0e..3c7f9c19 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -1234,4 +1234,11 @@ The following commands are available: + + Indicates whether the installer is prohibited from being downloaded for offline installation + + + Submission arguments used without submit flag. The following options require passing in '-s' / '--submit': + '-s / --submit' refers to a command line switch argument + \ No newline at end of file diff --git a/src/WingetCreateCore/Common/GitHub.cs b/src/WingetCreateCore/Common/GitHub.cs index 88246766..3d2d7b5f 100644 --- a/src/WingetCreateCore/Common/GitHub.cs +++ b/src/WingetCreateCore/Common/GitHub.cs @@ -361,7 +361,15 @@ await retryPolicy.ExecuteAsync(async () => // Remove a previous manifest if (shouldReplace) { - await this.DeletePackageManifest(repo.Id, packageId, replaceVersion, newBranchName); + try + { + await this.DeletePackageManifest(repo.Id, packageId, replaceVersion, newBranchName); + } + catch (NotFoundException) + { + // If the path to the manifest folder being replaced does not exist, do nothing. + // This can happen with submit command when user submits a new package and path to its version directory does not exist yet. + } } // Get latest description template from repo From d6e42dda2e630f9d7c1433e0df7fe583a41a55f2 Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Sun, 26 Nov 2023 17:04:17 +0500 Subject: [PATCH 2/5] var name --- src/WingetCreateCLI/Commands/UpdateCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index 7c2beabf..184fc6fa 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -139,9 +139,9 @@ public override async Task Execute() } var argumentsRequiringSubmit = new List { nameof(this.PRTitle), nameof(this.Replace) }; - bool submissionArguments = !string.IsNullOrEmpty(this.PRTitle) || this.Replace; + bool submissionArgumentsUsed = !string.IsNullOrEmpty(this.PRTitle) || this.Replace; - if (submissionArguments && !this.SubmitToGitHub) + if (submissionArgumentsUsed && !this.SubmitToGitHub) { Logger.ErrorLocalized(nameof(Resources.SubmitFlagRequired_ErrorMessage)); Console.WriteLine(); From 9442c7867bb892c916698f9b1deb803422b5e7b3 Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Mon, 27 Nov 2023 21:14:30 +0500 Subject: [PATCH 3/5] doc --- doc/submit.md | 1 + src/WingetCreateCLI/Commands/SubmitCommand.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/submit.md b/doc/submit.md index 945307ce..ed66d49a 100644 --- a/doc/submit.md +++ b/doc/submit.md @@ -16,6 +16,7 @@ The following arguments are available: | Argument | Description | |--------------|-------------| | **-p, --prtitle** | The title of the pull request submitted to GitHub. +| **-r, --replace** | Boolean value for replacing an existing manifest from the Windows Package Manager repo. Optionally provide a version or else the latest version will be replaced. Default is false. | **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo. If no token is provided, tool will prompt for GitHub login credentials. If you have provided your [GitHub token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) on the command line with the **submit** command and the device is registered with GitHub, **Winget-Create** will submit your PR to [Windows Package Manager repo](https://docs.microsoft.com/windows/package-manager/). diff --git a/src/WingetCreateCLI/Commands/SubmitCommand.cs b/src/WingetCreateCLI/Commands/SubmitCommand.cs index 804dae83..bceb7010 100644 --- a/src/WingetCreateCLI/Commands/SubmitCommand.cs +++ b/src/WingetCreateCLI/Commands/SubmitCommand.cs @@ -49,18 +49,18 @@ public static IEnumerable Examples [Value(1, MetaName = "ReplaceVersion", Required = false, HelpText = "ReplaceVersion_HelpText", ResourceType = typeof(Resources))] public string ReplaceVersion { get; set; } - /// - /// Gets or sets a value indicating whether or not to replace a previous version of the manifest with the update. - /// - [Option('r', "replace", Required = false, HelpText = "ReplacePrevious_HelpText", ResourceType = typeof(Resources))] - public bool Replace { get; set; } - /// /// Gets or sets the title for the pull request. /// [Option('p', "prtitle", Required = false, HelpText = "PullRequestTitle_HelpText", ResourceType = typeof(Resources))] public override string PRTitle { get => base.PRTitle; set => base.PRTitle = value; } + /// + /// Gets or sets a value indicating whether or not to replace a previous version of the manifest with the update. + /// + [Option('r', "replace", Required = false, HelpText = "ReplacePrevious_HelpText", ResourceType = typeof(Resources))] + public bool Replace { get; set; } + /// /// Gets or sets the GitHub token used to submit a pull request on behalf of the user. /// From 183cba5c5445805178e55e13c212902a1011aad4 Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Wed, 29 Nov 2023 19:39:37 +0500 Subject: [PATCH 4/5] address review comments --- src/WingetCreateCLI/Commands/SubmitCommand.cs | 55 ++++++++++++++++++ src/WingetCreateCLI/Commands/UpdateCommand.cs | 16 ++---- .../Properties/Resources.Designer.cs | 24 +++++++- src/WingetCreateCLI/Properties/Resources.resx | 13 ++++- src/WingetCreateCore/Common/GitHub.cs | 10 +--- .../UnitTests/UpdateCommandTests.cs | 56 +++++++++++++++++++ 6 files changed, 147 insertions(+), 27 deletions(-) diff --git a/src/WingetCreateCLI/Commands/SubmitCommand.cs b/src/WingetCreateCLI/Commands/SubmitCommand.cs index fe466110..9996022b 100644 --- a/src/WingetCreateCLI/Commands/SubmitCommand.cs +++ b/src/WingetCreateCLI/Commands/SubmitCommand.cs @@ -115,12 +115,24 @@ private async Task SubmitManifest() { Manifests manifests = new Manifests(); manifests.SingletonManifest = Serialization.DeserializeFromPath(expandedPath); + + if (this.Replace && !await this.ValidateReplaceArguments(manifests.SingletonManifest.PackageIdentifier, manifests.SingletonManifest.PackageVersion)) + { + return false; + } + return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion); } else if (Directory.Exists(expandedPath) && ValidateManifest(expandedPath)) { List manifestContents = Directory.GetFiles(expandedPath).Select(f => File.ReadAllText(f)).ToList(); Manifests manifests = Serialization.DeserializeManifestContents(manifestContents); + + if (this.Replace && !await this.ValidateReplaceArguments(manifests.VersionManifest.PackageIdentifier, manifests.VersionManifest.PackageVersion)) + { + return false; + } + return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion); } else @@ -129,5 +141,48 @@ private async Task SubmitManifest() return false; } } + + private async Task ValidateReplaceArguments(string packageId, string submitVersion) + { + string exactId; + try + { + exactId = await this.GitHubClient.FindPackageId(packageId); + } + catch (Octokit.RateLimitExceededException) + { + Logger.ErrorLocalized(nameof(Resources.RateLimitExceeded_Message)); + return false; + } + + if (string.IsNullOrEmpty(exactId)) + { + Logger.ErrorLocalized(nameof(Resources.ReplacePackageIdDoesNotExist_Error), packageId); + return false; + } + + if (!string.IsNullOrEmpty(this.ReplaceVersion)) + { + // If submit version is same as replace version, it's a regular update. + if (submitVersion == this.ReplaceVersion) + { + Logger.ErrorLocalized(nameof(Resources.ReplaceVersionEqualsSubmitVersion_ErrorMessage)); + return false; + } + + // Check if the replace version exists in the repository. + try + { + await this.GitHubClient.GetManifestContentAsync(packageId, this.ReplaceVersion); + } + catch (Octokit.NotFoundException) + { + Logger.ErrorLocalized(nameof(Resources.VersionDoesNotExist_Error), this.ReplaceVersion, packageId); + return false; + } + } + + return true; + } } } diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index 184fc6fa..391b340e 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -138,20 +138,12 @@ public override async Task Execute() return false; } - var argumentsRequiringSubmit = new List { nameof(this.PRTitle), nameof(this.Replace) }; - bool submissionArgumentsUsed = !string.IsNullOrEmpty(this.PRTitle) || this.Replace; + bool submitFlagMissing = !this.SubmitToGitHub && (!string.IsNullOrEmpty(this.PRTitle) || this.Replace); - if (submissionArgumentsUsed && !this.SubmitToGitHub) + if (submitFlagMissing) { - Logger.ErrorLocalized(nameof(Resources.SubmitFlagRequired_ErrorMessage)); + Logger.WarnLocalized(nameof(Resources.SubmitFlagMissing_Warning)); Console.WriteLine(); - - foreach (string argument in argumentsRequiringSubmit) - { - Logger.Error($"--{argument.ToLower()}"); - } - - return false; } Logger.DebugLocalized(nameof(Resources.RetrievingManifest_Message), this.Id); @@ -188,7 +180,7 @@ public override async Task Execute() } catch (Octokit.NotFoundException) { - Logger.ErrorLocalized(nameof(Resources.VersionDoesNotExist_Error), this.Version, this.Id); + Logger.ErrorLocalized(nameof(Resources.VersionDoesNotExist_Error), this.ReplaceVersion, this.Id); return false; } } diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index e3a0282f..2004ec9f 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -2265,6 +2265,15 @@ public static string RemoveLastItem_MenuItem { } } + /// + /// Looks up a localized string similar to Replace operation cannot be performed. PackageId '{0}' does not exist in the Windows Package Manager repo. . + /// + public static string ReplacePackageIdDoesNotExist_Error { + get { + return ResourceManager.GetString("ReplacePackageIdDoesNotExist_Error", resourceCulture); + } + } + /// /// Looks up a localized string similar to Boolean value for replacing an existing manifest from the Windows Package Manager repo. Optionally provide a version or else the latest version will be replaced. Default is false.. /// @@ -2283,6 +2292,15 @@ public static string ReplaceVersion_HelpText { } } + /// + /// Looks up a localized string similar to The replace version cannot be equal to the submit version.. + /// + public static string ReplaceVersionEqualsSubmitVersion_ErrorMessage { + get { + return ResourceManager.GetString("ReplaceVersionEqualsSubmitVersion_ErrorMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to The replace version cannot be equal to the update version.. /// @@ -2770,11 +2788,11 @@ public static string SubmitCommand_HelpText { } /// - /// Looks up a localized string similar to Submission arguments used without submit flag. The following options require passing in '-s' / '--submit':. + /// Looks up a localized string similar to Submit arguments were provided. Did you forget to include the --submit, -s flag?. /// - public static string SubmitFlagRequired_ErrorMessage { + public static string SubmitFlagMissing_Warning { get { - return ResourceManager.GetString("SubmitFlagRequired_ErrorMessage", resourceCulture); + return ResourceManager.GetString("SubmitFlagMissing_Warning", resourceCulture); } } diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index 3c7f9c19..25657619 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -1237,8 +1237,15 @@ Indicates whether the installer is prohibited from being downloaded for offline installation - - Submission arguments used without submit flag. The following options require passing in '-s' / '--submit': - '-s / --submit' refers to a command line switch argument + + Submit arguments were provided. Did you forget to include the --submit, -s flag? + '--submit, -s' refers to a command line switch argument + + + Replace operation cannot be performed. PackageId '{0}' does not exist in the Windows Package Manager repo. + {0} - will be replaced with the ID of the package + + + The replace version cannot be equal to the submit version. \ No newline at end of file diff --git a/src/WingetCreateCore/Common/GitHub.cs b/src/WingetCreateCore/Common/GitHub.cs index 3d2d7b5f..88246766 100644 --- a/src/WingetCreateCore/Common/GitHub.cs +++ b/src/WingetCreateCore/Common/GitHub.cs @@ -361,15 +361,7 @@ await retryPolicy.ExecuteAsync(async () => // Remove a previous manifest if (shouldReplace) { - try - { - await this.DeletePackageManifest(repo.Id, packageId, replaceVersion, newBranchName); - } - catch (NotFoundException) - { - // If the path to the manifest folder being replaced does not exist, do nothing. - // This can happen with submit command when user submits a new package and path to its version directory does not exist yet. - } + await this.DeletePackageManifest(repo.Id, packageId, replaceVersion, newBranchName); } // Get latest description template from repo diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs index 2db1b306..e6bcd51b 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs @@ -212,6 +212,62 @@ public async Task UpdateFailsWithUnmatchedPackages() Assert.That(result, Does.Contain(Resources.NewInstallerUrlMustMatchExisting_Message), "New installer must match error should be thrown"); } + /// + /// Verify that update command warns if submit arguments are provided without submit flag being set. + /// + /// A representing the asynchronous unit test. + [Test] + public async Task UpdateChecksMissingSubmitFlag() + { + string packageId = "TestPublisher.TestPackageId"; + string version = "1.2.3.4"; + + UpdateCommand command1 = new UpdateCommand + { + Id = packageId, + Version = version, + InstallerUrls = new[] { "https://fakedomain.com/fakeinstaller.exe" }, + SubmitToGitHub = false, + Replace = true, + }; + + UpdateCommand command2 = new UpdateCommand + { + Id = packageId, + Version = version, + InstallerUrls = new[] { "https://fakedomain.com/fakeinstaller.exe" }, + SubmitToGitHub = false, + PRTitle = "Test PR Title", + }; + + try + { + await command1.Execute(); + } + catch (Exception) + { + // Expected exception + } + + string result = this.sw.ToString(); + Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit arguments provided without submit flag warning should be thrown"); + + // Clear the string writer + this.sw.GetStringBuilder().Clear(); + + try + { + await command2.Execute(); + } + catch (Exception) + { + // Expected exception + } + + result = this.sw.ToString(); + Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit arguments provided without submit flag warning should be thrown"); + } + /// /// Since some installers are incorrectly labeled on the manifest, resort to using the installer URL to find matches. /// This unit test uses a msi installer that is not an arm64 installer, but because the installer URL includes "arm64", it should find a match. From b3e02b4d238062862d49f8473884a2afd296125f Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Thu, 30 Nov 2023 22:44:53 +0500 Subject: [PATCH 5/5] address review comments --- src/WingetCreateCLI/Commands/SubmitCommand.cs | 1 + .../Properties/Resources.Designer.cs | 2 +- src/WingetCreateCLI/Properties/Resources.resx | 2 +- .../UnitTests/UpdateCommandTests.cs | 44 +++++++++++-------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/WingetCreateCLI/Commands/SubmitCommand.cs b/src/WingetCreateCLI/Commands/SubmitCommand.cs index 9996022b..58dc3313 100644 --- a/src/WingetCreateCLI/Commands/SubmitCommand.cs +++ b/src/WingetCreateCLI/Commands/SubmitCommand.cs @@ -111,6 +111,7 @@ private async Task SubmitManifest() { string expandedPath = System.Environment.ExpandEnvironmentVariables(this.Path); + // TODO: Remove singleton support. if (File.Exists(expandedPath) && ValidateManifest(expandedPath)) { Manifests manifests = new Manifests(); diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index 2004ec9f..a3495ede 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -2266,7 +2266,7 @@ public static string RemoveLastItem_MenuItem { } /// - /// Looks up a localized string similar to Replace operation cannot be performed. PackageId '{0}' does not exist in the Windows Package Manager repo. . + /// Looks up a localized string similar to Replace operation cannot be performed. Package identifier '{0}' does not exist in the Windows Package Manager repo.. /// public static string ReplacePackageIdDoesNotExist_Error { get { diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index 25657619..67a26139 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -1242,7 +1242,7 @@ '--submit, -s' refers to a command line switch argument - Replace operation cannot be performed. PackageId '{0}' does not exist in the Windows Package Manager repo. + Replace operation cannot be performed. Package identifier '{0}' does not exist in the Windows Package Manager repo. {0} - will be replaced with the ID of the package diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs index e6bcd51b..7610ffeb 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs @@ -217,12 +217,12 @@ public async Task UpdateFailsWithUnmatchedPackages() /// /// A representing the asynchronous unit test. [Test] - public async Task UpdateChecksMissingSubmitFlag() + public async Task UpdateChecksMissingSubmitFlagWithReplace() { string packageId = "TestPublisher.TestPackageId"; string version = "1.2.3.4"; - UpdateCommand command1 = new UpdateCommand + UpdateCommand command = new UpdateCommand { Id = packageId, Version = version, @@ -231,18 +231,9 @@ public async Task UpdateChecksMissingSubmitFlag() Replace = true, }; - UpdateCommand command2 = new UpdateCommand - { - Id = packageId, - Version = version, - InstallerUrls = new[] { "https://fakedomain.com/fakeinstaller.exe" }, - SubmitToGitHub = false, - PRTitle = "Test PR Title", - }; - try { - await command1.Execute(); + await command.Execute(); } catch (Exception) { @@ -250,22 +241,39 @@ public async Task UpdateChecksMissingSubmitFlag() } string result = this.sw.ToString(); - Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit arguments provided without submit flag warning should be thrown"); + Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit flag missing warning should be shown"); + } + + /// + /// Verify that update command warns if submit arguments are provided without submit flag being set. + /// + /// A representing the asynchronous unit test. + [Test] + public async Task UpdateChecksMissingSubmitFlagWithPRTitle() + { + string packageId = "TestPublisher.TestPackageId"; + string version = "1.2.3.4"; - // Clear the string writer - this.sw.GetStringBuilder().Clear(); + UpdateCommand command = new UpdateCommand + { + Id = packageId, + Version = version, + InstallerUrls = new[] { "https://fakedomain.com/fakeinstaller.exe" }, + SubmitToGitHub = false, + PRTitle = "Test PR Title", + }; try { - await command2.Execute(); + await command.Execute(); } catch (Exception) { // Expected exception } - result = this.sw.ToString(); - Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit arguments provided without submit flag warning should be thrown"); + string result = this.sw.ToString(); + Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit flag missing warning should be shown"); } ///