示例#1
0
        public void ComplexTests()
        {
            Parser          p             = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("foo", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes"));
            propertyBag.Set(ProjectPropertyInstance.Create("one", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0"));
            propertyBag.Set(ProjectPropertyInstance.Create("two", "2"));
            propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring"));
            propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string"));
            propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one."));

            Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, FileSystems.Default);

            AssertParseEvaluate(p, "(($(foo) != 'two' and $(bar)) and 5 >= 1) or $(one) == 1", expander, true);
            AssertParseEvaluate(p, "(($(foo) != 'twoo' or !$(bar)) and 5 >= 1) or $(two) == 1", expander, true);
            AssertParseEvaluate(p, "!((($(foo) != 'twoo' or !$(bar)) and 5 >= 1) or $(two) == 1)", expander, false);
        }
示例#2
0
        public void StringExpansionTests()
        {
            Parser p = new Parser();

            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("foo", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes"));
            propertyBag.Set(ProjectPropertyInstance.Create("one", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0"));
            propertyBag.Set(ProjectPropertyInstance.Create("two", "2"));
            propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring"));
            propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string"));
            propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("TestQuote", "Contains'Quote'"));
            propertyBag.Set(ProjectPropertyInstance.Create("AnotherTestQuote", "Here's Johnny!"));
            propertyBag.Set(ProjectPropertyInstance.Create("Atsign", "Test the @ replacement"));

            Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, FileSystems.Default);

            AssertParseEvaluate(p, "'simplestring: true foo.cs;bar.cs;baz.cs' == '$(simple): $(foo) @(compile)'", expander, true);
            AssertParseEvaluate(p, "'$(c1) $(c2)' == 'Another (complex) one. Another (complex) one.'", expander, true);
            AssertParseEvaluate(p, "'CONTAINS%27QUOTE%27' == '$(TestQuote)'", expander, true);
            AssertParseEvaluate(p, "'Here%27s Johnny!' == '$(AnotherTestQuote)'", expander, true);
            AssertParseEvaluate(p, "'Test the %40 replacement' == $(Atsign)", expander, true);
        }
示例#3
0
        public void TestEquals()
        {
            BuildRequestConfiguration config1 = new BuildRequestConfiguration(new BuildRequestData("file", new Dictionary <string, string>(), "toolsVersion", new string[0], null), "2.0");

            Assert.Equal(config1, config1);
            BuildRequestConfiguration config2 = new BuildRequestConfiguration(new BuildRequestData("file", new Dictionary <string, string>(), "toolsVersion", new string[0], null), "2.0");

            Assert.Equal(config1, config2);

            BuildRequestConfiguration config3 = new BuildRequestConfiguration(new BuildRequestData("file2", new Dictionary <string, string>(), "toolsVersion", new string[0], null), "2.0");

            Assert.NotEqual(config1, config3);

            BuildRequestConfiguration config4 = new BuildRequestConfiguration(new BuildRequestData("file", new Dictionary <string, string>(), "toolsVersion2", new string[0], null), "2.0");

            Assert.NotEqual(config1, config4);

            PropertyDictionary <ProjectPropertyInstance> props = new PropertyDictionary <ProjectPropertyInstance>();

            props.Set(ProjectPropertyInstance.Create("prop1", "value1"));
            BuildRequestData          data    = new BuildRequestData("file", props.ToDictionary(), "toolsVersion", new string[0], null);
            BuildRequestConfiguration config5 = new BuildRequestConfiguration(data, "2.0");

            Assert.NotEqual(config1, config5);

            Assert.Equal(config1, config2);
            Assert.NotEqual(config1, config3);
        }
示例#4
0
        public void BasicPropertyDictionary()
        {
            PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>();

            ProjectPropertyInstance p1 = GetPropertyInstance("p1", "v1");
            ProjectPropertyInstance p2 = GetPropertyInstance("p2", "v2");
            ProjectPropertyInstance p3 = GetPropertyInstance("p1", "v1");
            ProjectPropertyInstance p4 = GetPropertyInstance("p2", "v3");

            properties.Set(p1);
            properties.Set(p2);
            properties.Set(p3);
            properties.Set(p1);
            properties.Set(p4);

            Assert.Equal(2, properties.Count);
            Assert.Equal("v1", properties["p1"].EvaluatedValue);
            Assert.Equal("v3", properties["p2"].EvaluatedValue);

            Assert.Equal(true, properties.Remove("p1"));
            Assert.Null(properties["p1"]);

            Assert.Equal(false, properties.Remove("x"));

            properties.Clear();

            Assert.Equal(0, properties.Count);
        }
示例#5
0
        /// <summary>
        /// Translates a PropertyDictionary of ProjectPropertyInstances.
        /// </summary>
        /// <param name="translator">The tranlator doing the translating</param>
        /// <param name="value">The dictionary to translate.</param>
        public static void TranslateProjectPropertyInstanceDictionary(this INodePacketTranslator translator, ref PropertyDictionary <ProjectPropertyInstance> value)
        {
            if (!translator.TranslateNullable(value))
            {
                return;
            }

            if (translator.Mode == TranslationDirection.ReadFromStream)
            {
                int count = 0;
                translator.Translate(ref count);

                value = new PropertyDictionary <ProjectPropertyInstance>(count);
                for (int i = 0; i < count; i++)
                {
                    ProjectPropertyInstance instance = null;
                    translator.Translate(ref instance, ProjectPropertyInstance.FactoryForDeserialization);
                    value[instance.Name] = instance;
                }
            }
            else // TranslationDirection.WriteToStream
            {
                int count = value.Count;
                translator.Translate(ref count);

                foreach (ProjectPropertyInstance instance in value)
                {
                    ProjectPropertyInstance instanceForSerialization = instance;
                    translator.Translate(ref instanceForSerialization, ProjectPropertyInstance.FactoryForDeserialization);
                }
            }
        }
示例#6
0
文件: GraphBuilder.cs 项目: 3F/IeXod
        private static List <ConfigurationMetadata> AddGraphBuildPropertyToEntryPoints(IEnumerable <ProjectGraphEntryPoint> entryPoints)
        {
            {
                var entryPointConfigurationMetadata = new List <ConfigurationMetadata>();

                foreach (var entryPoint in entryPoints)
                {
                    var globalPropertyDictionary = CreatePropertyDictionary(entryPoint.GlobalProperties);

                    AddGraphBuildGlobalVariable(globalPropertyDictionary);

                    var configurationMetadata = new ConfigurationMetadata(FileUtilities.NormalizePath(entryPoint.ProjectFile), globalPropertyDictionary);
                    entryPointConfigurationMetadata.Add(configurationMetadata);
                }

                return(entryPointConfigurationMetadata);
            }

            void AddGraphBuildGlobalVariable(PropertyDictionary <ProjectPropertyInstance> globalPropertyDictionary)
            {
                if (globalPropertyDictionary.GetProperty(PropertyNames.IsGraphBuild) == null)
                {
                    globalPropertyDictionary[PropertyNames.IsGraphBuild] = ProjectPropertyInstance.Create(PropertyNames.IsGraphBuild, "true");
                }
            }
        }
示例#7
0
        public static void AssertPropertyDoesNotExist(ProjectInstance projectInstance, string propertyName)
        {
            ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(propertyName);

            string value = propertyInstance == null ? null : propertyInstance.EvaluatedValue;

            Assert.IsNull(propertyInstance, "Not expecting the property to exist. Property: {0}, Value: {1}", propertyName, value);
        }
        private static ProjectPropertyInstance GetPropertyInstance()
        {
            Project                 project         = new Project();
            ProjectInstance         projectInstance = project.CreateProjectInstance();
            ProjectPropertyInstance property        = projectInstance.SetProperty("p", "v1");

            return(property);
        }
示例#9
0
        private static ProjectPropertyInstance GetPropertyInstance(string name, string value)
        {
            Project                 project         = new Project();
            ProjectInstance         projectInstance = project.CreateProjectInstance();
            ProjectPropertyInstance property        = projectInstance.SetProperty(name, value);

            return(property);
        }
示例#10
0
        internal void CreateUniqueGlobalProperty()
        {
            // create a copy so the mutation does not leak into the ProjectInstance
            _globalProperties = new PropertyDictionary <ProjectPropertyInstance>(_globalProperties);

            var key = $"{MSBuildConstants.MSBuildDummyGlobalPropertyHeader}{Guid.NewGuid():N}";

            _globalProperties[key] = ProjectPropertyInstance.Create(key, "Forces unique project identity in the MSBuild engine");
        }
 private static void MergeIntoPropertyDictionary(
     PropertyDictionary <ProjectPropertyInstance> destination,
     IReadOnlyDictionary <string, string> source)
 {
     foreach (var pair in source)
     {
         destination[pair.Key] = ProjectPropertyInstance.Create(pair.Key, pair.Value);
     }
 }
 public void SetInvalidNullValue()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         ProjectPropertyInstance property = GetPropertyInstance();
         property.EvaluatedValue          = null;
     }
                                           );
 }
        public string GetProjectPropertyByName(IProject project, string name)
        {
            Dictionary <string, string> cachedProperties;

            if (this.myData.TryGetValue(project, out cachedProperties))
            {
                string value;
                if (cachedProperties.TryGetValue(name, out value))
                {
                    return(value);
                }
            }
            else
            {
                cachedProperties = new Dictionary <string, string>();
                this.myData.Add(project, cachedProperties);
            }
            try
            {
                const string resolveassemblyreference = "ResolveAssemblyReferences";
                IProjectFile projectFile = project.ProjectFile;
                if (projectFile == null)
                {
                    return(null);
                }

                List <Project> loadedProjects =
                    ProjectCollection.GlobalProjectCollection.GetLoadedProjects(
                        projectFile.Location.FullPath).ToList();
                if (loadedProjects.Count != 1)
                {
                    return(null);
                }

                Project         loadedProject   = loadedProjects[0];
                ProjectInstance projectInstance =
                    BuildManager.DefaultBuildManager.GetProjectInstanceForBuild(loadedProject);
                if (projectInstance.Build(resolveassemblyreference, JetBrains.Util.EmptyList <ILogger> .InstanceList))
                {
                    ICollection <ProjectPropertyInstance> allProperties = projectInstance.Properties;
                    foreach (ProjectPropertyInstance property in allProperties)
                    {
                        cachedProperties.Add(property.Name, property.EvaluatedValue);
                    }
                    ProjectPropertyInstance projectPropertyInstance = projectInstance.GetProperty(name);
                    if (projectPropertyInstance != null)
                    {
                        return(projectPropertyInstance.EvaluatedValue);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogExceptionSilently(e);
            }
            return("");
        }
        public void DeepClone()
        {
            ProjectPropertyInstance property = GetPropertyInstance();

            ProjectPropertyInstance clone = property.DeepClone();

            Assert.Equal(false, Object.ReferenceEquals(property, clone));
            Assert.Equal("p", clone.Name);
            Assert.Equal("v1", clone.EvaluatedValue);
        }
示例#15
0
        public static bool AssertBooleanPropertyExists(ProjectInstance projectInstance, string propertyName)
        {
            ProjectPropertyInstance propertyInstance = BuildAssertions.AssertPropertyExists(projectInstance, TargetProperties.SonarQubeTestProject);

            bool result;
            bool parsedOk = bool.TryParse(propertyInstance.EvaluatedValue, out result);

            Assert.IsTrue(parsedOk, "Failed to convert the property value to a boolean. Property: {0}, Evaluated value: {1}", propertyInstance.Name, propertyInstance.EvaluatedValue);

            return(result);
        }
示例#16
0
        public void UpdateMSBuildProperties_SolutionHasFileName_SolutionDefinesSolutionDirMSBuildPropertyWithDirectoryEndingInSlash()
        {
            var solution = CreateSolution();

            ProjectPropertyInstance property = solution.MSBuildProjectCollection.GetGlobalProperty("SolutionDir");
            string solutionDir = property.EvaluatedValue;

            string expectedSolutionDir = @"d:\projects\MyProject\";

            Assert.AreEqual(expectedSolutionDir, solutionDir);
        }
        public void Serialization()
        {
            ProjectPropertyInstance property = GetPropertyInstance();

            TranslationHelpers.GetWriteTranslator().Translate(ref property, ProjectPropertyInstance.FactoryForDeserialization);
            ProjectPropertyInstance deserializedProperty = null;

            TranslationHelpers.GetReadTranslator().Translate(ref deserializedProperty, ProjectPropertyInstance.FactoryForDeserialization);

            Assert.Equal(property.Name, deserializedProperty.Name);
            Assert.Equal(property.EvaluatedValue, deserializedProperty.EvaluatedValue);
        }
        public void EqualsEndPastEnd1()
        {
            PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>();

            ProjectPropertyInstance p = ProjectPropertyInstance.Create("bbb", "value");

            dictionary.Set(p);

            ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "abbbaaa", 1, 3);

            Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted"
        }
示例#19
0
        public ConfigurationMetadata(Project project)
        {
            ErrorUtilities.VerifyThrowArgumentNull(project, nameof(project));
            _globalProperties = new PropertyDictionary <ProjectPropertyInstance>(project.GlobalProperties.Count);
            foreach (KeyValuePair <string, string> entry in project.GlobalProperties)
            {
                _globalProperties[entry.Key] = ProjectPropertyInstance.Create(entry.Key, entry.Value);
            }

            _toolsVersion    = project.ToolsVersion;
            _projectFullPath = FileUtilities.NormalizePath(project.FullPath);
        }
示例#20
0
        public void CloneProperties()
        {
            ProjectInstance first  = GetSampleProjectInstance();
            ProjectInstance second = first.DeepCopy();

            Assert.False(Object.ReferenceEquals(first.GetProperty("p1"), second.GetProperty("p1")));

            ProjectPropertyInstance newProperty = first.SetProperty("p1", "v1b");

            Assert.True(Object.ReferenceEquals(newProperty, first.GetProperty("p1")));
            Assert.Equal("v1b", first.GetPropertyValue("p1"));
            Assert.Equal("v1", second.GetPropertyValue("p1"));
        }
        public static void AssertExpectedPropertyValue(ProjectInstance projectInstance, string propertyName, string expectedValue)
        {
            ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(propertyName);

            if (expectedValue == null &&
                propertyInstance == null)
            {
                return;
            }

            Assert.IsNotNull(propertyInstance, "The expected property does not exist: {0}", propertyName);
            Assert.AreEqual(expectedValue, propertyInstance.EvaluatedValue, "Property '{0}' does not have the expected value", propertyName);
        }
示例#22
0
        public virtual string GetConfigurationProperty(string propertyName, bool resetCache)
        {
            if (snapshot == null)
            {
                snapshot = proj.CreateProjectInstance(config, platform);
            }
            ProjectPropertyInstance property = snapshot.GetProperty(propertyName);

            if (property == null)
            {
                return(null);
            }
            return(property.EvaluatedValue);
        }
        public void EqualsStartZero()
        {
            PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>();

            ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aab", "value1");
            ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("aba", "value2");

            dictionary.Set(p1);
            dictionary.Set(p2);

            ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "aabaa", 0, 2);

            Assert.True(Object.ReferenceEquals(p1, value)); // "Should have returned the 'aab' value"
        }
