コード例 #1
0
        public void GenerateWarnings_PackageHasInvalidBuildAndInvalidBuildTransitiveAndInvalidBuildCross_ShouldWarnThrice()
        {
            //Arrange
            string packageId = "packageId";
            var    files     = new string[]
            {
                "build/package_Id.props",
                "buildTransitive/package_Id.props",
                "buildCrossTargeting/package_Id.props"
            };

            //Act
            var rule = new UpholdBuildConventionRule();
            var conventionViolators = rule.IdentifyViolators(files, packageId);
            var issues = rule.GenerateWarnings(conventionViolators);

            //Assert
            Assert.Equal(issues.Count(), 3);
            var firstIssue           = issues.Single(p => p.Code == NuGetLogCode.NU5129 && p.Message.Contains("build/packageId.props"));
            var firstExpectedMessage = "- At least one .props file was found in 'build/', but 'build/packageId.props' was not." + Environment.NewLine;

            Assert.True(firstIssue.Message.Equals(firstExpectedMessage));
            var secondIssue           = issues.Single(p => p.Code == NuGetLogCode.NU5129 && p.Message.Contains("buildTransitive/packageId.props"));
            var secondExpectedMessage = "- At least one .props file was found in 'buildTransitive/', but 'buildTransitive/packageId.props' was not." + Environment.NewLine;

            Assert.True(secondIssue.Message.Equals(secondExpectedMessage));
            var thirdIssue           = issues.Single(p => p.Code == NuGetLogCode.NU5129 && p.Message.Contains("buildCrossTargeting/packageId.props"));
            var thirdExpectedMessage = "- At least one .props file was found in 'buildCrossTargeting/', but 'buildCrossTargeting/packageId.props' was not." + Environment.NewLine;

            Assert.True(thirdIssue.Message.Equals(thirdExpectedMessage));
        }
コード例 #2
0
        public void IdentifyViolators_PackageWithPropsAndTargetsFilesInSubfolders_ShouldHaveTheCorrectLocations()
        {
            //Arrange
            string packageId = "packageId";
            var    files     = new string[]
            {
                "build/net45/packageId.props",
                "build/net45/package_ID.props",
                "build/net462/package_Id.props",
                "build/netstandard1.3/packageId.targets",
                "build/netstandard1.3/package_Id.targets",
                "build/netcoreapp1.1/package_Id.props",
                "build/packageId.props",
                "build/package_ID.props"
            };

            //Act
            var rule = new UpholdBuildConventionRule();
            var conventionViolators = rule.IdentifyViolators(files, packageId);

            //Assert
            Assert.Equal(2, conventionViolators.Count());
            Assert.False(conventionViolators.Any(t => t.Path.Equals("build/net45/")));
            Assert.False(conventionViolators.Any(t => t.Path.Equals("build/netstandard1.3/")));
            Assert.False(conventionViolators.Any(t => t.Path.Equals("build/")));
            var secondIssue = conventionViolators.Single(t => t.Path.Equals("build/netcoreapp1.1/"));
            var thirdIssue  = conventionViolators.Single(t => t.Path.Equals("build/net462/"));
        }
コード例 #3
0
        public void GenerateWarnings_PackageWithPropsAndTargetsInMultipleSubFolders_ShouldWarn()
        {
            //Arrange
            string packageId = "packageId";
            var    files     = new string[]
            {
                "build/net45/package_Id.props",
                "build/net462/package_Id.props",
                "build/net471/package_Id.props",
                "build/netstandard1.3/package_Id.props",
                "build/netcoreapp1.1/package_Id.props"
            };

            //Act
            var rule = new UpholdBuildConventionRule();
            var conventionViolators = rule.IdentifyViolators(files, packageId);
            var issues = rule.GenerateWarnings(conventionViolators);

            //Assert
            Assert.Equal(issues.Count(), 1);
            var singleIssue     = issues.Single(p => p.Code == NuGetLogCode.NU5129);
            var expectedMessage = "- At least one .props file was found in 'build/net45/', but 'build/net45/packageId.props' was not." + Environment.NewLine +
                                  "- At least one .props file was found in 'build/net462/', but 'build/net462/packageId.props' was not." + Environment.NewLine +
                                  "- At least one .props file was found in 'build/net471/', but 'build/net471/packageId.props' was not." + Environment.NewLine +
                                  "- At least one .props file was found in 'build/netstandard1.3/', but 'build/netstandard1.3/packageId.props' was not." + Environment.NewLine +
                                  "- At least one .props file was found in 'build/netcoreapp1.1/', but 'build/netcoreapp1.1/packageId.props' was not." + Environment.NewLine;

            Assert.True(singleIssue.Message.Equals(expectedMessage));
        }
コード例 #4
0
        public void FindAbsentExpectedFiles_PackageWithIncorrectlyNamedMSBuildFile_FindsOne(string[] files)
        {
            //Arrange
            string packageId = "packageId";

            //Act
            var rule   = new UpholdBuildConventionRule();
            var issues = rule.FindAbsentExpectedFiles(files, packageId);

            //Assert
            Assert.Single(issues);
        }
