public void GetOrAddProperty_ExistingProperty()
        {
            string projectXml =
                "" "
                <Project>
                  <PropertyGroup>
                    <MyProperty>1</MyProperty>
                  </PropertyGroup>
                </Project>
                " "";

            var project = ProjectRootElementFactory.Create(projectXml);

            BuildUtilities.GetOrAddProperty(project, "MyProperty");
            Assert.Single(project.Properties);
            Assert.Single(project.PropertyGroups);

            var group = project.PropertyGroups.First();

            Assert.Single(group.Properties);

            var property = group.Properties.First();

            Assert.Equal("1", property.Value);
        }
Exemplo n.º 2
0
        public async Task OnDimensionValueChanged_Add()
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new ConfigurationProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();

            // On ChangeEventStage.After nothing should be changed
            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                unconfiguredProject,
                ConfigurationDimensionChange.Add,
                ChangeEventStage.After,
                ConfigurationGeneral.ConfigurationProperty,
                "CustomConfig");
            await provider.OnDimensionValueChangedAsync(args);

            var property = BuildUtilities.GetProperty(project, Configurations);

            Assert.NotNull(property);
            Assert.Equal("Debug;Release;CustomConfiguration", property.Value);

            // On ChangeEventStage.Before the property should be added
            args = new ProjectConfigurationDimensionValueChangedEventArgs(
                unconfiguredProject,
                ConfigurationDimensionChange.Add,
                ChangeEventStage.Before,
                ConfigurationGeneral.ConfigurationProperty,
                "CustomConfig");
            await provider.OnDimensionValueChangedAsync(args);

            property = BuildUtilities.GetProperty(project, Configurations);
            Assert.NotNull(property);
            Assert.Equal("Debug;Release;CustomConfiguration;CustomConfig", property.Value);
        }
        public async Task OnDimensionValueChanged_Rename_UnknownValue()
        {
            string projectXml =
                "" "
                <Project>
                  <PropertyGroup>
                    <PROP>A;B;C</PROP>
                  </PropertyGroup>
                </Project>
                " "";

            var rootElement       = ProjectRootElementFactory.Create(projectXml.Replace("PROP", PropertyName));
            var projectAccessor   = IProjectAccessorFactory.Create(rootElement);
            var configuredProject = ConfiguredProjectFactory.Create();
            var provider          = CreateInstance(projectAccessor);
            var project           = UnconfiguredProjectFactory.Create(configuredProject: configuredProject);

            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                project,
                ConfigurationDimensionChange.Rename,
                ChangeEventStage.After,
                DimensionName,
                "Renamed",
                "Unknown");
            await Assert.ThrowsAsync <ArgumentException>(() => provider.OnDimensionValueChangedAsync(args));

            var property = BuildUtilities.GetProperty(rootElement, PropertyName);

            Assert.NotNull(property);
            Assert.Equal("A;B;C", property.Value);
        }
Exemplo n.º 4
0
        public async Task PlatformProjectConfigurationDimensionProvider_OnDimensionValueChanged_Remove()
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new PlatformProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();

            // On ChangeEventStage.After nothing should be changed
            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                unconfiguredProject,
                ConfigurationDimensionChange.Delete,
                ChangeEventStage.After,
                ConfigurationGeneral.PlatformProperty,
                "x86");
            await provider.OnDimensionValueChangedAsync(args);

            var property = BuildUtilities.GetProperty(project, Platforms);

            Assert.NotNull(property);
            Assert.Equal("AnyCPU;x64;x86", property.Value);

            // On ChangeEventStage.Before the property should be removed
            args = new ProjectConfigurationDimensionValueChangedEventArgs(
                unconfiguredProject,
                ConfigurationDimensionChange.Delete,
                ChangeEventStage.Before,
                ConfigurationGeneral.PlatformProperty,
                "x86");
            await provider.OnDimensionValueChangedAsync(args);

            property = BuildUtilities.GetProperty(project, Platforms);
            Assert.NotNull(property);
            Assert.Equal("AnyCPU;x64", property.Value);
        }
        public async Task SetProjectGuidAsync_SetsFirstProjectGuidIgnoringConditions(string input, string expected)
        {
            var result   = ProjectRootElementFactory.Create(input);
            var provider = CreateInstance(result);

            await provider.SetProjectGuidAsync(new Guid("{C26D43ED-ED18-46F9-8950-0B1A7232746E}"));

            MSBuildAssert.AssertProjectXml(expected, result);
        }
        public async Task SetProjectGuidAsync_WhenNoProjectGuidProperty_DoesNotSet(string projectXml)
        {
            var result   = ProjectRootElementFactory.Create(projectXml);
            var provider = CreateInstance(result);

            await provider.SetProjectGuidAsync(new Guid("{C26D43ED-ED18-46F9-8950-0B1A7232746E}"));

            MSBuildAssert.AssertProjectXml(projectXml, result);
        }
