Exemplo n.º 1
0
        public void GetOrAddProperty_NoGroups()
        {
            using (var project = new MsBuildProjectFile())
            {
                BuildUtilities.GetOrAddProperty(project.Project, "MyProperty");
                Assert.Equal(1, project.Project.Properties.Count);
                Assert.Equal(1, project.Project.PropertyGroups.Count);

                var group = project.Project.PropertyGroups.First();
                Assert.Equal(1, group.Properties.Count);

                var property = group.Properties.First();
                Assert.Equal(string.Empty, property.Value);
            }
        }
Exemplo n.º 2
0
        public void GetProperty_ExistentProperty()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>MyPropertyValue</MyProperty>
  </PropertyGroup>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                var property = BuildUtilities.GetProperty(project.Project, "MyProperty");
                Assert.NotNull(property);
            }
        }
Exemplo n.º 3
0
        public void RenamePropertyValue_NonDefaultDelimiter()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>1|2|3</MyProperty>
  </PropertyGroup>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                BuildUtilities.RenamePropertyValue(project.Project, "1|2|3", "MyProperty", "2", "5", '|');
                var property = BuildUtilities.GetProperty(project.Project, "MyProperty");
                Assert.NotNull(property);
                Assert.Equal("1|5|3", property.Value);
            }
        }
Exemplo n.º 4
0
        public void RemovePropertyValue_EmptyAfterRemove()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>1</MyProperty>
  </PropertyGroup>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                BuildUtilities.RemovePropertyValue(project.Project, "1", "MyProperty", "1");
                var property = BuildUtilities.GetProperty(project.Project, "MyProperty");
                Assert.NotNull(property);
                Assert.Equal(string.Empty, property.Value);
            }
        }
Exemplo n.º 5
0
        public void AppendPropertyValue_EmptyProperty()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty/>
  </PropertyGroup>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                BuildUtilities.AppendPropertyValue(project.Project, "", "MyProperty", "1");
                var property = BuildUtilities.GetProperty(project.Project, "MyProperty");
                Assert.NotNull(property);
                Assert.Equal("1", property.Value);
            }
        }
Exemplo n.º 6
0
        public void AppendPropertyValue_DefaultDelimiter()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>1;2</MyProperty>
  </PropertyGroup>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                BuildUtilities.AppendPropertyValue(project.Project, "1;2", "MyProperty", "3");
                var property = BuildUtilities.GetProperty(project.Project, "MyProperty");
                Assert.NotNull(property);
                Assert.Equal("1;2;3", property.Value);
            }
        }
Exemplo n.º 7
0
        public void GetOrAddProperty_FirstGroup()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup/>
  <PropertyGroup/>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                BuildUtilities.GetOrAddProperty(project.Project, "MyProperty");
                Assert.Equal(1, project.Project.Properties.Count);
                Assert.Equal(2, project.Project.PropertyGroups.Count);

                var group = project.Project.PropertyGroups.First();
                Assert.Equal(1, group.Properties.Count);

                var property = group.Properties.First();
                Assert.Equal(string.Empty, property.Value);
            }
        }
Exemplo n.º 8
0
        public void GetOrAddProperty_ExistingProperty()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
    <MyProperty>1</MyProperty>
  </PropertyGroup>
</Project>";

            using (var project = new MsBuildProjectFile(projectXml))
            {
                BuildUtilities.GetOrAddProperty(project.Project, "MyProperty");
                Assert.Equal(1, project.Project.Properties.Count);
                Assert.Equal(1, project.Project.PropertyGroups.Count);

                var group = project.Project.PropertyGroups.First();
                Assert.Equal(1, group.Properties.Count);

                var property = group.Properties.First();
                Assert.Equal("1", property.Value);
            }
        }