winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ConfigureExportCommand.cs (11384B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ConfigureExportCommand.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace AppInstallerCLIE2ETests
      8 {
      9     using System.IO;
     10     using AppInstallerCLIE2ETests.Helpers;
     11     using NUnit.Framework;
     12     using NUnit.Framework.Internal;
     13 
     14     /// <summary>
     15     /// `Configure export` command tests.
     16     /// </summary>
     17     public class ConfigureExportCommand
     18     {
     19         private const string Command = "configure export";
     20         private const string ShowCommand = "configure show";
     21 
     22         private string previousPathValue = string.Empty;
     23 
     24         /// <summary>
     25         /// Set up.
     26         /// </summary>
     27         [OneTimeSetUp]
     28         public void BaseSetup()
     29         {
     30             TestCommon.SetupTestSource(false);
     31             var installDir = TestCommon.GetRandomTestDir();
     32             TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestPackageExport -v 1.0.0.0 --silent -l {installDir}");
     33             this.previousPathValue = System.Environment.GetEnvironmentVariable("PATH");
     34             System.Environment.SetEnvironmentVariable("PATH", this.previousPathValue + ";" + installDir);
     35             DSCv3ResourceTestBase.EnsureTestResourcePresence();
     36         }
     37 
     38         /// <summary>
     39         /// Tear down.
     40         /// </summary>
     41         [OneTimeTearDown]
     42         public void BaseTeardown()
     43         {
     44             TestCommon.RunAICLICommand("uninstall", "AppInstallerTest.TestPackageExport");
     45             TestCommon.TearDownTestSource();
     46             if (!string.IsNullOrEmpty(this.previousPathValue))
     47             {
     48                 System.Environment.SetEnvironmentVariable("PATH", this.previousPathValue);
     49             }
     50         }
     51 
     52         /// <summary>
     53         /// Export a specific package.
     54         /// </summary>
     55         [Test]
     56         public void ExportTestPackage()
     57         {
     58             var exportDir = TestCommon.GetRandomTestDir();
     59             var exportFile = Path.Combine(exportDir, "exported.yml");
     60             var result = TestCommon.RunAICLICommand(Command, $"--package-id AppInstallerTest.TestPackageExport -o {exportFile}");
     61             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     62             Assert.True(File.Exists(exportFile));
     63 
     64             // Check exported file is readable and validate content
     65             var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}");
     66             Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
     67             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
     68             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
     69             Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
     70             Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
     71             Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
     72 
     73             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
     74             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
     75             Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
     76             Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
     77             Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
     78         }
     79 
     80         /// <summary>
     81         /// Export a specific package with related configuration.
     82         /// </summary>
     83         [Test]
     84         public void ExportTestPackageWithPackageSettings()
     85         {
     86             var exportDir = TestCommon.GetRandomTestDir();
     87             var exportFile = Path.Combine(exportDir, "exported.yml");
     88             var result = TestCommon.RunAICLICommand(Command, $"--package-id AppInstallerTest.TestPackageExport --module AppInstallerTest --resource TestResource -o {exportFile}");
     89             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     90             Assert.True(File.Exists(exportFile));
     91 
     92             // Check exported file is readable and validate content
     93             var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}");
     94             Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
     95             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
     96             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
     97             Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
     98             Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
     99             Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
    100 
    101             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
    102             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
    103             Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
    104             Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
    105             Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
    106 
    107             Assert.True(showResult.StdOut.Contains("AppInstallerTest/TestResource"));
    108             Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_AppInstallerTest.TestPackageExport"));
    109             Assert.True(showResult.StdOut.Contains("data: TestData"));
    110         }
    111 
    112         /// <summary>
    113         /// Export a specific package with version.
    114         /// </summary>
    115         [Test]
    116         public void ExportTestPackageWithVersion()
    117         {
    118             var exportDir = TestCommon.GetRandomTestDir();
    119             var exportFile = Path.Combine(exportDir, "exported.yml");
    120             var result = TestCommon.RunAICLICommand(Command, $"--package-id AppInstallerTest.TestPackageExport --include-versions -o {exportFile}");
    121             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    122             Assert.True(File.Exists(exportFile));
    123 
    124             // Check exported file is readable and validate content
    125             var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}");
    126             Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
    127             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
    128             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
    129             Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
    130             Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
    131             Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
    132 
    133             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
    134             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
    135             Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
    136             Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
    137             Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
    138             Assert.True(showResult.StdOut.Contains("version: 1.0.0.0"));
    139         }
    140 
    141         /// <summary>
    142         /// Export all.
    143         /// </summary>
    144         [Test]
    145         public void ExportAll()
    146         {
    147             var exportDir = TestCommon.GetRandomTestDir();
    148             var exportFile = Path.Combine(exportDir, "exported.yml");
    149             var result = TestCommon.RunAICLICommand(Command, $"--all -o {exportFile}", timeOut: 1200000);
    150             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    151             Assert.True(File.Exists(exportFile));
    152 
    153             // Check exported file is readable and validate content
    154             var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}", timeOut: 1200000);
    155             Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
    156 
    157             Assert.True(showResult.StdOut.Contains("Microsoft.PowerShell"));
    158 
    159             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/UserSettingsFile"));
    160             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/AdminSettings"));
    161             Assert.True(showResult.StdOut.Contains("Microsoft.Windows.Settings/WindowsSettings"));
    162 
    163             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
    164             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
    165             Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
    166             Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
    167             Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
    168 
    169             Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
    170             Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
    171             Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
    172             Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
    173             Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
    174 
    175             Assert.True(showResult.StdOut.Contains("AppInstallerTest/TestResource"));
    176             Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_AppInstallerTest.TestPackageExport"));
    177             Assert.True(showResult.StdOut.Contains("data: TestData"));
    178         }
    179 
    180         /// <summary>
    181         /// Export a specific package that's not installed.
    182         /// </summary>
    183         [Test]
    184         public void ExportFailedWithNotFoundPackage()
    185         {
    186             var exportDir = TestCommon.GetRandomTestDir();
    187             var exportFile = Path.Combine(exportDir, "exported.yml");
    188             var result = TestCommon.RunAICLICommand(Command, $"--package-id NotFound.NotFound -o {exportFile}");
    189             Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode);
    190         }
    191 
    192         /// <summary>
    193         /// Export all with specific package id.
    194         /// </summary>
    195         [Test]
    196         public void ExportFailedWithAllAndSpecificPackage()
    197         {
    198             var exportDir = TestCommon.GetRandomTestDir();
    199             var exportFile = Path.Combine(exportDir, "exported.yml");
    200             var result = TestCommon.RunAICLICommand(Command, $"--all --package-id AppInstallerTest.TestPackageExport -o {exportFile}");
    201             Assert.AreEqual(Constants.ErrorCode.ERROR_INVALID_CL_ARGUMENTS, result.ExitCode);
    202         }
    203     }
    204 }