Exemplo n.º 7
0
        public async Task GetProjectConfigurationDimensionsAsync_NoPropertyValue()
        {
            var project             = ProjectRootElementFactory.Create();
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new ConfigurationProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();
            var values = await provider.GetProjectConfigurationDimensionsAsync(unconfiguredProject);

            Assert.Empty(values);
        }
Exemplo n.º 8
0
        public void RenamePropertyValue_InheritedValue()
        {
            var project = ProjectRootElementFactory.Create();

            BuildUtilities.RenamePropertyValue(project, "1;2", "MyProperty", "1", "3");
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal("3;2", property.Value);
        }
Exemplo n.º 9
0
        public void GetOrAddProperty_NoGroups()
        {
            var project = ProjectRootElementFactory.Create();

            BuildUtilities.GetOrAddProperty(project, "MyProperty");
            Assert.Single(project.Properties);
            Assert.Collection(project.PropertyGroups,
                              group => Assert.Collection(group.Properties,
                                                         firstProperty => Assert.Equal(string.Empty, firstProperty.Value)));
        }
Exemplo n.º 10
0
        public async Task GetDefaultValuesForDimensionsAsync_TFM()
        {
            var project             = ProjectRootElementFactory.Create(ProjectXmlTFM);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new TargetFrameworkProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();
            var values = await provider.GetDefaultValuesForDimensionsAsync(unconfiguredProject);

            Assert.Empty(values);
        }
Exemplo n.º 11
0
        public void RenamePropertyValue_MissingProperty()
        {
            var project = ProjectRootElementFactory.Create();

            Assert.Throws <ArgumentException>("oldValue", () => BuildUtilities.RenamePropertyValue(project, "", "MyProperty", "1", "2"));
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal(string.Empty, property.Value);
        }
Exemplo n.º 12
0
        public void AppendPropertyValue_MissingProperty()
        {
            var project = ProjectRootElementFactory.Create();

            BuildUtilities.AppendPropertyValue(project, "", "MyProperty", "1");
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal("1", property.Value);
        }
Exemplo n.º 13
0
        public async Task PlatformProjectConfigurationDimensionProvider_GetDefaultValuesForDimensionsAsync()
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new PlatformProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();
            var values = await provider.GetDefaultValuesForDimensionsAsync(unconfiguredProject);

            Assert.Single(values);
            var value = values.First();

            Assert.Equal(ConfigurationGeneral.PlatformProperty, value.Key);
            Assert.Equal("AnyCPU", value.Value);
        }
Exemplo n.º 14
0
        public void GetProperty_ExistentProperty()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>MyPropertyValue</MyProperty>
  </PropertyGroup>
</Project>";

            var project  = ProjectRootElementFactory.Create(projectXml);
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
        }
Exemplo n.º 15
0
        public async Task GetDefaultValuesForDimensionsAsync_TFMs(string projectXml)
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new TargetFrameworkProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();
            var values = await provider.GetDefaultValuesForDimensionsAsync(unconfiguredProject);

            Assert.Single(values);
            var value = values.First();

            Assert.Equal(ConfigurationGeneral.TargetFrameworkProperty, value.Key);
            Assert.Equal("netcoreapp1.0", value.Value);
        }
