Exemplo n.º 1
0
        public async Task TestOptimizeSnapDllForPackageArchive(string osPlatformStr)
        {
            var osPlatform = OSPlatform.Create(osPlatformStr);

            using var snapDllAssemblyDefinition = await _snapFilesystem.FileReadAssemblyDefinitionAsync(typeof(SnapAppWriter).Assembly.Location, CancellationToken.None);

            using var optimizedAssemblyDefinition = _snapAppWriter.OptimizeSnapDllForPackageArchive(snapDllAssemblyDefinition, osPlatform);
            Assert.NotNull(optimizedAssemblyDefinition);

            var optimizedAssembly = Assembly.Load(optimizedAssemblyDefinition.ToByteArray());

            // Assembly is rewritten so we have to use a dynamic cast :(

            var optimizedAssembltType = optimizedAssembly.GetType(typeof(SnapEmbeddedResources).FullName
                                                                  ?? throw new InvalidOperationException(), true);

            var optimizedEmbeddedResources = (dynamic)Activator.CreateInstance
                                                 (optimizedAssembltType ?? throw new InvalidOperationException(), true);

            Assert.NotNull(optimizedEmbeddedResources);

            Assert.True((bool)optimizedEmbeddedResources.IsOptimized);

            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunWindowsX86));
            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunLibWindowsX86));

            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunWindowsX64));
            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunLibWindowsX64));

            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunLinuxX64));
            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunLibLinuxX64));

            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunLinuxArm64));
            Assert.Throws <FileNotFoundException>(() => object.ReferenceEquals(null, optimizedEmbeddedResources.CoreRunLibLinuxArm64));
        }