コード例 #1
0
        public async Task BaselineTest(SharedFxConfig config)
        {
            var previousVersion       = TestData.GetPreviousAspNetCoreReleaseVersion();
            var url                   = new Uri($"https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/" + previousVersion + "/aspnetcore-runtime-internal-" + previousVersion + "-win-x64.zip");
            var zipName               = "assemblies.zip";
            var nugetAssemblyVersions = new Dictionary <string, Version>();
            var dir                   = TestData.GetTestDataValue($"RuntimeAssetsOutputPath:{config.Name}");

            using (var testClient = new WebClient())
            {
                var reporter = new ConsoleReporter(PhysicalConsole.Singleton);
                await RetryHelpers.RetryAsync(async() => await testClient.DownloadFileTaskAsync(url, zipName), reporter);
            }

            var zipPath           = Path.Combine(AppContext.BaseDirectory, zipName);
            var tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                Directory.CreateDirectory(tempDirectoryPath);
                ZipFile.ExtractToDirectory(zipPath, tempDirectoryPath);
                var nugetAssembliesPath = Path.Combine(tempDirectoryPath, "shared", config.Name, previousVersion);


                var files = Directory.GetFiles(nugetAssembliesPath, "*.dll");
                foreach (var file in files)
                {
                    try
                    {
                        var assemblyVersion = AssemblyName.GetAssemblyName(file).Version;
                        var dllName         = Path.GetFileName(file);
                        nugetAssemblyVersions.Add(dllName, assemblyVersion);
                    }
                    catch (BadImageFormatException) { }
                }

                files = Directory.GetFiles(dir, "*.dll");

                Assert.All(files, file =>
                {
                    try
                    {
                        var localAssemblyVersion = AssemblyName.GetAssemblyName(file).Version;
                        var dllName = Path.GetFileName(file);
                        Assert.Contains(dllName, nugetAssemblyVersions.Keys);
                        Assert.InRange(localAssemblyVersion.CompareTo(nugetAssemblyVersions[dllName]), 0, int.MaxValue);
                    }
                    catch (BadImageFormatException) { }
                });
            }
            finally
            {
                Directory.Delete(tempDirectoryPath, true);
            }
        }