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_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); }