Beispiel #1
0
        public async Task WhenDimensionsAreGiven_ThenThePropertyIsOnlySetInTheMatchingConfigurations()
        {
            var project = UnconfiguredProjectFactory.Create(
                fullPath: @"C:\alpha\beta\MyProject.csproj",
                configuredProject: ConfiguredProjectFactory.Create(
                    services: ConfiguredProjectServicesFactory.Create(
                        IPropertyPagesCatalogProviderFactory.Create(new()
            {
                {
                    "Project",
                    IPropertyPagesCatalogFactory.Create(new Dictionary <string, ProjectSystem.Properties.IRule>()
                    {
                        { "MyPage", IRuleFactory.Create(new Rule
                            {
                                Name       = "MyPage",
                                Properties = new()
                                {
                                    new TestProperty
                                    {
                                        Name       = "MyProperty",
                                        DataSource = new() { HasConfigurationCondition = true }
                                    }
                                }
                            }) }
                    })
                }
            }))));
            var projectConfigurations = GetConfigurations();

            var affectedConfigs = new List <string>();

            var queryCacheProvider = IProjectStateProviderFactory.Create(
                IProjectStateFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName, context) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create(
                    "MyProperty",
                    dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                    setValue: o => affectedConfigs.Add(config.Name))
            })));
            var targetDimensions = new List <(string dimension, string value)>
            {
                ("Configuration", "Release"),
                ("Platform", "x86")
            };

            var coreActionExecutor = new ProjectSetUIPropertyValueActionCore(
                queryCacheProvider,
                pageName: "MyPage",
                propertyName: "MyProperty",
                targetDimensions,
                prop => prop.SetValueAsync("new value"));

            await coreActionExecutor.OnBeforeExecutingBatchAsync(new[] { project });

            bool propertyUpdated = await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.True(propertyUpdated);
            Assert.Single(affectedConfigs);
            Assert.Contains("Release|x86", affectedConfigs);
        }
Beispiel #2
0
        public async Task WhenNoDimensionsAreGiven_ThenThePropertyIsSetInAllConfigurations()
        {
            var project = UnconfiguredProjectFactory.Create(
                fullPath: @"C:\alpha\beta\MyProject.csproj",
                configuredProject: ConfiguredProjectFactory.Create(
                    services: ConfiguredProjectServicesFactory.Create(
                        IPropertyPagesCatalogProviderFactory.Create(new()
            {
                {
                    "Project",
                    IPropertyPagesCatalogFactory.Create(new Dictionary <string, ProjectSystem.Properties.IRule>()
                    {
                        { "MyPage", IRuleFactory.Create(new Rule
                            {
                                Name       = "MyPage",
                                Properties = new()
                                {
                                    new TestProperty
                                    {
                                        Name       = "MyProperty",
                                        DataSource = new() { HasConfigurationCondition = true }
                                    }
                                }
                            }) }
                    })
                }
            }))));

            var projectConfigurations = GetConfigurations();

            var affectedConfigs = new List <string>();

            var queryCacheProvider = IProjectStateProviderFactory.Create(
                IProjectStateFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName, context) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create(
                    "MyProperty",
                    dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                    setValue: o => affectedConfigs.Add(config.Name))
            })));
            var emptyTargetDimensions = Enumerable.Empty <(string dimension, string value)>();

            var coreActionExecutor = new ProjectSetUIPropertyValueActionCore(
                queryCacheProvider,
                pageName: "MyPage",
                propertyName: "MyProperty",
                emptyTargetDimensions,
                prop => prop.SetValueAsync("new value"));

            await coreActionExecutor.OnBeforeExecutingBatchAsync(new[] { project });

            bool propertyUpdated = await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.True(propertyUpdated);
            Assert.Equal(expected: 4, actual: affectedConfigs.Count);
            foreach (var configuration in projectConfigurations)
            {
                Assert.Contains(configuration.Name, affectedConfigs);
            }
        }