示例#24
0
        public void EqualsSameStartEnd1()
        {
            PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>();

            ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("A", "value1");
            ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("B", "value2");

            dictionary.Set(p1);
            dictionary.Set(p2);

            ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "babbbb", 1, 1);

            Assert.IsTrue(Object.ReferenceEquals(p1, value), "Should have returned the 'A' value");
        }
        /// <summary>
        /// Set up expression tests by creating files for existence checks.
        /// </summary>
        public ExpressionTest(ITestOutputHelper output)
        {
            this.output = output;

            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            // Dummy project instance to own the items.
            ProjectRootElement xml = ProjectRootElement.Create();

            xml.FullPath = @"c:\abc\foo.proj";

            ProjectInstance parentProject = new ProjectInstance(xml);

            itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath));

            PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("a", "no"));
            propertyBag.Set(ProjectPropertyInstance.Create("b", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("c", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx"));
            propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx"));
            propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5"));
            propertyBag.Set(ProjectPropertyInstance.Create("and", "and"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_semi_c", "a;c"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b"));
            propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b"));
            propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\"));

            Dictionary <string, string> metadataDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            metadataDictionary["Culture"] = "french";
            StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary);

            _expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata, FileSystems.Default);

            foreach (string file in FilesWithExistenceChecks)
            {
                using (StreamWriter sw = File.CreateText(file)) {; }
            }
        }
        public void EqualsSameStartEnd2()
        {
            MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable;
            PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer);

            ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("a", "value1");
            ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("b", "value2");

            dictionary.Set(p1);
            dictionary.Set(p2);

            ProjectPropertyInstance value = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "aabaa", 2, 2);

            Assert.True(Object.ReferenceEquals(p2, value)); // "Should have returned the 'b' value"
        }
 /// <summary>
 /// Sets the given property in the given property group.
 /// </summary>
 private void SetProperty(ToolsetPropertyDefinition property, PropertyDictionary <ProjectPropertyInstance> propertyGroup, PropertyDictionary <ProjectPropertyInstance> globalProperties)
 {
     try
     {
         // Global properties cannot be overwritten
         if (globalProperties[property.Name] == null)
         {
             propertyGroup.Set(ProjectPropertyInstance.Create(property.Name, EscapingUtilities.UnescapeAll(property.Value), true /* may be reserved */, false /* not immutable */));
         }
     }
     catch (ArgumentException ex)
     {
         InvalidToolsetDefinitionException.Throw(ex, "InvalidPropertyNameInToolset", property.Name, property.Source.LocationString, ex.Message);
     }
 }
