public void RepoFactory_MultipleEnabledSources_RepoCreated() { // Arrange TestLogger logger = new TestLogger(); // Create a valid config settings file that specifies the package sources to use string configXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""local1_inactive"" value=""c:\inactiveCache\should.be.ignored"" /> <add key=""local2_active"" value=""d:\active_cache"" /> <add key=""local3_active"" value=""c:\another\active\cache"" /> </packageSources> <disabledPackageSources> <add key=""local1_inactive"" value=""true"" /> </disabledPackageSources> </configuration>"; Settings settings = CreateSettingsFromXml(configXml); // Act IPackageRepository actualRepo = NuGetRepositoryFactory.CreateRepository(settings, logger); // Assert Assert.IsInstanceOfType(actualRepo, typeof(AggregateRepository)); AggregateRepository actualAggregateRepo = (AggregateRepository)actualRepo; AssertExpectedPackageSources(actualAggregateRepo, "d:\\active_cache", "c:\\another\\active\\cache"); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void RepoFactory_NoEnabledSources_RepoCreated() { // Arrange TestLogger logger = new TestLogger(); string configXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""local1_inactive"" value=""c:\inactiveCache\should.be.ignored"" /> <add key=""local2_inactive"" value=""c:\inactiveCache2\should.be.ignored"" /> <add key=""local3_inactive"" value=""c:\inactiveCache3\should.be.ignored"" /> </packageSources> <disabledPackageSources> <add key=""local1_inactive"" value=""true"" /> <add key=""local2_inactive"" value=""true"" /> <add key=""local3_inactive"" value=""true"" /> </disabledPackageSources> </configuration>"; Settings settings = CreateSettingsFromXml(configXml); // Act IPackageRepository actualRepo = NuGetRepositoryFactory.CreateRepository(settings, logger); // Assert Assert.IsInstanceOfType(actualRepo, typeof(AggregateRepository)); AggregateRepository actualAggregateRepo = (AggregateRepository)actualRepo; AssertExpectedPackageSources(actualAggregateRepo /* no packages sources so no repositories */); }
public void RepoFactory_CreateRepositoryForArguments_CustomNuGetRepo_Overwrites_Default() { var settings = new ProcessedArgsBuilder("SomePackage", "SomeoutDir") .SetCustomNuGetRepository("file:///customrepo/path") .SetPackageVersion("0.0.1") .SetLanguage("cs") .Build(); var logger = new TestLogger(); var repo = NuGetRepositoryFactory.CreateRepositoryForArguments(logger, settings, "c:\\dummy\\config\\"); repo.Should().BeOfType <LazyLocalPackageRepository>(); repo.Source.Should().Be("/customrepo/path"); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void RepoFactory_CreateRepositoryForArguments_NoCustomNuGetRepo_DefaultUsed() { // Create a valid config settings file that specifies the package sources to use var configXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""local1"" value=""d:\cache1"" /> <add key=""local2"" value=""c:\cache2"" /> </packageSources> <disabledPackageSources> <add key=""local1_inactive"" value=""true"" /> </disabledPackageSources> </configuration>"; var fullConfigFilePath = WriteConfigFile(configXml); var settings = new ProcessedArgsBuilder("SomePackage", "SomeoutDir") .SetPackageVersion("0.0.1") .SetLanguage("cs") .Build(); var logger = new TestLogger(); var actualRepo = NuGetRepositoryFactory.CreateRepositoryForArguments(logger, settings, Path.GetDirectoryName(fullConfigFilePath)); actualRepo.Should().BeOfType <AggregateRepository>(); AggregateRepository actualAggregateRepo = (AggregateRepository)actualRepo; // There might be other machine-level nuget.config settings that have been picked, // so we'll only check that the known package sources above were found AssertExpectedPackageSourcesExist(actualAggregateRepo, "d:\\cache1", "c:\\cache2"); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void RepoFactory_OneEnabledSource_RepoCreated() { // Arrange TestLogger logger = new TestLogger(); string configXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""my.local"" value=""c:\active"" /> </packageSources> </configuration>"; Settings settings = CreateSettingsFromXml(configXml); // Act IPackageRepository actualRepo = NuGetRepositoryFactory.CreateRepository(settings, logger); // Assert Assert.IsInstanceOfType(actualRepo, typeof(AggregateRepository)); AggregateRepository actualAggregateRepo = (AggregateRepository)actualRepo; AssertExpectedPackageSources(actualAggregateRepo, "c:\\active"); }
public void RepoFactory_FailingRepo_ErrorLoggedAndSuppressed() { // Arrange TestLogger logger = new TestLogger(); string configXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""remote_bad"" value=""http://bad.remote.unreachable.repo"" /> </packageSources> </configuration>"; Settings settings = CreateSettingsFromXml(configXml); // Act IPackageRepository actualRepo = NuGetRepositoryFactory.CreateRepository(settings, logger); IPackage locatedPackage = actualRepo.FindPackage("dummy.package.id"); // trying to use the bad repo should fail // Assert Assert.IsNull(locatedPackage, "Should have failed to locate a package"); logger.AssertSingleWarningExists(NuGetLoggerAdapter.LogMessagePrefix, "http://bad.remote.unreachable.repo"); logger.AssertWarningsLogged(1); logger.AssertErrorsLogged(0); }