Exemplo n.º 16
0
        public static IProjectAccessor ImplementOpenProjectForReadAsync <TResult>(string xml)
        {
            var rootElement       = ProjectRootElementFactory.Create(xml);
            var evaluationProject = ProjectFactory.Create(rootElement);

            var mock = new Mock <IProjectAccessor>();

            mock.Setup(a => a.OpenProjectForReadAsync(It.IsAny <ConfiguredProject>(), It.IsAny <Func <Project, TResult> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((ConfiguredProject project, Func <Project, TResult> action, CancellationToken cancellationToken) =>
            {
                return(action(evaluationProject));
            });

            return(mock.Object);
        }
        [InlineData("C26D43EDED1846F989500B1%417232746E")] // With escaped characters
        public async Task SetProjectGuidAsync_WhenProjectGuidPropertyAlreadyHasSameGuid_DoesNotSet(string guid)
        {
            var projectXml = $@"
<Project>
     <PropertyGroup>
         <ProjectGuid>{guid}</ProjectGuid>
     </PropertyGroup>
 </Project>";

            var result   = ProjectRootElementFactory.Create(projectXml);
            var provider = CreateInstance(result);

            await provider.SetProjectGuidAsync(new Guid("{C26D43ED-ED18-46F9-8950-0B1A7232746E}"));

            MSBuildAssert.AssertProjectXml(projectXml, result);
        }
        public async Task OnDimensionValueChanged_Rename()
        {
            string projectXml =
                "" "
                <Project>
                  <PropertyGroup>
                    <PROP>A;B;C</PROP>
                  </PropertyGroup>
                </Project>
                " "";

            var rootElement       = ProjectRootElementFactory.Create(projectXml.Replace("PROP", PropertyName));
            var projectAccessor   = IProjectAccessorFactory.Create(rootElement);
            var configuredProject = ConfiguredProjectFactory.Create();
            var provider          = CreateInstance(projectAccessor);
            var project           = UnconfiguredProjectFactory.Create(configuredProject: configuredProject);

            // On ChangeEventStage.Before nothing should be changed
            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                project,
                ConfigurationDimensionChange.Rename,
                ChangeEventStage.Before,
                DimensionName,
                "Renamed",
                "B");
            await provider.OnDimensionValueChangedAsync(args);

            var property = BuildUtilities.GetProperty(rootElement, PropertyName);

            Assert.NotNull(property);
            Assert.Equal("A;B;C", property.Value);

            // On ChangeEventStage.Before the property should be renamed
            args = new ProjectConfigurationDimensionValueChangedEventArgs(
                project,
                ConfigurationDimensionChange.Rename,
                ChangeEventStage.After,
                DimensionName,
                "Renamed",
                "B");
            await provider.OnDimensionValueChangedAsync(args);

            property = BuildUtilities.GetProperty(rootElement, PropertyName);
            Assert.NotNull(property);
            Assert.Equal("A;Renamed;C", property.Value);
        }
Exemplo n.º 19
0
        public async Task GetProjectConfigurationDimensionsAsync_TFMs(string projectXml)
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new TargetFrameworkProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();
            var values = await provider.GetProjectConfigurationDimensionsAsync(unconfiguredProject);

            Assert.Single(values);
            var value = values.First();

            Assert.Equal(ConfigurationGeneral.TargetFrameworkProperty, value.Key);
            string[] dimensionValues = value.Value.ToArray();
            AssertEx.CollectionLength(dimensionValues, 2);
            Assert.Equal("netcoreapp1.0", dimensionValues[0]);
            Assert.Equal("net45", dimensionValues[1]);
        }
Exemplo n.º 20
0
        public void AppendPropertyValue_DefaultDelimiter()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>1;2</MyProperty>
  </PropertyGroup>
</Project>";

            var project = ProjectRootElementFactory.Create(projectXml);

            BuildUtilities.AppendPropertyValue(project, "1;2", "MyProperty", "3");
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal("1;2;3", property.Value);
        }
Exemplo n.º 21
0
        public void RenamePropertyValue_NonDefaultDelimiter()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>1|2|3</MyProperty>
  </PropertyGroup>
</Project>";

            var project = ProjectRootElementFactory.Create(projectXml);

            BuildUtilities.RenamePropertyValue(project, "1|2|3", "MyProperty", "2", "5", '|');
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal("1|5|3", property.Value);
        }
Exemplo n.º 22
0
        public void RemovePropertyValue_EmptyAfterRemove()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty>1</MyProperty>
  </PropertyGroup>
</Project>";

            var project = ProjectRootElementFactory.Create(projectXml);

            BuildUtilities.RemovePropertyValue(project, "1", "MyProperty", "1");
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal(string.Empty, property.Value);
        }
Exemplo n.º 23
0
        public void AppendPropertyValue_EmptyProperty()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup>
     <MyProperty/>
  </PropertyGroup>
</Project>";

            var project = ProjectRootElementFactory.Create(projectXml);

            BuildUtilities.AppendPropertyValue(project, "", "MyProperty", "1");
            var property = BuildUtilities.GetProperty(project, "MyProperty");

            Assert.NotNull(property);
            Assert.Equal("1", property.Value);
        }
Exemplo n.º 24
0
        public async Task PlatformProjectConfigurationDimensionProvider_GetProjectConfigurationDimensionsAsync()
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new PlatformProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();
            var values = await provider.GetProjectConfigurationDimensionsAsync(unconfiguredProject);

            Assert.Single(values);
            var value = values.First();

            Assert.Equal(ConfigurationGeneral.PlatformProperty, value.Key);
            string[] dimensionValues = value.Value.ToArray();
            Assert.Equal(3, dimensionValues.Length);
            Assert.Equal("AnyCPU", dimensionValues[0]);
            Assert.Equal("x64", dimensionValues[1]);
            Assert.Equal("x86", dimensionValues[2]);
        }
