public async Task GetProjectConfigurationDimensionsAsync_TFM()
        {
            using (var projectFile = new MsBuildProjectFile(ProjectXmlTFM))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new TargetFrameworkProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                var values = await provider.GetProjectConfigurationDimensionsAsync(unconfiguredProject);

                Assert.Empty(values);
            }
        }
        Load_FromExistentTestFileWithTargetImplementingComplexConditionalOverwritableProperty_ShouldReturnProjectContainingTargetWithOverwritableProperty()
        {
            IMsBuildProject projectFile = MsBuildProjectFile.Load("TestData/ProjectFiles/TargetWithProperties.tcsproj");

            IMsBuildTarget target = projectFile.GetChildren <IMsBuildTarget>()
                                    .First(t => t.Name.Equals("WithComplexConditionalOverwritableProperty"));

            IMsBuildProperty overwritableProperty =
                target.GetChildren <IMsBuildPropertyGroup>().First().GetChildren <IMsBuildProperty>()
                .First(p => p.Name.Equals("OverwritableProperty"));

            Assert.AreEqual(true, overwritableProperty.HasPublicSetter);
        }
        Load_FromExistentTestFileWithDocumentedTargetNamedCheckFileNameSyntax_ShouldContainTargetWithXmlHelp()
        {
            IMsBuildProject projectFile = MsBuildProjectFile.Load("TestData/ProjectFiles/Test.tcsproj");

            IMsBuildTarget target = projectFile.GetChildren <IMsBuildTarget>()
                                    .First(t => t.Name.Equals("CheckFileNameSyntax"));

            Assert.AreEqual("Checks the files from @(RelevantFiles) if it ends with '*.json'.",
                            target.Help.GetSectionContent("Synopsis", StringComparison.OrdinalIgnoreCase));
            Assert.AreEqual(
                "Prints an error with information about the item when it does not\nmatches the file extension 'json'. The printed error contains\ninformation about the affected item.",
                target.Help.GetSectionContent("DESCRIPTION", StringComparison.OrdinalIgnoreCase));
        }
        public async Task TargetFrameworkProjectConfigurationDimensionProvider_GetDefaultValuesForDimensionsAsync_TFMs(string projectXml)
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new TargetFrameworkProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                var values = await provider.GetDefaultValuesForDimensionsAsync(unconfiguredProject);

                Assert.Equal(1, values.Count());
                var value = values.First();
                Assert.Equal(ConfigurationGeneral.TargetFrameworkProperty, value.Key);
                Assert.Equal("netcoreapp1.0", value.Value);
            }
        }
        public async void ConfigurationProjectConfigurationDimensionProvider_GetDefaultValuesForDimensionsAsync()
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new ConfigurationProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                var values = await provider.GetDefaultValuesForDimensionsAsync(unconfiguredProject);

                Assert.Equal(1, values.Count());
                var value = values.First();
                Assert.Equal(ConfigurationGeneral.ConfigurationProperty, value.Key);
                Assert.Equal("Debug", value.Value);
            }
        }
