winget-cli

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

ConfigureListCommand.cs (4734B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ConfigureListCommand.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 
     13     /// <summary>
     14     /// `Configure list` command tests.
     15     /// </summary>
     16     public class ConfigureListCommand
     17     {
     18         private const string ConfigureWithAgreementsAndVerbose = "configure --accept-configuration-agreements --verbose";
     19         private const string ConfigureTestRepoFile = "Configure_TestRepo.yml";
     20 
     21         /// <summary>
     22         /// Teardown done once after all the tests here.
     23         /// </summary>
     24         [OneTimeTearDown]
     25         public void OneTimeTeardown()
     26         {
     27             this.DeleteTxtFiles();
     28         }
     29 
     30         /// <summary>
     31         /// Applies a configuration, then verifies that it is in the overall list.
     32         /// </summary>
     33         [Test]
     34         public void ListAllConfigurations()
     35         {
     36             var result = TestCommon.RunAICLICommand(ConfigureWithAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
     37             Assert.AreEqual(0, result.ExitCode);
     38 
     39             result = TestCommon.RunAICLICommand("configure list", "--verbose");
     40             Assert.AreEqual(0, result.ExitCode);
     41             Assert.True(result.StdOut.Contains(ConfigureTestRepoFile));
     42         }
     43 
     44         /// <summary>
     45         /// Applies a configuration (to ensure at least one exists), gets the overall list, then the details about the first configuration.
     46         /// </summary>
     47         [Test]
     48         public void ListSpecificConfiguration()
     49         {
     50             var result = TestCommon.RunAICLICommand(ConfigureWithAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
     51             Assert.AreEqual(0, result.ExitCode);
     52 
     53             string guid = TestCommon.GetConfigurationInstanceIdentifierFor(ConfigureTestRepoFile);
     54             result = TestCommon.RunAICLICommand("configure list", $"-h {guid}");
     55             Assert.AreEqual(0, result.ExitCode);
     56             Assert.True(result.StdOut.Contains(guid));
     57             Assert.True(result.StdOut.Contains(ConfigureTestRepoFile));
     58         }
     59 
     60         /// <summary>
     61         /// Applies a configuration (to ensure at least one exists), gets the overall list, then the removes the first configuration.
     62         /// </summary>
     63         [Test]
     64         public void RemoveConfiguration()
     65         {
     66             var result = TestCommon.RunAICLICommand(ConfigureWithAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
     67             Assert.AreEqual(0, result.ExitCode);
     68 
     69             string guid = TestCommon.GetConfigurationInstanceIdentifierFor(ConfigureTestRepoFile);
     70             result = TestCommon.RunAICLICommand("configure list", $"-h {guid} --remove");
     71             Assert.AreEqual(0, result.ExitCode);
     72 
     73             result = TestCommon.RunAICLICommand("configure list", "--verbose");
     74             Assert.AreEqual(0, result.ExitCode);
     75             Assert.False(result.StdOut.Contains(guid));
     76         }
     77 
     78         /// <summary>
     79         /// Applies a configuration (to ensure at least one exists), gets the overall list, then the outputs the first configuration.
     80         /// </summary>
     81         [Test]
     82         public void OutputConfiguration()
     83         {
     84             var result = TestCommon.RunAICLICommand(ConfigureWithAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
     85             Assert.AreEqual(0, result.ExitCode);
     86 
     87             string guid = TestCommon.GetConfigurationInstanceIdentifierFor(ConfigureTestRepoFile);
     88             string tempFile = TestCommon.GetRandomTestFile(".yml");
     89             result = TestCommon.RunAICLICommand("configure list", $"-h {guid} --output {tempFile}");
     90             Assert.AreEqual(0, result.ExitCode);
     91 
     92             result = TestCommon.RunAICLICommand("configure validate", $"--verbose {tempFile}");
     93             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
     94         }
     95 
     96         private void DeleteTxtFiles()
     97         {
     98             // Delete all .txt files in the test directory; they are placed there by the tests
     99             foreach (string file in Directory.GetFiles(TestCommon.GetTestDataFile("Configuration"), "*.txt"))
    100             {
    101                 File.Delete(file);
    102             }
    103         }
    104     }
    105 }