Ejemplo n.º 1
0
        public PackagingDummyFactory()
        {
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = new PackageDescription {
                    Id = A.Dummy <string>(), Version = A.Dummy <string>()
                };

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var packageDescription = A.Dummy <PackageDescription>();
                var result             = new Package {
                    PackageDescription = packageDescription, PackageFileBytes = Encoding.UTF32.GetBytes(A.Dummy <string>()), PackageFileBytesRetrievalDateTimeUtc = A.Dummy <DateTime>()
                };

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = new PackageRepositoryConfiguration {
                    Source = A.Dummy <string>(), SourceName = A.Dummy <string>(), UserName = A.Dummy <string>(), ClearTextPassword = A.Dummy <string>(), ProtocolVersion = A.Dummy <int?>()
                };

                return(result);
            });
        }
        public static void Roundtrip_DefaultPropertiesPackageRepositoryConfiguration()
        {
            // Arrange
            var expected       = new PackageRepositoryConfiguration();
            var bsonSerializer = new ObcBsonSerializer <PackagingBsonSerializationConfiguration>();
            var jsonSerializer = new ObcJsonSerializer <PackagingJsonSerializationConfiguration>();

            // Act
            var actualBsonString     = bsonSerializer.SerializeToString(expected);
            var actualFromBsonString = bsonSerializer.Deserialize <PackageRepositoryConfiguration>(actualBsonString);

            var actualJsonString     = jsonSerializer.SerializeToString(expected);
            var actualFromJsonString = jsonSerializer.Deserialize <PackageRepositoryConfiguration>(actualJsonString);

            // Assert
            actualFromBsonString.Should().Be(expected);
            actualFromJsonString.Should().Be(expected);
        }
        public static void DownloadPrivate()
        {
            var repoConfig = new PackageRepositoryConfiguration
            {
                Source            = "https://ci.appveyor.com/nuget/XXX",
                ClearTextPassword = "******",
                UserName          = "******",
                SourceName        = "ThisIsGalleryName",
                ProtocolVersion   = 2,
            };

            var defaultWorkingDirectory = @"D:\Temp\NewNuGet";
            var pm      = new PackageRetriever(defaultWorkingDirectory, new[] { PackageRepositoryConfiguration.NugetOrgV2, PackageRepositoryConfiguration.NugetOrgV3, repoConfig });
            var package = pm.GetPackage(new PackageDescription {
                Id = "ThisIsPackage"
            });

            Assert.NotNull(package.PackageFileBytes);
        }
Ejemplo n.º 4
0
        public PackageRetriever(
            string defaultWorkingDirectory,
            string nugetConfigFilePath,
            string nugetExeFilePath = null,
            Action <string> consoleOutputCallback = null)
        {
            this.defaultWorkingDirectory = defaultWorkingDirectory;

            this.tempDirectory = SetupTempWorkingDirectory(defaultWorkingDirectory);

            if (!File.Exists(nugetConfigFilePath))
            {
                throw new ArgumentException(Invariant($"{nameof(nugetConfigFilePath)} does not exist on disk."));
            }

            this.nugetConfigFilePath = nugetConfigFilePath;

            this.nugetExeFilePath = this.SetupNugetExe(nugetExeFilePath);

            this.consoleOutputCallback = consoleOutputCallback;

            var repoConfigs = new List <PackageRepositoryConfiguration>();

            try
            {
                var nugetConfigFileContents = File.ReadAllText(this.nugetConfigFilePath);

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(nugetConfigFileContents);

                var xpath = "/*[local-name()='configuration']/*[local-name()='packageSources']/*[local-name()='add']";
                var nodes = xmlDoc.SelectNodes(xpath);

                if (nodes == null || nodes.Count == 0)
                {
                    throw new ArgumentException(Invariant($"{nameof(nugetConfigFilePath)} has no packageSources"));
                }

                foreach (XmlNode node in nodes)
                {
                    if (node == null)
                    {
                        throw new ArgumentException(Invariant($"Could not parse {nameof(nugetConfigFilePath)} - found null node"));
                    }

                    var sourceName            = node.Attributes["key"]?.InnerText;
                    var source                = node.Attributes["value"]?.InnerText;
                    var protocolVersionString = node.Attributes["protocolVersion"]?.InnerText;
                    int?protocolVersion       = null;
                    if (!string.IsNullOrWhiteSpace(protocolVersionString))
                    {
                        try
                        {
                            protocolVersion = int.Parse(protocolVersionString, CultureInfo.InvariantCulture);
                        }
                        catch (Exception)
                        {
                            throw new ArgumentException(Invariant($"In {nameof(nugetConfigFilePath)} source '{sourceName}:{source}' has an invalid protocolVersion"));
                        }
                    }

                    var repoConfig = new PackageRepositoryConfiguration()
                    {
                        Source          = source,
                        SourceName      = sourceName,
                        ProtocolVersion = protocolVersion,
                    };

                    repoConfigs.Add(repoConfig);
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException(Invariant($"Could not parse {nameof(nugetConfigFilePath)}"), ex);
            }

            this.packageRepositoryConfigurations = repoConfigs;
        }