示例#6
0
        public async void TargetFrameworkProjectConfigurationDimensionProvider_GetProjectConfigurationDimensionsAsync_TFMs(string projectXml)
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new TargetFrameworkProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                var values = await provider.GetProjectConfigurationDimensionsAsync(unconfiguredProject);

                Assert.Equal(1, values.Count());
                var value = values.First();
                Assert.Equal(ConfigurationGeneral.TargetFrameworkProperty, value.Key);
                string[] dimensionValues = value.Value.ToArray();
                Assert.Equal(2, dimensionValues.Length);
                Assert.Equal("netcoreapp1.0", dimensionValues[0]);
                Assert.Equal("net45", dimensionValues[1]);
            }
        }
        public async void ConfigurationProjectConfigurationDimensionProvider_GetProjectConfigurationDimensionsAsync()
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new ConfigurationProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                var values = await provider.GetProjectConfigurationDimensionsAsync(unconfiguredProject);

                Assert.Equal(1, values.Count());
                var value = values.First();
                Assert.Equal(ConfigurationGeneral.ConfigurationProperty, value.Key);
                string[] dimensionValues = value.Value.ToArray();
                Assert.Equal(3, dimensionValues.Length);
                Assert.Equal("Debug", dimensionValues[0]);
                Assert.Equal("Release", dimensionValues[1]);
                Assert.Equal("CustomConfiguration", dimensionValues[2]);
            }
        }
        public async Task PlatformProjectConfigurationDimensionProvider_GetProjectConfigurationDimensionsAsync()
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new PlatformProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                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]);
            }
        }
        public async void ConfigurationProjectConfigurationDimensionProvider_OnDimensionValueChanged_Remove_MissingValue()
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new ConfigurationProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);

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

                var property = BuildUtilities.GetProperty(projectFile.Project, Configurations);
                Assert.NotNull(property);
                Assert.Equal("Debug;Release;CustomConfiguration", property.Value);
            }
        }
        public async Task TargetFrameworkProjectConfigurationDimensionProvider_OnDimensionValueChanged(ConfigurationDimensionChange change, ChangeEventStage stage)
        {
            // No changes should happen for TFM so verify that the property is the same before and after
            using (var projectFile = new MsBuildProjectFile(ProjectXmlTFMs))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var    provider            = new TargetFrameworkProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var    unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);
                var    property            = BuildUtilities.GetProperty(projectFile.Project, ConfigurationGeneral.TargetFrameworksProperty);
                string expectedTFMs        = property.Value;

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

                Assert.NotNull(property);
                Assert.Equal(expectedTFMs, property.Value);
            }
        }
        public async void ConfigurationProjectConfigurationDimensionProvider_OnDimensionValueChanged_Rename()
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new ConfigurationProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);

                // On ChangeEventStage.Before nothing should be changed
                ProjectConfigurationDimensionValueChangedEventArgs args = new ProjectConfigurationDimensionValueChangedEventArgs(
                    unconfiguredProject,
                    ConfigurationDimensionChange.Rename,
                    ChangeEventStage.Before,
                    ConfigurationGeneral.ConfigurationProperty,
                    "RenamedConfiguration",
                    "CustomConfiguration");
                await provider.OnDimensionValueChangedAsync(args);

                var property = BuildUtilities.GetProperty(projectFile.Project, Configurations);
                Assert.NotNull(property);
                Assert.Equal("Debug;Release;CustomConfiguration", property.Value);

                // On ChangeEventStage.Before the property should be renamed
                args = new ProjectConfigurationDimensionValueChangedEventArgs(
                    unconfiguredProject,
                    ConfigurationDimensionChange.Rename,
                    ChangeEventStage.After,
                    ConfigurationGeneral.ConfigurationProperty,
                    "RenamedConfiguration",
                    "CustomConfiguration");
                await provider.OnDimensionValueChangedAsync(args);

                property = BuildUtilities.GetProperty(projectFile.Project, Configurations);
                Assert.NotNull(property);
                Assert.Equal("Debug;Release;RenamedConfiguration", property.Value);
            }
        }
        public async Task PlatformProjectConfigurationDimensionProvider_OnDimensionValueChanged_Rename()
        {
            using (var projectFile = new MsBuildProjectFile(projectXml))
            {
                IProjectXmlAccessor _projectXmlAccessor = IProjectXmlAccessorFactory.Create(projectFile.Project);
                var provider            = new PlatformProjectConfigurationDimensionProvider(_projectXmlAccessor);
                var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFile.Filename);

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

                var property = BuildUtilities.GetProperty(projectFile.Project, Platforms);
                Assert.NotNull(property);
                Assert.Equal("AnyCPU;x64;x86", property.Value);

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

                property = BuildUtilities.GetProperty(projectFile.Project, Platforms);
                Assert.NotNull(property);
                Assert.Equal("AnyCPU;x64;x86", property.Value);
            }
        }
        public void Load_FromExistentTestFile_ShouldNotReturnNullObject()
        {
            IMsBuildProject projectFile = MsBuildProjectFile.Load("TestData/ProjectFiles/Test.tcsproj");

            Assert.IsNotNull(projectFile);
        }
 protected override Expression <Func <MsBuildProjectFile, bool> > FindExisting(MsBuildProjectFile record)
 => existing
 => existing.ProjectType == record.ProjectType &&
 existing.MsBuildConditionalContructItemGroupPropertyGroupSectionId == record.MsBuildConditionalContructItemGroupPropertyGroupSectionId &&
 ((existing.MsBuildTargetListId == null && record.MsBuildTargetListId == null) || (existing.MsBuildTargetListId == record.MsBuildTargetListId));
        protected override IEnumerable <object> EnumerateReferences(MsBuildProjectFile record)
        {
            yield return(record.MsBuildConditionalContructItemGroupPropertyGroupSection);

            yield return(record.MsBuildTargetList);
        }
        public void Load_FromExistentTestFileWithTwoTargets_ShouldReturnObjectWithTwoContainingTargets()
        {
            IMsBuildProject projectFile = MsBuildProjectFile.Load("TestData/ProjectFiles/Test.tcsproj");

            Assert.AreEqual(2, projectFile.GetChildren <IMsBuildTarget>().Count);
        }
        Load_FromExistentTestFileWithOnePropertyGroupContainingThreeProperties_ShouldReturnObjectContainingThreeProperties()
        {
            IMsBuildProject projectFile = MsBuildProjectFile.Load("TestData/ProjectFiles/Test.tcsproj");

            Assert.AreEqual(3, projectFile.GetChildren <IMsBuildProperty>().Count);
        }
示例#18
0
 /// <summary>
 /// Loads the content as MSBuild project from the given file
 /// </summary>
 /// <param name="file">File from which the content should be loaded</param>
 /// <returns>MSBuild project representation</returns>
 private IMsBuildProject LoadMsBuildProject(IFile file)
 {
     return(MsBuildProjectFile.LoadContent(file.ReadAllText()));
 }