Inheritance: System.Property
        private IEnumerable <RuleSetDeclaration> SetSingleValidRuleSetDeclarationPerProject(string configurationName = "Configuration", bool useUniqueProjectRuleSets = false)
        {
            List <RuleSetDeclaration> declarations = new List <RuleSetDeclaration>();

            foreach (ProjectMock project in this.projectHelper.FilteredProjects.OfType <ProjectMock>())
            {
                var configuration = new ConfigurationMock(configurationName);
                project.ConfigurationManager.Configurations.Add(configuration);

                PropertyMock ruleSetProperty = configuration.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetPropertyKey);
                ruleSetProperty.Value = project.FilePath.ToUpperInvariant(); // Catch cases where file paths are compared without OrdinalIgnoreCase
                if (useUniqueProjectRuleSets)
                {
                    ruleSetProperty.Value = Path.ChangeExtension(project.FilePath, configurationName + ".ruleSet");
                }

                PropertyMock ruleSetDirectories = configuration.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetDirectoriesPropertyKey);
                ruleSetDirectories.Value = ConflictsManager.CombineDirectories(new[] { this.TestContext.TestRunDirectory, "." });

                RuleSetDeclaration declaration = new RuleSetDeclaration(
                    project,
                    ruleSetProperty,
                    ruleSetProperty.Value.ToString().ToLowerInvariant(), // Catch cases where file paths are compared without OrdinalIgnoreCase
                    configuration.ConfigurationName,
                    ruleSetDirectories.Value.ToString().Split(';'));

                declarations.Add(declaration);

                this.ruleSetInfoProvider.RegisterProjectInfo(project, declaration);
            }

            return(declarations);
        }
示例#2
0
        private void VerifyRuleSetInformation(RuleSetDeclaration info, PropertyMock property)
        {
            Assert.AreSame(property, info.DeclaringProperty);
            Assert.AreEqual(property.Value, info.RuleSetPath);

            Configuration configuration = (Configuration)property.Collection.Parent;

            if (configuration == null)
            {
                Assert.Inconclusive("Test setup error, expected to have configuration as parent");
            }

            Assert.AreEqual(configuration.ConfigurationName, info.ConfigurationContext);

            Property ruleSetDirectory      = configuration.Properties.OfType <Property>().SingleOrDefault(p => p.Name == Constants.CodeAnalysisRuleSetDirectoriesPropertyKey);
            string   ruleSetDirectoryValue = ruleSetDirectory?.Value as string;

            if (string.IsNullOrWhiteSpace(ruleSetDirectoryValue))
            {
                Assert.AreEqual(0, info.RuleSetDirectories.Count());
            }
            else
            {
                string[] expected = ruleSetDirectoryValue.Split(new[] { SolutionRuleSetsInformationProvider.RuleSetDirectoriesValueSpliter }, StringSplitOptions.RemoveEmptyEntries);
                CollectionAssert.AreEquivalent(expected, info.RuleSetDirectories.ToArray(), "Actual: {0}", string.Join(", ", info.RuleSetDirectories));
            }
        }
        private void VerifyRuleSetInformation(RuleSetDeclaration info, PropertyMock property)
        {
            info.DeclaringProperty.Should().Be(property);
            info.RuleSetPath.Should().Be((string)property.Value);

            Configuration configuration = (Configuration)property.Collection.Parent;

            if (configuration == null)
            {
                FluentAssertions.Execution.Execute.Assertion.FailWith("Test setup error, expected to have configuration as parent");
            }

            info.ConfigurationContext.Should().Be(configuration.ConfigurationName);

            ((IVsBuildPropertyStorage)projectMock).GetPropertyValue(Constants.CodeAnalysisRuleSetDirectoriesPropertyKey, configuration.ConfigurationName, 0, out string ruleSetDirectoryValue);
            if (string.IsNullOrWhiteSpace(ruleSetDirectoryValue))
            {
                info.RuleSetDirectories.Should().BeEmpty();
            }
            else
            {
                string[] expected = ruleSetDirectoryValue.Split(new[] { SolutionRuleSetsInformationProvider.RuleSetDirectoriesValueSpliter }, StringSplitOptions.RemoveEmptyEntries);
                CollectionAssert.AreEquivalent(expected, info.RuleSetDirectories.ToArray(), "Actual: {0}", string.Join(", ", info.RuleSetDirectories));
            }
        }
        public void AssertPropertyExists(string name, object value)
        {
            PropertyMock property = this.properties.SingleOrDefault(p => p.Name == name);

            Assert.IsNotNull(property, $"Could not find property {name}");
            Assert.AreEqual(value, property.Value, $"Unexpected property {name} value");
        }
        public PropertyMock RegisterKnownProperty(string name)
        {
            if (this.properties.Any(p => p.Name == name))
            {
                Assert.Inconclusive($"Already has property: {name}");
            }

            PropertyMock prop = new PropertyMock(name, this);
            this.properties.Add(prop);
            return prop;
        }