Exemplo n.º 25
0
        public async Task OnDimensionValueChanged_Remove_MissingValue()
        {
            var project             = ProjectRootElementFactory.Create(projectXml);
            var projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var provider            = new ConfigurationProjectConfigurationDimensionProvider(projectXmlAccessor);
            var unconfiguredProject = UnconfiguredProjectFactory.Create();

            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                unconfiguredProject,
                ConfigurationDimensionChange.Delete,
                ChangeEventStage.Before,
                ConfigurationGeneral.ConfigurationProperty,
                "NonExistantConfiguration");
            await Assert.ThrowsAsync <ArgumentException>(() => provider.OnDimensionValueChangedAsync(args));

            var property = BuildUtilities.GetProperty(project, Configurations);

            Assert.NotNull(property);
            Assert.Equal("Debug;Release;CustomConfiguration", property.Value);
        }
Exemplo n.º 26
0
        public async Task OnDimensionValueChanged(ConfigurationDimensionChange change, ChangeEventStage stage)
        {
            // No changes should happen for TFM so verify that the property is the same before and after
            var    project             = ProjectRootElementFactory.Create(ProjectXmlTFMs);
            var    projectXmlAccessor  = IProjectXmlAccessorFactory.Create(project);
            var    provider            = new TargetFrameworkProjectConfigurationDimensionProvider(projectXmlAccessor);
            var    unconfiguredProject = UnconfiguredProjectFactory.Create();
            var    property            = BuildUtilities.GetProperty(project, ConfigurationGeneral.TargetFrameworksProperty);
            string expectedTFMs        = property.Value;

            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                unconfiguredProject,
                change,
                stage,
                ConfigurationGeneral.TargetFrameworkProperty,
                "NewTFM");
            await provider.OnDimensionValueChangedAsync(args);

            Assert.NotNull(property);
            Assert.Equal(expectedTFMs, property.Value);
        }
Exemplo n.º 27
0
        public void GetOrAddProperty_FirstGroup()
        {
            string projectXml =
                @"<Project>
  <PropertyGroup/>
  <PropertyGroup/>
</Project>";

            var project = ProjectRootElementFactory.Create(projectXml);

            BuildUtilities.GetOrAddProperty(project, "MyProperty");
            Assert.Single(project.Properties);
            AssertEx.CollectionLength(project.PropertyGroups, 2);

            var group = project.PropertyGroups.First();

            Assert.Single(group.Properties);

            var property = group.Properties.First();

            Assert.Equal(string.Empty, property.Value);
        }
        public async Task PlatformProjectConfigurationDimensionProvider_OnDimensionValueChanged_Rename()
        {
            var rootElement     = ProjectRootElementFactory.Create(projectXml);
            var projectAccessor = IProjectAccessorFactory.Create(rootElement);
            var provider        = new PlatformProjectConfigurationDimensionProvider(projectAccessor);

            var project = UnconfiguredProjectFactory.Create();

            // Nothing should happen on platform rename as it's unsupported
            var args = new ProjectConfigurationDimensionValueChangedEventArgs(
                project,
                ConfigurationDimensionChange.Rename,
                ChangeEventStage.Before,
                ConfigurationGeneral.PlatformProperty,
                "RenamedPlatform",
                "x86");
            await provider.OnDimensionValueChangedAsync(args);

            var property = BuildUtilities.GetProperty(rootElement, Platforms);

            Assert.NotNull(property);
            Assert.Equal("AnyCPU;x64;x86", property.Value);

            // On ChangeEventStage.Before the property should be renamed
            args = new ProjectConfigurationDimensionValueChangedEventArgs(
                project,
                ConfigurationDimensionChange.Rename,
                ChangeEventStage.After,
                ConfigurationGeneral.PlatformProperty,
                "RenamedPlatform",
                "x86");
            await provider.OnDimensionValueChangedAsync(args);

            property = BuildUtilities.GetProperty(rootElement, Platforms);
            Assert.NotNull(property);
            Assert.Equal("AnyCPU;x64;x86", property.Value);
        }
Exemplo n.º 29
0
        public static IProjectAccessor Create(string xml = null)
        {
            var rootElement = ProjectRootElementFactory.Create(xml);

            return(Create(rootElement));
        }
Exemplo n.º 30
0
 public static void AssertProjectXml(string expected, ProjectRootElement actual)
 {
     AssertProjectXml(ProjectRootElementFactory.Create(expected), actual);
 }