public void UpgradesPackage()
        {
            // Arrange
            var sut     = new LeanSchemeProcessor();
            var tracing = new TestTracing();
            var project = TestFixtureHelper.CreateNuGetProject(VisualStudioProjectScheme.Lean, TestVersion.Low, TestPackage.One, new Dictionary <string, string>
            {
                { "TestPackage.One", "3.0.0" }
            });

            // Act
            var result = sut.InstallPackages(
                project.Content,
                project.RequestedPackages,
                project.InstalledPackages,
                project.Name,
                tracing);

            // Assert
            Assert.Equal(
                expected:
                @"<Project Sdk=""Microsoft.NET.Sdk"">

  <ItemGroup>
    <PackageReference Include=""TestPackage.One"" Version=""3.0.0"" />
  </ItemGroup>

</Project>",
                actual: result);
        }
        public void SortsPackageReferencesInAlphabeticalOrder(TestPackage existingPackage, TestPackage testPackageToInstall)
        {
            // Arrange
            var sut     = new LeanSchemeProcessor();
            var tracing = new TestTracing();
            var project = TestFixtureHelper.CreateNuGetProject(VisualStudioProjectScheme.Lean, TestVersion.Low, existingPackage, new Dictionary <string, string>
            {
                { $"{nameof(TestPackage)}.{testPackageToInstall}", "1.0.0" }
            });

            // Act
            var result = sut.InstallPackages(
                project.Content,
                project.RequestedPackages,
                project.InstalledPackages,
                project.Name,
                tracing);

            // Assert
            Assert.Equal(
                expected:
                @"<Project Sdk=""Microsoft.NET.Sdk"">

  <ItemGroup>
    <PackageReference Include=""TestPackage.One"" Version=""1.0.0"" />
    <PackageReference Include=""TestPackage.Two"" Version=""1.0.0"" />
  </ItemGroup>

</Project>",
                actual: result);
        }
        public void UpgradesPackage()
        {
            // Arrange
            var sut     = new VerboseWithPackageReferencesSchemeProcessor();
            var tracing = new TestTracing();
            var project = TestFixtureHelper.CreateNuGetProject(VisualStudioProjectScheme.VerboseWithPackageReference, TestVersion.Low, TestPackage.One, nugetPackagesToInstall: new Dictionary <string, string>
            {
                { "TestPackage.One", "3.0.0" }
            });

            // Act
            var result = sut.InstallPackages(
                project.Content,
                project.RequestedPackages,
                project.InstalledPackages,
                project.Name,
                tracing);

            // Assert
            Assert.Equal(
                expected:
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup>
    <PackageReference Include=""TestPackage.One"">
      <Version>3.0.0</Version>
    </PackageReference>
  </ItemGroup>
</Project>",
                actual: result);
        }