示例#6
0
        public PropertyMock RegisterKnownProperty(string name)
        {
            if (this.properties.Any(p => p.Name == name))
            {
                FluentAssertions.Execution.Execute.Assertion.FailWith($"Already has property: {name}");
            }

            PropertyMock prop = new PropertyMock(name, this);

            this.properties.Add(prop);
            return(prop);
        }
        public PropertyMock RegisterKnownProperty(string name)
        {
            if (this.properties.Any(p => p.Name == name))
            {
                Assert.Inconclusive($"Already has property: {name}");
            }

            PropertyMock prop = new PropertyMock(name, this);

            this.properties.Add(prop);
            return(prop);
        }
        public void SolutionRuleSetsInformationProvider_GetProjectRuleSetsDeclarations_ConfigurationPropertyWithDefaultValue()
        {
            // Arrange
            PropertyMock prop1 = CreateProperty(this.projectMock, "config1", ProjectBindingOperation.DefaultProjectRuleSet);

            // Act
            RuleSetDeclaration[] info = testSubject.GetProjectRuleSetsDeclarations(this.projectMock).ToArray();

            // Assert
            info.Should().HaveCount(1, "Unexpected number of results");
            VerifyRuleSetInformation(info[0], prop1);
            this.outputPane.AssertOutputStrings(0);
        }
示例#9
0
        public void SolutionRuleSetsInformationProvider_GetProjectRuleSetsDeclarations_ConfigurationPropertyWithDefaultValue()
        {
            // Setup
            var          testSubject = new SolutionRuleSetsInformationProvider(this.serviceProvider);
            PropertyMock prop1       = CreateProperty(this.projectMock, "config1", ProjectBindingOperation.DefaultProjectRuleSet);

            // Act
            RuleSetDeclaration[] info = testSubject.GetProjectRuleSetsDeclarations(this.projectMock).ToArray();

            // Verify
            Assert.AreEqual(1, info.Length, "Unexpected number of results");
            VerifyRuleSetInformation(info[0], prop1);
            this.outputPane.AssertOutputStrings(0);
        }
        private void SetValidProjectConfiguration(ProjectMock project, string configurationName = "Configuration")
        {
            var configuration = new ConfigurationMock(configurationName);

            project.ConfigurationManager.Configurations.Add(configuration);

            PropertyMock ruleSetProperty = configuration.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetPropertyKey);

            ruleSetProperty.Value = project.FilePath.ToUpperInvariant(); // Catch cases where file paths are compared without OrdinalIgnoreCase

            this.ruleSetInfoProvider.RegisterProjectInfo(project, new RuleSetDeclaration[] {
                new RuleSetDeclaration(project, ruleSetProperty, (string)ruleSetProperty.Value, configurationName)
            });
        }
        public void SolutionRuleSetsInformationProvider_GetProjectRuleSetsDeclarations_ConfigurationPropertyWithEmptyRuleSets()
        {
            // Arrange
            PropertyMock prop1 = CreateProperty(this.projectMock, "config1", null);
            PropertyMock prop2 = CreateProperty(this.projectMock, "config2", string.Empty);

            // Act
            RuleSetDeclaration[] info = testSubject.GetProjectRuleSetsDeclarations(this.projectMock).ToArray();

            // Assert
            info.Should().HaveCount(2, "Unexpected number of results");
            VerifyRuleSetInformation(info[0], prop1);
            VerifyRuleSetInformation(info[1], prop2);
            this.outputPane.AssertOutputStrings(0);
        }
        public void SolutionRuleSetsInformationProvider_GetProjectRuleSetsDeclarations_ConfigurationPropertyWithSameNonDefaultValues()
        {
            // Arrange
            PropertyMock prop1 = CreateProperty(this.projectMock, "config1", "Custom1.ruleset");
            PropertyMock prop2 = CreateProperty(this.projectMock, "config2", @"x:\Folder\Custom2.ruleset");
            PropertyMock prop3 = CreateProperty(this.projectMock, "config3", @"..\Custom3.ruleset");

            // Act
            RuleSetDeclaration[] info = testSubject.GetProjectRuleSetsDeclarations(this.projectMock).ToArray();

            // Assert
            info.Should().HaveCount(3, "Unexpected number of results");
            VerifyRuleSetInformation(info[0], prop1);
            VerifyRuleSetInformation(info[1], prop2);
            VerifyRuleSetInformation(info[2], prop3);
            this.outputPane.AssertOutputStrings(0);
        }
        private void SetValidProjectRuleSets(Func <ProjectMock, string, RuleSet> filePathToRuleSetFactory)
        {
            foreach (ProjectMock project in this.projectSystemHelper.FilteredProjects.OfType <ProjectMock>())
            {
                foreach (ConfigurationMock config in project.ConfigurationManager.Configurations)
                {
                    PropertyMock property = config.Properties
                                            .OfType <PropertyMock>()
                                            .SingleOrDefault(p => p.Name == Constants.CodeAnalysisRuleSetPropertyKey);

                    string ruleSetPath = property?.Value as string;
                    if (ruleSetPath != null)
                    {
                        this.ruleSetSerializer.RegisterRuleSet(filePathToRuleSetFactory.Invoke(project, ruleSetPath));
                    }
                }
            }
        }
