示例#1
0
        public void UpdatePackageToSpecificVersion()
        {
            // arrange
            NuGetManager nuget = new NuGetManager();
            var nugetSources = AbsolutePath(@"LocalizedNugetPackage");

            nuget.InstallPackages(
                _appInfo.PhysicalPath,
                new List<PackageName>
                    {
                        new PackageName("LocalizedNugetPackage", new SemanticVersion("1.0"))
                    },
                nugetSources);


            // act
            nuget.UpdatePackages(
                _appInfo.PhysicalPath,
                new List<PackageName>
                    {
                        new PackageName("LocalizedNugetPackage", new SemanticVersion("2.0.0"))
                    },
                nugetSources);

            // assert
            var expectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.2.0.0");
            Assert.IsTrue(Directory.Exists(expectedPackageInstallDir));
            var notExpectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.1.0.0");
            Assert.IsFalse(Directory.Exists(notExpectedPackageInstallDir));
        }
示例#2
0
            public void PackageNameIsEmpty_Throws()
            {
                var manager = new NuGetManager();

                var ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage("DummyPath", null));
                Assert.Contains("packageName", ex.Message);

                ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage("DummyPath", string.Empty));
                Assert.Contains("packageName", ex.Message);
            }
示例#3
0
            public void PhysicalPathIsEmpty_Throws()
            {
                var manager = new NuGetManager();

                var ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage(null, "DummyPackage"));
                Assert.Contains("appPhysicalPath", ex.Message);

                ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage(string.Empty, "DummyPackage"));
                Assert.Contains("appPhysicalPath", ex.Message);
            }
示例#4
0
            public void SourcesProvided_NugetDefaultFeedIncluded()
            {
                // arrange
                var mockNugetCore = new Mock<INuGetCore>();
                mockNugetCore.Setup(n => n.InstallPackage("DummyPath", "DummyPackage", It.Is<string>(s => s.Contains(NuGetManager.NUGET_DEFAULT_SOURCE)), "", null))
                    .Returns(() => null)
                    .Verifiable();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>();

                // act
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.InstallPackage("DummyPath", "DummyPackage", "http://DummyFeed");
                
                // assert
                mockNugetCore.Verify();
            }
示例#5
0
        public void InstallSatelliteAssemblyTest()
        {
            // arrange
            NuGetManager nuget = new NuGetManager();
            var nugetSources = AbsolutePath(@"LocalizedNugetPackage");

            // act
            nuget.InstallPackages(
                _appInfo.PhysicalPath,
                new List<PackageName>
                    {
                        new PackageName("LocalizedNugetPackage.zh-Hans", new SemanticVersion("1.0"))
                    },
                nugetSources);

            // assert
            var expectedLocAssembly = Path.Combine(_appInfo.PhysicalPath, @"bin\zh-Hans\LocalizedNugetPackage.resources.dll");
            Assert.IsTrue(File.Exists(expectedLocAssembly));
        }
示例#6
0
            public void InstallAllProvidedPackages()
            {
                // arrange
                var mockNugetCore = new Mock<INuGetCore>();
                mockNugetCore.Setup(n => n.InstallPackage("DummyPath", "FooPackage", It.IsAny<string>(), "1.0", null))
                    .Returns(Enumerable.Empty<string>).Verifiable();
                mockNugetCore.Setup(n => n.InstallPackage("DummyPath", "BarPackage", It.IsAny<string>(), "2.0", null))
                    .Returns(Enumerable.Empty<string>).Verifiable();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>();

                var packagesToInstall = new List<PackageName>() {
                    new PackageName("FooPackage", SemanticVersion.Parse("1.0")),
                    new PackageName("BarPackage", SemanticVersion.Parse("2.0"))
                };

                // act
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.InstallPackages("DummyPath", packagesToInstall);

                // assert
                mockNugetCore.Verify();
            }
示例#7
0
            public void PackagesIsNull_Throws()
            {
                var manager = new NuGetManager();

                Assert.Throws<ArgumentNullException>(() => manager.InstallPackages("DummyPath", (IEnumerable<PackageName>)null));
            }
示例#8
0
            public void BinariesOnlyTrue_WebConfigDoesntExist()
            {
                // arrange
                var mockNugetCore = new Mock<INuGetCore>();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict);
                mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal));
                mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config")).Returns(false).Verifiable();
                mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config.temp")).Returns(false).Verifiable();

                // act
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.InstallPackage(@"DummyPath", "DummyPackage", binariesOnly: true);

                // assert
                mockFileSystem.Verify();
                // assert we don't call any other FileSystem APIs handled by MockBehavior.Strict
            }