예제 #4
0
        public void ConsolidateInstallsVersionsToHighestExisting()
        {
            // Arrange
            var tracing  = new TestTracing();
            var sut      = TestFixtureHelper.GetNuGetInstaller(true, false);
            var saved    = new List <(string path, string content)>();
            var project1 = TestFixtureHelper.CreateProject(VisualStudioProjectScheme.Lean, TestVersion.High, TestPackage.One, new Dictionary <string, string>());
            var project2 = TestFixtureHelper.CreateProject(VisualStudioProjectScheme.Lean, TestVersion.High, TestPackage.Two, new Dictionary <string, string>
            {
                { "TestPackage.One", "1.0.0" }
            });
            var projects = new[] { project1, project2 };

            // Act
            sut.Execute(projects, tracing, (path, content) => saved.Add((path, content)));

            // Assert
            Assert.Collection(saved, nuGetProject =>
            {
                Assert.Equal(project2.FilePath, nuGetProject.path);
                Assert.Equal(
                    XDocument.Parse(
                        @"<Project Sdk=""Microsoft.NET.Sdk"">

  <ItemGroup>
    <PackageReference Include=""TestPackage.One"" Version=""2.0.0"" />
    <PackageReference Include=""TestPackage.Two"" Version=""2.0.0"" />
  </ItemGroup>

</Project>", LoadOptions.PreserveWhitespace).ToString(),
                    nuGetProject.content);
            });
        }
예제 #5
0
        public void SortsPackageReferencesInAlphabeticalOrder(TestPackage existingPackage, TestPackage testPackageToInstall)
        {
            // Arrange
            var sut     = new VerboseWithPackageReferencesSchemeProcessor();
            var tracing = new TestTracing();
            var project = TestFixtureHelper.CreateNuGetProject(NuGetScheme.VerboseWithPackageReference, TestVersion.Low, existingPackage, new Dictionary <string, string>
            {
                { $"{nameof(TestPackage)}.{testPackageToInstall}", "1.0.0" }
            });

            // Act
            var result = sut.InstallPackages(
                project.Content,
                project.RequestedPackages,
                project.InstalledPackages,
                project.Name,
                tracing);

            // Assert
            Assert.Equal(
                expected:
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup>
    <PackageReference Include=""TestPackage.One"">
      <Version>1.0.0</Version>
    </PackageReference>
    <PackageReference Include=""TestPackage.Two"">
      <Version>1.0.0</Version>
    </PackageReference>
  </ItemGroup>
</Project>",
                actual: result);
        }
예제 #6
0
        public void GetInstalledPackagesReturnsEmptyCollection()
        {
            // Arrange
            var sut     = new UnsupportedSchemeProcessor();
            var project = TestFixtureHelper.CreateProject(VisualStudioProjectScheme.Unsupported, TestVersion.Low, TestPackage.One, new Dictionary <string, string>());

            // Act
            var installedPackages = sut.GetInstalledPackages(project.FilePath, null);

            // Assert
            Assert.Empty(installedPackages);
        }
예제 #7
0
        public void ResolvesCorrectly(object untypedNuGetScheme)
        {
            var nuGetScheme = (VisualStudioProjectScheme)untypedNuGetScheme;

            // Arrange
            var project  = TestFixtureHelper.CreateProject(nuGetScheme, TestVersion.High, TestPackage.One, new Dictionary <string, string>());
            var document = XDocument.Load(project.FilePath);

            // Act
            var result = document.ResolveProjectScheme();

            // Assert
            Assert.Equal(nuGetScheme, result);
        }
예제 #8
0
        public void ResolvesCorrectly(object untypedNuGetScheme)
        {
            var nuGetScheme = (NuGetScheme)untypedNuGetScheme;

            // Arrange
            var project  = TestFixtureHelper.CreateProject(nuGetScheme, TestVersion.High, TestPackage.One, new Dictionary <string, string>());
            var document = XDocument.Load(project.ProjectFile());

            // Act
            var result = NugetInstallerFactoryExtension.ResolveNuGetScheme(document.Root);

            // Assert
            Assert.Equal(nuGetScheme, result);
        }
        public void GetsInstalledPackages()
        {
            // Arrange
            var sut     = new LeanSchemeProcessor();
            var project = TestFixtureHelper.CreateProject(VisualStudioProjectScheme.Lean, TestVersion.Low, TestPackage.One, new Dictionary <string, string>());
            var doc     = XDocument.Load(project.FilePath);

            // Act
            var installedPackages = sut.GetInstalledPackages(project.FilePath, doc);

            // Assert
            Assert.Collection(installedPackages, x =>
            {
                Assert.Equal("TestPackage.One", x.Key);
                Assert.Equal(x.Value.Version, VersionRange.Parse("1.0.0"));
            });
        }
예제 #10
0
        public void ConsolidatationNotTriggeredWhenVersionsAreTheSame()
        {
            // Arrange
            var tracing  = new TestTracing();
            var sut      = TestFixtureHelper.GetNuGetInstaller(true, false);
            var projects = new[]
            {
                TestFixtureHelper.CreateProject(VisualStudioProjectScheme.Lean, TestVersion.High, TestPackage.One, new Dictionary <string, string>()),
                TestFixtureHelper.CreateProject(VisualStudioProjectScheme.Lean, TestVersion.High, TestPackage.One, new Dictionary <string, string>()),
            };

            // Act
            sut.Execute(projects, tracing, (filePath, content) => { });

            // Assert
            Assert.Empty(tracing.InfoEntries);
        }
예제 #11
0
        public void GetsInstalledPackages()
        {
            // Arrange
            var sut     = new VerboseWithPackageReferencesSchemeProcessor();
            var project = TestFixtureHelper.CreateProject(NuGetScheme.VerboseWithPackageReference, TestVersion.Low, TestPackage.One, new Dictionary <string, string>());
            var doc     = XDocument.Load(project.ProjectFile());

            // Act
            var installedPackages = sut.GetInstalledPackages(project, doc);

            // Assert
            Assert.Collection(installedPackages, x =>
            {
                Assert.Equal("TestPackage.One", x.Key);
                Assert.Equal(x.Value.Version, SemanticVersion.Parse("1.0.0"));
            });
        }
        public void UpgradePackageCreatesWarning()
        {
            // Arrange
            var sut     = new VerboseWithPackagesDotConfigSchemeProcessor();
            var tracing = new TestTracing();
            var project = TestFixtureHelper.CreateNuGetProject(VisualStudioProjectScheme.VerboseWithPackagesDotConfig, TestVersion.Low, TestPackage.One, nugetPackagesToInstall: new Dictionary <string, string>
            {
                { "TestPackage.One", "3.0.0" }
            });

            // Act
            sut.InstallPackages(
                project.Content,
                project.RequestedPackages,
                project.InstalledPackages,
                project.Name,
                tracing);

            // Assert
            Assert.Collection(tracing.WarningEntries,
                              element => Assert.Contains(
                                  "https://blog.nuget.org/20180409/migrate-packages-config-to-package-reference.html",
                                  element));
        }
예제 #13
0
        public void UpgradePackageCreatesWarning()
        {
            // Arrange
            var sut     = new UnsupportedSchemeProcessor();
            var tracing = new TestTracing();
            var project = TestFixtureHelper.CreateNuGetProject(VisualStudioProjectScheme.Unsupported, TestVersion.Low, TestPackage.One, nugetPackagesToInstall: new Dictionary <string, string>
            {
                { "TestPackage.One", "3.0.0" }
            });

            // Act
            sut.InstallPackages(
                project.Content,
                project.RequestedPackages,
                project.InstalledPackages,
                project.Name,
                tracing);

            // Assert
            Assert.Collection(tracing.DebugEntries,
                              element => Assert.Contains(
                                  "Skipped",
                                  element));
        }