public void TestLoadWrongFile(string configFilePath)
        {
            DefaultConfigUpdater updater = new DefaultConfigUpdater();

            Assert.IsFalse(updater.TryLoad(configFilePath, out string error));
            Assert.IsFalse(string.IsNullOrWhiteSpace(error));
        }
        public void TestMissingPackageUpdate()
        {
            // Load file
            DefaultConfigUpdater updater = CreateAndLoadDefaultConfigUpdater();

            // Update a package that doesn't exist
            Assert.IsFalse(updater.TryUpdatePackage("Some.Package.Nobody.Created", NuGetVersion.Parse("1.2.3"), out _));
            FileSaveResult[] saveResults = updater.Save();
            Assert.IsNotNull(saveResults);
            Assert.AreEqual(0, saveResults.Length);
        }
        private DefaultConfigUpdater CreateAndLoadDefaultConfigUpdater()
        {
            DefaultConfigUpdater updater = new DefaultConfigUpdater();
            string defaultConfigPath     = Path.Combine(Environment.CurrentDirectory, "Assets", "default.config");

            Assert.IsTrue(File.Exists(defaultConfigPath));
            Assert.IsTrue(updater.TryLoad(defaultConfigPath, out string error), error);
            Assert.IsTrue(string.IsNullOrEmpty(error));

            return(updater);
        }
        public void TestDefaultConfigContent(string packageId)
        {
            // Load file
            DefaultConfigUpdater updater = CreateAndLoadDefaultConfigUpdater();

            // Test Content: change a version in default.config or packageconfig, depending on the input
            Assert.IsTrue(updater.TryUpdatePackage(packageId, NuGetVersion.Parse("99.2.3-hello3"), out _));
            FileSaveResult[] saveResults = updater.Save();
            Assert.IsNotNull(saveResults);
            Assert.AreEqual(1, saveResults.Length);

            Assert.IsTrue(saveResults[0].Succeeded);
        }
        public void TestSetCorrectVersionDefaultConfig(string packageId)
        {
            // Load file
            DefaultConfigUpdater updater = CreateAndLoadDefaultConfigUpdater();

            // Test Content
            string versionNumber = Guid.NewGuid().ToString();

            // Edit a package that is inside default.config or .packageconfig depending on the input
            Assert.IsTrue(updater.TryUpdatePackage(packageId, versionNumber, out _));
            FileSaveResult[] saveResults = updater.Save();
            Assert.IsNotNull(saveResults);
            Assert.AreEqual(1, saveResults.Length);

            Assert.IsTrue(saveResults[0].Succeeded);
            Assert.IsTrue(File.ReadAllText(saveResults[0].Path).Contains(versionNumber), "Written version number was not found in the saved file.");
        }
예제 #6
0
        public void TestDownloadTimeout()
        {
            // Generate test default.config
            string testConfig        = @"<?xml version=""1.0"" encoding=""us-ascii""?>
<corext>
	<packages>
		<package id=""runtime.win-x64.Microsoft.NETCore.DotNetAppHost"" version=""unimportant"" link=""path\to\extract"" />
	</packages>
</corext>";
            string defaultConfigPath = Path.GetTempFileName();

            File.WriteAllText(defaultConfigPath, testConfig);

            // Load default.config
            DefaultConfigUpdater defaultConfigUpdater = new DefaultConfigUpdater();
            bool configLoadResult = defaultConfigUpdater.TryLoad(defaultConfigPath, out string error);

            Assert.IsTrue(configLoadResult, "Loading default.config failed.");

            // Load msi.swr
            string        swrPath       = Path.Combine(Environment.CurrentDirectory, "Assets", "msi.swr");
            SwrFileReader swrFileReader = new SwrFileReader(4);

            SwrFile[] loadedSwrFiles = swrFileReader.LoadSwrFiles(Environment.CurrentDirectory);
            SwrFile   swrFile        = loadedSwrFiles.First(s => s.Path == swrPath);

            PropsVariableDeducer variableDeducer = new PropsVariableDeducer("https://api.nuget.org/v3/index.json", null);
            bool operationResult = variableDeducer.DeduceVariableValues(defaultConfigUpdater,
                                                                        new[] { new PackageUpdateResult("runtime.win-x64.Microsoft.NETCore.DotNetAppHost", "unimportant", "3.1.3") },
                                                                        new SwrFile[] { swrFile }, out List <PropsFileVariableReference> results, out string details,

                                                                        // Timeout in zero seconds
                                                                        TimeSpan.FromSeconds(0));

            Assert.IsFalse(operationResult, "Operation should have timed out, but it succeeded.");
            Assert.IsTrue(details.Contains("timed out"));
            Assert.IsTrue(results == null || results.Count == 0, $"No props file should have been updated, {results?.Count} were updated");
        }
예제 #7
0
        public void TestVariableValueDeduce(int maxWaitMilliseconds)
        {
            // Generate test default.config
            string testConfig        = @"<?xml version=""1.0"" encoding=""us-ascii""?>
<corext>
	<packages>
		<package id=""runtime.win-x64.Microsoft.NETCore.DotNetAppHost"" version=""unimportant"" link=""path\to\extract"" />
	</packages>
</corext>";
            string defaultConfigPath = Path.GetTempFileName();

            File.WriteAllText(defaultConfigPath, testConfig);

            // Load default.config
            DefaultConfigUpdater defaultConfigUpdater = new DefaultConfigUpdater();
            bool configLoadResult = defaultConfigUpdater.TryLoad(defaultConfigPath, out string error);

            Assert.IsTrue(configLoadResult, "Loading default.config failed.");

            // Load msi.swr
            string        swrPath       = Path.Combine(Environment.CurrentDirectory, "Assets", "msi.swr");
            SwrFileReader swrFileReader = new SwrFileReader(4);

            SwrFile[] loadedSwrFiles = swrFileReader.LoadSwrFiles(Environment.CurrentDirectory);
            SwrFile   swrFile        = loadedSwrFiles.First(s => s.Path == swrPath);

            PropsVariableDeducer variableDeducer = new PropsVariableDeducer("https://api.nuget.org/v3/index.json", null);
            bool operationResult = variableDeducer.DeduceVariableValues(defaultConfigUpdater,
                                                                        new[] { new PackageUpdateResult("runtime.win-x64.Microsoft.NETCore.DotNetAppHost", "unimportant", "3.1.3") },
                                                                        new SwrFile[] { swrFile }, out List <PropsFileVariableReference> results, out string details, TimeSpan.FromMilliseconds(maxWaitMilliseconds));

            Assert.IsTrue(operationResult, $"Operation failed with message: {details}");
            Assert.IsNotNull(results);
            Assert.IsTrue(results.Any(r => r.ReferencedFilePath == swrPath), "Cannot find the value of variable in given swr.");
            Assert.IsTrue(results.Any(r => r.ReferencedFilePath == swrPath && r.Name == "AspNetCoreTargetingPack30Version"), "Cannot find the correct variable.");
            Assert.IsTrue(results.Any(r => r.ReferencedFilePath == swrPath && r.Name == "AspNetCoreTargetingPack30Version" && r.Value == "apphost"), "Wrong value was found for the variable.");
        }