winget-cli

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

ManifestUnitTests.cs (7148B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ManifestUnitTests.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace WinGetUtilInterop.UnitTests.APIUnitTests
      8 {
      9     using System.Collections.Generic;
     10     using System.IO;
     11     using System.Linq;
     12     using System.Reflection;
     13     using Microsoft.WinGetUtil.Api;
     14     using Microsoft.WinGetUtil.Common;
     15     using Microsoft.WinGetUtil.Manifest.V1;
     16     using Microsoft.WinGetUtil.Models.V1;
     17     using WinGetUtilInterop.UnitTests.Common;
     18     using Xunit;
     19     using Xunit.Abstractions;
     20 
     21     /// <summary>
     22     /// API manifests tests.
     23     /// </summary>
     24     public class ManifestUnitTests
     25     {
     26         private static string testCollateralDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestCollateral");
     27         private readonly ITestOutputHelper log;
     28 
     29         /// <summary>
     30         /// Initializes a new instance of the <see cref="ManifestUnitTests"/> class.
     31         /// </summary>
     32         /// <param name="log">Output Helper.</param>
     33         public ManifestUnitTests(ITestOutputHelper log)
     34         {
     35             this.log = log;
     36         }
     37 
     38         /// <summary>
     39         /// Test creating a manifest with shadow.
     40         /// </summary>
     41         [FactSkipx64CI]
     42         public void CreateShadowManifest()
     43         {
     44             var input = Path.Combine(testCollateralDir, "Shadow");
     45             var mergedManifestPath = Path.GetTempFileName();
     46             var logFile = Path.GetTempFileName();
     47 
     48             var factory = new WinGetFactory();
     49             using var log = factory.LoggingInit(logFile);
     50             using var result = factory.CreateManifest(
     51                 input,
     52                 mergedManifestPath,
     53                 WinGetCreateManifestOption.SchemaAndSemanticValidation | WinGetCreateManifestOption.AllowShadowManifest);
     54 
     55             Assert.NotNull(result);
     56             Assert.True(result.IsValid);
     57             Assert.NotNull(result.ManifestHandle);
     58 
     59             var manifest = Manifest.CreateManifestFromPath(mergedManifestPath);
     60 
     61             Assert.Equal("microsoft.msixsdk", manifest.Id);
     62             Assert.Equal("1.7.32", manifest.Version);
     63             Assert.Single(manifest.Installers);
     64             Assert.Equal("en-US", manifest.PackageLocale);
     65             Assert.Equal("Microsoft", manifest.Publisher);
     66             Assert.Equal("MSIX SDK", manifest.PackageName);
     67             Assert.Equal("MIT License", manifest.License);
     68             Assert.Equal("The MSIX SDK project is an effort to enable developers", manifest.Description);
     69             Assert.Equal("This is MSIX SDK", manifest.ShortDescription);
     70 
     71             Assert.Single(manifest.Icons);
     72             Assert.Equal("https://shadowIcon-default", manifest.Icons[0].IconUrl);
     73             Assert.Equal("ico", manifest.Icons[0].IconFileType);
     74             Assert.Equal("custom", manifest.Icons[0].IconResolution);
     75             Assert.Equal("default", manifest.Icons[0].IconTheme);
     76             Assert.Equal("1111111111111111111111111111111111111111111111111111111111111111", manifest.Icons[0].IconSha256);
     77 
     78             Assert.Equal(2, manifest.Localization.Count);
     79 
     80             var enGBLocale = manifest.Localization.Where(l => l.PackageLocale == "en-gb").FirstOrDefault();
     81             Assert.NotNull(enGBLocale);
     82             Assert.Single(enGBLocale.Icons);
     83             Assert.Equal("https://shadowIcon-en-GB", enGBLocale.Icons[0].IconUrl);
     84             Assert.Equal("png", enGBLocale.Icons[0].IconFileType);
     85             Assert.Equal("32x32", enGBLocale.Icons[0].IconResolution);
     86             Assert.Equal("light", enGBLocale.Icons[0].IconTheme);
     87             Assert.Equal("2222222222222222222222222222222222222222222222222222222222222222", enGBLocale.Icons[0].IconSha256);
     88 
     89             var frFRLocale = manifest.Localization.Where(l => l.PackageLocale == "fr-FR").FirstOrDefault();
     90             Assert.NotNull(frFRLocale);
     91             Assert.Single(frFRLocale.Icons);
     92             Assert.Equal("https://shadowIcon-fr-FR", frFRLocale.Icons[0].IconUrl);
     93             Assert.Equal("jpeg", frFRLocale.Icons[0].IconFileType);
     94             Assert.Equal("20x20", frFRLocale.Icons[0].IconResolution);
     95             Assert.Equal("dark", frFRLocale.Icons[0].IconTheme);
     96             Assert.Equal("3333333333333333333333333333333333333333333333333333333333333333", frFRLocale.Icons[0].IconSha256);
     97         }
     98 
     99         /// <summary>
    100         /// Test serializing the shadow manifest.
    101         /// </summary>
    102         [Fact]
    103         public void SerializeShadowManifest()
    104         {
    105             var shadowManifest = ManifestShadow.CreateManifest();
    106             shadowManifest.Id = "Package.package";
    107             shadowManifest.Version = "1.0";
    108             shadowManifest.PackageLocale = "en-US";
    109             shadowManifest.ManifestVersion = "1.5";
    110             shadowManifest.Icons = new List<ManifestIcon>
    111             {
    112                 new ManifestIcon()
    113                 {
    114                     IconUrl = "iconUrl",
    115                     IconFileType = "fileType",
    116                     IconResolution = "iconResolution",
    117                     IconTheme = "iconTheme",
    118                     IconSha256 = "iconSha256",
    119                 },
    120             };
    121             shadowManifest.Localization = new List<ManifestShadowLocalization>
    122             {
    123                 new ManifestShadowLocalization()
    124                 {
    125                     PackageLocale = "es-MX",
    126                     Icons = new List<ManifestIcon>()
    127                     {
    128                         new ManifestIcon()
    129                         {
    130                             IconUrl = "iconUrl-esMX",
    131                             IconFileType = "fileType-esMX",
    132                             IconResolution = "iconResolution-esMX",
    133                             IconTheme = "iconTheme-esMX",
    134                             IconSha256 = "iconSha256-esMX",
    135                         },
    136                     },
    137                 },
    138                 new ManifestShadowLocalization()
    139                 {
    140                     PackageLocale = "de-DE",
    141                     Icons = new List<ManifestIcon>()
    142                     {
    143                         new ManifestIcon()
    144                         {
    145                             IconUrl = "iconUrl-de-DE",
    146                             IconFileType = "fileType-de-DE",
    147                             IconResolution = "iconResolution-de-DE",
    148                             IconTheme = "iconTheme-de-DE",
    149                             IconSha256 = "iconSha256-de-DE",
    150                         },
    151                     },
    152                 },
    153             };
    154 
    155             var serialized = shadowManifest.Serialize();
    156             Assert.Equal(File.ReadAllText(Path.Combine(testCollateralDir, "ExpectedShadowManifest.yaml")), serialized);
    157             this.log.WriteLine(serialized);
    158         }
    159     }
    160 }