示例#14
0
        public void SolutionRuleSetsInformationProvider_GetProjectRuleSetsDeclarations_RuleSetsWithDirectories()
        {
            // Setup
            var          testSubject = new SolutionRuleSetsInformationProvider(this.serviceProvider);
            PropertyMock ruleSet1    = CreateProperty(this.projectMock, "config1", "Custom1.ruleset");

            CreateProperty(this.projectMock, "config1", @"x:\YYY\zzz", Constants.CodeAnalysisRuleSetDirectoriesPropertyKey);
            PropertyMock ruleSet2 = CreateProperty(this.projectMock, "config2", "Custom1.ruleset");

            CreateProperty(this.projectMock, "config2", @"x:\YYY\zzz;q:\;", Constants.CodeAnalysisRuleSetDirectoriesPropertyKey);

            // Act
            RuleSetDeclaration[] info = testSubject.GetProjectRuleSetsDeclarations(this.projectMock).ToArray();

            // Verify
            Assert.AreEqual(2, info.Length, "Unexpected number of results");
            VerifyRuleSetInformation(info[0], ruleSet1);
            VerifyRuleSetInformation(info[1], ruleSet2);
            this.outputPane.AssertOutputStrings(0);
        }
        public void SolutionRuleSetsInformationProvider_GetProjectRuleSetsDeclarations_RuleSetsWithDirectories()
        {
            // Arrange
            PropertyMock ruleSet1 = CreateProperty(this.projectMock, "config1", "Custom1.ruleset");

            SetBuildProperty(this.projectSystemHelper, this.projectMock, Constants.CodeAnalysisRuleSetDirectoriesPropertyKey, @"x:\YYY\zzz", "config1");

            PropertyMock ruleSet2 = CreateProperty(this.projectMock, "config2", "Custom1.ruleset");

            SetBuildProperty(this.projectSystemHelper, this.projectMock, Constants.CodeAnalysisRuleSetDirectoriesPropertyKey, @"x:\YYY\zzz;q:\;", "config2");

            // Act
            RuleSetDeclaration[] info = testSubject.GetProjectRuleSetsDeclarations(this.projectMock).ToArray();

            // Assert
            info.Should().HaveCount(2, "Unexpected number of results");
            VerifyRuleSetInformation(info[0], ruleSet1);
            VerifyRuleSetInformation(info[1], ruleSet2);
            this.outputPane.AssertOutputStrings(0);
        }
        private void VerifyRuleSetInformation(RuleSetDeclaration info, PropertyMock property)
        {
            Assert.AreSame(property, info.DeclaringProperty);
            Assert.AreEqual(property.Value, info.RuleSetPath);

            Configuration configuration = (Configuration)property.Collection.Parent;
            if (configuration == null)
            {
                Assert.Inconclusive("Test setup error, expected to have configuration as parent");
            }

            Assert.AreEqual(configuration.ConfigurationName, info.ConfigurationContext);

            Property ruleSetDirectory = configuration.Properties.OfType<Property>().SingleOrDefault(p => p.Name == Constants.CodeAnalysisRuleSetDirectoriesPropertyKey);
            string ruleSetDirectoryValue = ruleSetDirectory?.Value as string;
            if (string.IsNullOrWhiteSpace(ruleSetDirectoryValue))
            {
                Assert.AreEqual(0, info.RuleSetDirectories.Count());
            }
            else
            {
                string[] expected = ruleSetDirectoryValue.Split(new[] { SolutionRuleSetsInformationProvider.RuleSetDirectoriesValueSpliter }, StringSplitOptions.RemoveEmptyEntries);
                CollectionAssert.AreEquivalent(expected, info.RuleSetDirectories.ToArray(), "Actual: {0}", string.Join(", ", info.RuleSetDirectories));
            }
        }