Exemplo n.º 1
0
        public void PortingProjectSucceeds()
        {
            var result = _portingHandler.ApplyPortProjectFileChanges
                         (
                new List <string> {
                _tmpProjectPath
            },
                _tmpSolutionDirectory,
                "netcoreapp3.1.0",
                new Dictionary <string, string> {
                { "Newtonsoft.Json", "12.0.3" }
            });

            Assert.True(result[0].Success);
            Assert.AreEqual(_tmpProjectPath, result[0].ProjectFile);
            Assert.AreEqual("Nop.Core", result[0].ProjectName);

            var portResult = GetProjects(Path.Combine(_tmpSolutionDirectory, "NopCommerce.sln")).Find(package => package.ProjectName == "Nop.Core");

            Assert.AreEqual(_tmpProjectPath, portResult.ProjectFilePath);
            Assert.AreEqual(".NETCoreApp 3.1.0", portResult.TargetFrameworks[0]);
            Assert.AreEqual(
                new PackageVersionPair
            {
                PackageId = "Newtonsoft.Json",
                Version   = "12.0.3"
            },
                portResult.PackageReferences.Find(nugetPackage => nugetPackage.PackageId == "Newtonsoft.Json"));
        }
        public void PortingProjectSucceedsWithOriginalVerson()
        {
            var result = _portingHandler.ApplyPortProjectFileChanges
                         (
                GetProjects(_tmpSolutionFileName),
                _tmpSolutionFileName,
                "netcoreapp3.1",
                new Dictionary <string, Tuple <string, string> > {
                { "Newtonsoft.Json", new Tuple <string, string>("9.0.0", "12.0.3") }
            });

            Assert.True(result[0].Success);
            Assert.AreEqual(_tmpProjectPath, result[0].ProjectFile);
            Assert.AreEqual("Nop.Core", result[0].ProjectName);

            var portResult = GetProjects(_tmpSolutionFileName).Find(package => package.ProjectName == "Nop.Core");

            Assert.AreEqual(_tmpProjectPath, portResult.ProjectFilePath);
            Assert.AreEqual(".NETCoreApp 3.1.0", portResult.TargetFrameworks[0]);
            Assert.AreEqual(
                new PackageVersionPair
            {
                PackageId = "Newtonsoft.Json",
                Version   = "12.0.3"
            },
                portResult.PackageReferences.Find(nugetPackage => nugetPackage.PackageId == "Newtonsoft.Json"));
        }
Exemplo n.º 3
0
        public List <PortingResult> ApplyPortingChanges(PortingRequest request)
        {
            try
            {
                var upgradeVersions = request.RecommendedActions
                                      .Where(r => r.RecommendedActionType == RecommendedActionType.UpgradePackage)
                                      .Select(recommendation =>
                {
                    var packageRecommendation = (PackageRecommendation)recommendation;
                    return(new Tuple <string, Tuple <string, string> >(packageRecommendation.PackageId, new Tuple <string, string>(packageRecommendation.Version, packageRecommendation.TargetVersions.First())));
                })
                                      .GroupBy(t => t.Item1).Select(t => t.FirstOrDefault())
                                      .ToDictionary(t => t.Item1, t => t.Item2);

                return(_portingHandler.ApplyPortProjectFileChanges(
                           request.Projects,
                           request.SolutionPath,
                           request.TargetFramework,
                           request.IncludeCodeFix,
                           upgradeVersions));
            }
            catch (Exception ex)
            {
                throw new PortingAssistantException("Could not apply porting changes", ex);
            }
        }