Exemple #1
0
        public void TestProjectWithoutPackagesFile()
        {
            var packagesConfigFile = new ProjectPackagesFile(ProjectName);

            var target = new ProjectPackagesParser(Mock.Of <ILogger>(), Mock.Of <IFileReader>());

            var actual = target.Parse(packagesConfigFile);

            actual.ProjectName.Should().Be(ProjectName);
            actual.Nugets.Should().BeEmpty();
        }
Exemple #2
0
        public ProjectNugetsGrouping Parse(ProjectPackagesFile projectPackagesFile)
        {
            if (!projectPackagesFile.HasPackages)
            {
                return(EmptyProjectNugetsGrouping(projectPackagesFile.ProjectName));
            }

            var contents = FileReader.ReadFileContents(projectPackagesFile.PackagesFilePath);

            if (contents == string.Empty)
            {
                Logger.Warning("Config file located at {Path} is empty", projectPackagesFile.PackagesFilePath);
                return(EmptyProjectNugetsGrouping(projectPackagesFile.ProjectName));
            }

            XDocument xDocument;

            try
            {
                xDocument = XDocument.Parse(contents);
            }
            catch (XmlException e)
            {
                Logger.Warning(
                    "Config file located at {Path} contains invalid XML - {XmlExceptionMessage}",
                    projectPackagesFile.PackagesFilePath, e.Message
                    );
                return(EmptyProjectNugetsGrouping(projectPackagesFile.ProjectName));
            }

            try
            {
                var packages = from package in xDocument.Descendants("package")
                               select new NugetPackage(
                    package.Attribute("id").Value,
                    package.Attribute("version").Value,
                    package.Attribute("targetFramework").Value);

                return(new ProjectNugetsGrouping(projectPackagesFile.ProjectName, packages.ToList()));
            }
            catch (NullReferenceException)
            {
                Logger.Warning(
                    "Config file located at {Path} contains package elements with missing id, version, or targetFramework attributes",
                    projectPackagesFile.PackagesFilePath
                    );
                return(EmptyProjectNugetsGrouping(projectPackagesFile.ProjectName));
            }
        }
Exemple #3
0
        public void TestProjectWithPackagesFile(TestData testData)
        {
            var packagesConfigFile = new ProjectPackagesFile(ProjectName, "path");

            var mockFileReader = new Mock <IFileReader>();

            mockFileReader
            .Setup(fileReader => fileReader.ReadFileContents(
                       It.Is <string>(value => value == packagesConfigFile.PackagesFilePath)
                       ))
            .Returns(testData.PackagesConfigContent);

            var target = new ProjectPackagesParser(Mock.Of <ILogger>(), mockFileReader.Object);

            var actual = target.Parse(packagesConfigFile);

            actual.ProjectName.Should().Be(testData.ExpectedProjectNugetsGrouping.ProjectName);
            actual.Nugets.Should().ContainInOrder(testData.ExpectedProjectNugetsGrouping.Nugets);
        }