winget-cli

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

WinGetUtilInstallerMetadataCollection.cs (3824B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="WinGetUtilInstallerMetadataCollection.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace AppInstallerCLIE2ETests.WinGetUtil
      8 {
      9     using System;
     10     using System.IO;
     11     using System.Runtime.InteropServices;
     12     using AppInstallerCLIE2ETests.Helpers;
     13     using Newtonsoft.Json;
     14     using NUnit.Framework;
     15 
     16     /// <summary>
     17     /// Test winget util installer metadata.
     18     /// </summary>
     19     public class WinGetUtilInstallerMetadataCollection
     20     {
     21         /// <summary>
     22         /// Test begin complete installer metadata.
     23         /// </summary>
     24         [Test]
     25         public void WinGetUtil_BeginCompleteInstallerMetadataCollection()
     26         {
     27             string logFilePath = TestCommon.GetRandomTestFile(".log");
     28             string inputJson = TestCommon.GetTestDataFile(@"WinGetUtil\InstallerMetadata\Minimal.json");
     29             string outputFilePath = TestCommon.GetRandomTestFile(".json");
     30 
     31             WinGetUtilWrapper.WinGetBeginInstallerMetadataCollection(
     32                 inputJson,
     33                 logFilePath,
     34                 WinGetUtilWrapper.WinGetBeginInstallerMetadataCollectionOptions.WinGetBeginInstallerMetadataCollectionOption_InputIsFilePath,
     35                 out IntPtr collectionHandle);
     36 
     37             Assert.AreNotEqual(IntPtr.Zero, collectionHandle);
     38             Assert.True(File.Exists(logFilePath));
     39 
     40             WinGetUtilWrapper.WinGetCompleteInstallerMetadataCollection(
     41                 collectionHandle,
     42                 outputFilePath,
     43                 WinGetUtilWrapper.WinGetCompleteInstallerMetadataCollectionOptions.WinGetCompleteInstallerMetadataCollectionOption_None);
     44 
     45             string outputJson = File.ReadAllText(outputFilePath);
     46             Assert.IsNotEmpty(JsonConvert.DeserializeObject(outputJson).ToString());
     47         }
     48 
     49         /// <summary>
     50         /// Test merge installer metadata.
     51         /// </summary>
     52         [Test]
     53         public void WinGetUtil_MergeInstallerMetadata_Success()
     54         {
     55             string logFilePath = TestCommon.GetRandomTestFile(".log");
     56             string inputJsonPath = TestCommon.GetTestDataFile(@"WinGetUtil\InstallerMetadata\MergeValid.json");
     57             string inputJson = File.ReadAllText(inputJsonPath);
     58 
     59             WinGetUtilWrapper.WinGetMergeInstallerMetadata(
     60                inputJson,
     61                out string outputJson,
     62                0,
     63                logFilePath,
     64                WinGetUtilWrapper.WinGetMergeInstallerMetadataOptions.WinGetMergeInstallerMetadataOptions_None);
     65 
     66             Assert.True(File.Exists(logFilePath));
     67             Assert.IsNotEmpty(JsonConvert.DeserializeObject(outputJson).ToString());
     68         }
     69 
     70         /// <summary>
     71         /// Test merge installer metadata failed.
     72         /// </summary>
     73         [Test]
     74         public void WinGetUtil_MergeInstallerMetadata_Fail_SubmissionMismatch()
     75         {
     76             string logFilePath = TestCommon.GetRandomTestFile(".log");
     77             string inputJsonPath = TestCommon.GetTestDataFile(@"WinGetUtil\InstallerMetadata\MergeSubmissionMismatch.json");
     78             string inputJson = File.ReadAllText(inputJsonPath);
     79 
     80             Assert.Throws<COMException>(() =>
     81             {
     82                 WinGetUtilWrapper.WinGetMergeInstallerMetadata(
     83                    inputJson,
     84                    out string outputJson,
     85                    0,
     86                    logFilePath,
     87                    WinGetUtilWrapper.WinGetMergeInstallerMetadataOptions.WinGetMergeInstallerMetadataOptions_None);
     88             });
     89 
     90             Assert.True(File.Exists(logFilePath));
     91         }
     92     }
     93 }