示例#1
0
        public async Task TestSkipAnalyzersGlobalPropertiesProvider(
            bool implicitBuild,
            bool skipAnalyzersSettingTurnedOn)
        {
            UnconfiguredProject project = UnconfiguredProjectFactory.Create(
                unconfiguredProjectServices: UnconfiguredProjectServicesFactory.Create(
                    projectService: IProjectServiceFactory.Create()));
            IImplicitlyTriggeredBuildState buildState = IImplicityTriggeredBuildStateFactory.Create(implicitBuild);
            IProjectSystemOptions          options    = IProjectSystemOptionsFactory.ImplementGetSkipAnalyzersForImplicitlyTriggeredBuildAsync(ct => skipAnalyzersSettingTurnedOn);

            SkipAnalyzersGlobalPropertiesProvider provider = new SkipAnalyzersGlobalPropertiesProvider(
                project,
                buildState,
                options);

            IImmutableDictionary <string, string> properties = await provider.GetGlobalPropertiesAsync(CancellationToken.None);

            if (implicitBuild && skipAnalyzersSettingTurnedOn)
            {
                Assert.Equal(expected: 2, actual: properties.Count);
                Assert.Equal(expected: "true", actual: properties["IsImplicitlyTriggeredBuild"]);
                Assert.Equal(expected: "ImplicitBuild", actual: properties["FastUpToDateCheckIgnoresKinds"]);
            }
            else
            {
                Assert.Empty(properties);
            }
        }
        public async Task VerifyExpectedBehaviors(string projectPath, bool crossTargeting, bool implicitlyTriggeredBuild, string[] startupProjects, bool globalOptionEnabled, bool expectTargetFrameworkSet)
        {
            var projectService = IProjectServiceFactory.Create();

            var unconfiguredProject = UnconfiguredProjectFactory.Create(fullPath: projectPath);

            ConfiguredProject?configuredProject;

            if (crossTargeting)
            {
                var dimensions = Empty.PropertiesMap
                                 .Add("Configuration", "Debug")
                                 .Add("Platform", "AnyCPU")
                                 .Add("TargetFramework", "netcoreapp1.0");
                var projectConfiguration = new StandardProjectConfiguration("Debug|AnyCPU|netcoreapp1.0", dimensions);
                configuredProject = ConfiguredProjectFactory.Create(projectConfiguration: projectConfiguration, unconfiguredProject: unconfiguredProject);
            }
            else
            {
                var dimensions = Empty.PropertiesMap
                                 .Add("Configuration", "Debug")
                                 .Add("Platform", "AnyCPU");
                var projectConfiguration = new StandardProjectConfiguration("Debug|AnyCPU", dimensions);
                configuredProject = ConfiguredProjectFactory.Create(projectConfiguration: projectConfiguration, unconfiguredProject: unconfiguredProject);
            }

            var activeDebugFrameworkServices = IActiveDebugFrameworkServicesFactory.ImplementGetActiveDebuggingFrameworkPropertyAsync("myFramework1.0");

            var implicitlyTriggeredBuildState = IImplicityTriggeredBuildStateFactory.Create(implicitlyTriggeredBuild, startupProjects);

            var projectSystemOptions = IProjectSystemOptionsFactory.ImplementGetPreferSingleTargetBuildsForStartupProjectsAsync(ct => globalOptionEnabled);

            var provider = new StartupProjectSingleTargetGlobalBuildPropertyProvider(
                projectService,
                configuredProject,
                activeDebugFrameworkServices,
                implicitlyTriggeredBuildState,
                projectSystemOptions);

            var globalProperties = await provider.GetGlobalPropertiesAsync(CancellationToken.None);

            if (expectTargetFrameworkSet)
            {
                Assert.Equal(expected: 1, actual: globalProperties.Count);
                Assert.Equal(expected: "myFramework1.0", actual: globalProperties[ConfigurationGeneral.TargetFrameworkProperty]);
            }
            else
            {
                Assert.Empty(globalProperties);
            }
        }