示例#28
0
        /// <summary>
        /// Creates a standard ProjectCollection and adds a fake toolset with the following contents to it:
        ///
        /// ToolsVersion = Fake
        /// Base Properties:
        /// a = a1
        /// b = b1
        ///
        /// SubToolset "12.0":
        /// d = d4
        /// e = e5
        ///
        /// SubToolset "v11.0":
        /// b = b2
        /// c = c2
        ///
        /// SubToolset "FakeSubToolset":
        /// a = a3
        /// c = c3
        ///
        /// SubToolset "v13.0":
        /// f = f6
        /// g = g7
        /// </summary>
        private Toolset GetFakeToolset(IDictionary <string, string> globalPropertiesForProjectCollection)
        {
            ProjectCollection projectCollection = new ProjectCollection(globalPropertiesForProjectCollection);

            IDictionary <string, string> properties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            properties.Add("a", "a1");
            properties.Add("b", "b1");

            Dictionary <string, SubToolset> subToolsets = new Dictionary <string, SubToolset>(StringComparer.OrdinalIgnoreCase);

            // SubToolset 12.0 properties
            PropertyDictionary <ProjectPropertyInstance> subToolset12Properties = new PropertyDictionary <ProjectPropertyInstance>();

            subToolset12Properties.Set(ProjectPropertyInstance.Create("d", "d4"));
            subToolset12Properties.Set(ProjectPropertyInstance.Create("e", "e5"));

            // SubToolset v11.0 properties
            PropertyDictionary <ProjectPropertyInstance> subToolset11Properties = new PropertyDictionary <ProjectPropertyInstance>();

            subToolset11Properties.Set(ProjectPropertyInstance.Create("b", "b2"));
            subToolset11Properties.Set(ProjectPropertyInstance.Create("c", "c2"));

            // FakeSubToolset properties
            PropertyDictionary <ProjectPropertyInstance> fakeSubToolsetProperties = new PropertyDictionary <ProjectPropertyInstance>();

            fakeSubToolsetProperties.Set(ProjectPropertyInstance.Create("a", "a3"));
            fakeSubToolsetProperties.Set(ProjectPropertyInstance.Create("c", "c3"));

            // SubToolset v13.0 properties
            PropertyDictionary <ProjectPropertyInstance> subToolset13Properties = new PropertyDictionary <ProjectPropertyInstance>();

            subToolset13Properties.Set(ProjectPropertyInstance.Create("f", "f6"));
            subToolset13Properties.Set(ProjectPropertyInstance.Create("g", "g7"));

            subToolsets.Add("12.0", new SubToolset("12.0", subToolset12Properties));
            subToolsets.Add("v11.0", new SubToolset("v11.0", subToolset11Properties));
            subToolsets.Add("FakeSubToolset", new SubToolset("FakeSubToolset", fakeSubToolsetProperties));
            subToolsets.Add("v13.0", new SubToolset("v13.0", subToolset13Properties));

            Toolset parentToolset = projectCollection.GetToolset("4.0");

            Toolset fakeToolset = new Toolset("Fake", parentToolset.ToolsPath, properties, projectCollection, subToolsets, parentToolset.OverrideTasksPath);

            projectCollection.AddToolset(fakeToolset);

            return(fakeToolset);
        }
        public void MatchProperty()
        {
            MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Default;
            PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer);

            ProjectPropertyInstance p = ProjectPropertyInstance.Create("foo", "bar");

            dictionary.Set(p);

            string s = "$(foo)";
            ProjectPropertyInstance value = dictionary.GetProperty(s, 2, 4);

            Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted"

            Assert.Equal(MSBuildNameIgnoreCaseComparer.Default.GetHashCode("foo"), comparer.GetHashCode(s, 2, 3));
        }
        public void TestTranslation()
        {
            var globalProperties = new PropertyDictionary <ProjectPropertyInstance>();

            globalProperties["a"] = ProjectPropertyInstance.Create("a", "b");

            var initial = new ConfigurationMetadata("path", globalProperties);

            initial.Translate(TranslationHelpers.GetWriteTranslator());
            var copy = ConfigurationMetadata.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            copy.ProjectFullPath.ShouldBe(initial.ProjectFullPath);
            copy.ToolsVersion.ShouldBe(initial.ToolsVersion);

            Assert.Equal(copy.GlobalProperties.GetCopyOnReadEnumerable(), initial.GlobalProperties.GetCopyOnReadEnumerable(), EqualityComparer <ProjectPropertyInstance> .Default);
        }