コード例 #5
0
        public void FindAbsentExpectedFiles_PackageWithCorrectlyNamedMSBuildFile_FindsZero(string[] files)
        {
            //Arrange
            string packageId = "packageId";

            //Act
            var rule   = new UpholdBuildConventionRule();
            var actual = rule.FindAbsentExpectedFiles(files, packageId);

            //Assert
            Assert.Empty(actual);
        }
コード例 #6
0
        public void WarningNotRaisedWhenGenerateWarningsCalledAndConventionIsFollowed(string[] files)
        {
            //Arrange
            string packageId = "packageId";

            //Act
            var rule = new UpholdBuildConventionRule();
            var conventionViolators = rule.IdentifyViolators(files, packageId);
            var issues = rule.GenerateWarnings(conventionViolators);

            //Assert
            Assert.Empty(issues);
        }
コード例 #7
0
        public void WarningRaisedWhenGenerateWarningsCalledAndConventionIsNotFollowed(string[] files)
        {
            //Arrange
            string packageId = "packageId";

            //Act
            var rule = new UpholdBuildConventionRule();
            var conventionViolators = rule.IdentifyViolators(files, packageId);
            var issues = rule.GenerateWarnings(conventionViolators);

            //Assert
            Assert.Equal(issues.Count(), 1);
            var singleIssue = issues.Single(p => p.Code == NuGetLogCode.NU5129);
        }
コード例 #8
0
        public void FindAbsentExpectedFiles_PackageWithFileNameSimilarToBuildDirectory_DoesNotWarn()
        {
            // Arrange
            var packageId = "PackageId";
            var files     = new[]
            {
                @"buildCustom\anything.props",
                "buildCustom/anything.targets"
            };

            // Act
            var target = new UpholdBuildConventionRule();
            var actual = target.FindAbsentExpectedFiles(files, packageId);

            // Assert
            Assert.Empty(actual);
        }
コード例 #9
0
        public void FindAbsentExpectedFiles_DifferentPathSeparators_GroupTogether()
        {
            // Arrange
            var files = new[]
            {
                "build/net5.0/one.props",
                @"build\net5.0\two.props"
            };
            var packageId = "PackageId";

            // Act
            var target = new UpholdBuildConventionRule();
            var actual = target.FindAbsentExpectedFiles(files, packageId);

            // Assert
            Assert.Equal(1, actual.Count);
        }
コード例 #10
0
        public void FindAbsentExpectedFiles_MultiplePropsInOneDirectory_FindsOne()
        {
            // Arrange
            var files = new[]
            {
                "build/one.props",
                "build/two.props"
            };
            var packageId = "PackageId";

            // Act
            var target = new UpholdBuildConventionRule();
            var actual = target.FindAbsentExpectedFiles(files, packageId);

            // Assert
            Assert.Equal(1, actual.Count);
        }
コード例 #11
0
        public void FindAbsentExpectedFiles_MultiplePropsInSubDirectories_FindsOne(string pathToTest)
        {
            // Arrange
            var files = new[]
            {
                pathToTest + "one.props",
                pathToTest + "two/two.props",
                pathToTest + "three/three.props"
            };
            var packageId = "PackageId";

            // Act
            var target = new UpholdBuildConventionRule();
            var actual = target.FindAbsentExpectedFiles(files, packageId);

            // Assert
            Assert.Equal(1, actual.Count);
        }
コード例 #12
0
        public void FindAbsentExpectedFiles_NonCompliantFileInTfmSubDirectory_ExpectedPathIsBuildRoot()
        {
            // Arrange
            var files = new[]
            {
                "build/net5.0/custom/other.props"
            };
            var packageId = "packageId";

            // Act
            var target = new UpholdBuildConventionRule();
            var actual = target.FindAbsentExpectedFiles(files, packageId);

            // Assert
            UpholdBuildConventionRule.ExpectedFile expectedFile = Assert.Single(actual);
            Assert.Equal("build/net5.0/", expectedFile.Path);
            Assert.Equal("build/net5.0/packageId.props", expectedFile.ExpectedPath);
        }
コード例 #13
0
        public void GenerateWarnings_SingleIssue_SingleLineMessage()
        {
            //Arrange
            var issues = new[]
            {
                new UpholdBuildConventionRule.ExpectedFile("build/net45/", ".props", "build/net45/packageId.props")
            };

            //Act
            var target  = new UpholdBuildConventionRule();
            var warning = target.GenerateWarning(issues);

            //Assert
            Assert.NotNull(warning);
            Assert.Equal(NuGetLogCode.NU5129, warning.Code);
            var expectedMessage = "- At least one .props file was found in 'build/net45/', but 'build/net45/packageId.props' was not." + Environment.NewLine;

            Assert.Equal(expectedMessage, warning.Message);
        }
コード例 #14
0
        public void IdentifyViolators_PackageWithPropsAndTargetsFilesUnderBuild_ShouldHaveTheCorrectLocations()
        {
            //Arrange
            string packageId = "packageId";
            var    files     = new string[]
            {
                "build/packageId.props",
                "build/package_ID.props",
                "build/package_Id.targets"
            };

            //Act
            var rule = new UpholdBuildConventionRule();
            var conventionViolators = rule.IdentifyViolators(files, packageId);

            //Assert
            Assert.Equal(conventionViolators.Count(), 1);
            Assert.True(conventionViolators.All(t => t.Path.Equals("build/")));
        }