示例#9
0
            public void BinariesOnlyTrue_WebConfigIsPreserved()
            {
                // arrange
                var mockNugetCore = new Mock<INuGetCore>();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>();
                mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal));
                mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config")).Returns(true).Verifiable();
                mockFileSystem.Setup(fs => fs.FileCopy(@"DummyPath\web.config", @"DummyPath\web.config.temp", true)).Verifiable();
                mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config.temp")).Returns(true).Verifiable();
                mockFileSystem.Setup(fs => fs.FileCopy(@"DummyPath\web.config.temp", @"DummyPath\web.config", true)).Verifiable();
                mockFileSystem.Setup(fs => fs.FileDelete(@"DummyPath\web.config.temp")).Verifiable();

                // act
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.InstallPackage(@"DummyPath", "DummyPackage", binariesOnly: true);

                // assert 
                mockFileSystem.Verify();
            }
示例#10
0
            public void BinariesOnlyFalse_WebConfigNotPreserved()
            {
                var mockNugetCore = new Mock<INuGetCore>();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict);
                mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal));

                // act
                // assert we don't call any other FileSystem APIs handled by MockBehavior.Strict
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.InstallPackage(@"DummyPath", "DummyPackage", binariesOnly: false);
            }
示例#11
0
            public void NullVersionConvertedToEmptyString()
            {
                // arrange
                var mockNugetCore = new Mock<INuGetCore>();
                mockNugetCore.Setup(n => n.UpdatePackage("DummyPath", "FooPackage", It.IsAny<string>(), "", null))
                    .Returns(Enumerable.Empty<string>).Verifiable();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>();

                var packagesToUpdate = new List<PackageName>() {
                    new PackageName("FooPackage", null),
                };

                // act
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.UpdatePackages("DummyPath", packagesToUpdate);

                // assert
                mockNugetCore.Verify();
            }
示例#12
0
            public void ReadFromPackagesConfig_UseCustomSources(string configContent, string[] packagesToExpect, string customSources)
            {
                // arrange
                var mockNugetCore = new Mock<INuGetCore>();
                foreach (var package in packagesToExpect)
                {
                    string packageId = package.Split('|')[0];
                    string packageVer = package.Split('|')[1];
                    mockNugetCore.Setup(n => n.InstallPackage("DummyPath", packageId, It.Is<string>(s => s.Contains(customSources)), It.IsAny<string>(), null))
                        .Returns(Enumerable.Empty<string>).Verifiable();
                }
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict);
                mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal));
                mockFileSystem.Setup(fs => fs.FileExists("DummyPackagesConfigPath")).Returns(true);
                mockFileSystem.Setup(fs => fs.FileReadAllText("DummyPackagesConfigPath")).Returns(configContent);

                // act
                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                manager.InstallPackages("DummyPath", "DummyPackagesConfigPath", binariesOnly: false);

                // assert
                mockNugetCore.Verify();
            }
示例#13
0
            public void PackagesConfigPathDoesNotExist_Throws()
            {
                var mockNugetCore = new Mock<INuGetCore>();
                var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict); // strict ensures we don't use any other FileSystem APIs
                mockFileSystem.Setup(fs => fs.FileExists("DummyPackagesConfigPath")).Returns(false).Verifiable();

                var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object);
                Assert.Throws<FileNotFoundException>(() => manager.InstallPackages("DummyPath", "DummyPackagesConfigPath"));
                mockFileSystem.Verify();
            }
示例#14
0
 public void PackagesConfigPathIsEmpty_Throws()
 {
     var manager = new NuGetManager();
     Assert.Throws<ArgumentNullException>(() => manager.InstallPackages("DummyPath", (string)null));
     Assert.Throws<ArgumentNullException>(() => manager.InstallPackages("DummyPath", ""));
 }
示例#15
0
        public void UpdatePackage_UpdatesReferencesInProjectFile()
        {
            // arrange
            NuGetManager nuget = new NuGetManager();
            var nugetSources = AbsolutePath(@"LocalizedNugetPackage");

            nuget.InstallPackages(
                _appInfo.PhysicalPath,
                new List<PackageName>
                    {
                        new PackageName("LocalizedNugetPackage", new SemanticVersion("1.0"))
                    },
                nugetSources);


            // act
            nuget.UpdatePackage(
                _appInfo.PhysicalPath,
                "LocalizedNugetPackage",
                nugetSources);

            var projectFileContents = File.ReadAllText(Path.Combine(_appInfo.PhysicalPath, "TestEasyWAP.csproj"));

            // assert
            var expectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.3.0.0-prerelease");
            Assert.IsTrue(Directory.Exists(expectedPackageInstallDir));
            Assert.IsTrue(projectFileContents.Contains("LocalizedNugetPackage.3.0.0-prerelease"));
            var notExpectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.1.0.0");
            Assert.IsFalse(Directory.Exists(notExpectedPackageInstallDir));
            Assert.IsFalse(projectFileContents.Contains("LocalizedNugetPackage.1.0.0"));
            
        }