示例#1
0
        public void WhenCreatingPropertiesFromARule_OneEntityIsCreatedPerProperty()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus(includeAllProperties: true);

            var context      = IQueryExecutionContextFactory.Create();
            var parentEntity = IEntityWithIdFactory.Create(key: "Parent", value: "ParentRule");
            var cache        = IProjectStateFactory.Create();
            var rule         = new Rule();

            rule.BeginInit();
            rule.Properties.AddRange(new[]
            {
                new TestProperty {
                    Name = "Alpha"
                },
                new TestProperty {
                    Name = "Beta"
                },
                new TestProperty {
                    Name = "Gamma"
                },
            });
            rule.EndInit();

            var result = UIPropertyDataProducer.CreateUIPropertyValues(context, parentEntity, cache, QueryProjectPropertiesContext.ProjectFile, rule, properties);

            Assert.Collection(result, new Action <IEntityValue>[]
            {
                entity => { assertEqual(entity, expectedName: "Alpha"); },
                entity => { assertEqual(entity, expectedName: "Beta"); },
                entity => { assertEqual(entity, expectedName: "Gamma"); }
            });
示例#2
0
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus(includeAllProperties: true);

            var context  = IQueryExecutionContextFactory.Create();
            var id       = new EntityIdentity(key: "PropertyName", value: "A");
            var cache    = IProjectStateFactory.Create();
            var property = new TestProperty
            {
                Name        = "A",
                DisplayName = "Page A",
                Description = "This is the description for Page A",
                HelpUrl     = "https://mypage",
                Category    = "general",
                Visible     = false,
                DataSource  = new DataSource {
                    HasConfigurationCondition = false
                }
            };

            InitializeFakeRuleForProperty(property);

            var result = (UIPropertyValue)UIPropertyDataProducer.CreateUIPropertyValue(context, id, cache, QueryProjectPropertiesContext.ProjectFile, property, order: 42, requestedProperties: properties);

            Assert.Equal(expected: "A", actual: result.Name);
            Assert.Equal(expected: "Page A", actual: result.DisplayName);
            Assert.Equal(expected: "This is the description for Page A", actual: result.Description);
            Assert.True(result.ConfigurationIndependent);
            Assert.Equal(expected: "general", actual: result.CategoryName);
            Assert.False(result.IsVisible);
            Assert.Equal(expected: 42, actual: result.Order);
            Assert.Equal(expected: "string", actual: result.Type);
        }
        public async Task WhenThePropertyIsConfigurationIndependent_ThenOnlyOneValueIsReturned()
        {
            var parent = IEntityWithIdFactory.Create(key: "ParentName", value: "Aardvark");

            var defaultConfiguration = ProjectConfigurationFactory.Create("Alpha|Beta");
            var otherConfiguration   = ProjectConfigurationFactory.Create("Delta|Gamma");
            var cache = IProjectStateFactory.Create(
                projectConfigurations: ImmutableHashSet <ProjectConfiguration> .Empty.Add(defaultConfiguration).Add(otherConfiguration),
                defaultConfiguration: defaultConfiguration,
                bindToRule: (config, schemaName, context) => IRuleFactory.Create(
                    name: "ParentName",
                    properties: new[] { IPropertyFactory.Create("MyProperty") }));

            var schema = new Rule
            {
                Properties =
                {
                    new TestProperty {
                        Name = "MyProperty", DataSource = new(){ HasConfigurationCondition                            = false }
                    }
                }
            };
            var propertyName        = "MyProperty";
            var requestedProperties = PropertiesAvailableStatusFactory.CreateUIPropertyValuePropertiesAvailableStatus();
            var results             = await UIPropertyValueDataProducer.CreateUIPropertyValueValuesAsync(
                IQueryExecutionContextFactory.Create(),
                parent,
                cache,
                schema,
                propertiesContext : QueryProjectPropertiesContext.ProjectFile,
                propertyName,
                requestedProperties);

            Assert.Single(results);
        }
        public void WhenCreatingFromAParentAndRule_TheRuleNameIsTheEntityId()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus(includeAllProperties: true);

            var propertyPage = (PropertyPageValue)PropertyPageDataProducer.CreatePropertyPageValue(
                IQueryExecutionContextFactory.Create(),
                IEntityWithIdFactory.Create(key: "ParentKey", value: "ParentValue"),
                IProjectStateFactory.Create(),
                QueryProjectPropertiesContext.ProjectFile,
                new Rule {
                Name = "MyRule", DisplayName = "My Rule Display Name", Order = 42, PageTemplate = "generic"
            },
                requestedProperties: properties);

            Assert.Equal(expected: "MyRule", actual: propertyPage.Id[ProjectModelIdentityKeys.PropertyPageName]);
        }
        public void WhenCreatingAModel_ProviderStateIsTheCorrectType()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus(includeAllProperties: true);

            var propertyPage = (IEntityValueFromProvider)PropertyPageDataProducer.CreatePropertyPageValue(
                IQueryExecutionContextFactory.Create(),
                IEntityWithIdFactory.Create(key: "A", value: "B"),
                IProjectStateFactory.Create(),
                QueryProjectPropertiesContext.ProjectFile,
                new Rule {
                Name = "MyRule", DisplayName = "My Rule Display Name", Order = 42, PageTemplate = "generic"
            },
                requestedProperties: properties);

            Assert.IsType <ContextAndRuleProviderState>(propertyPage.ProviderState);
        }
示例#6
0
        public void WhenCreatingFromAParentAndProperty_ThePropertyNameIsTheEntityId()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus();

            var context      = IQueryExecutionContextFactory.Create();
            var parentEntity = IEntityWithIdFactory.Create(key: "parent", value: "A");
            var cache        = IProjectStateFactory.Create();
            var property     = new TestProperty {
                Name = "MyProperty"
            };
            var order = 42;

            InitializeFakeRuleForProperty(property);

            var result = (UIPropertyValue)UIPropertyDataProducer.CreateUIPropertyValue(context, parentEntity, cache, QueryProjectPropertiesContext.ProjectFile, property, order, properties);

            Assert.Equal(expected: "MyProperty", actual: result.Id[ProjectModelIdentityKeys.UIPropertyName]);
        }
        public void WhenPropertyValuesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus(includeAllProperties: true);

            var propertyPage = (PropertyPageValue)PropertyPageDataProducer.CreatePropertyPageValue(
                IQueryExecutionContextFactory.Create(),
                IEntityWithIdFactory.Create(key: "A", value: "B"),
                IProjectStateFactory.Create(),
                QueryProjectPropertiesContext.ProjectFile,
                new Rule {
                Name = "MyRule", DisplayName = "My Rule Display Name", Order = 42, PageTemplate = "generic"
            },
                requestedProperties: properties);

            Assert.Equal(expected: "MyRule", actual: propertyPage.Name);
            Assert.Equal(expected: "My Rule Display Name", actual: propertyPage.DisplayName);
            Assert.Equal(expected: 42, actual: propertyPage.Order);
            Assert.Equal(expected: "generic", actual: propertyPage.Kind);
        }
示例#8
0
        public void WhenTheEntityIsCreated_TheProviderStateIsTheExpectedType()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus();

            var context  = IQueryExecutionContextFactory.Create();
            var id       = new EntityIdentity(key: "PropertyName", value: "A");
            var cache    = IProjectStateFactory.Create();
            var property = new TestProperty
            {
                Name = "A"
            };
            var rule = new Rule();

            rule.BeginInit();
            rule.Properties.Add(property);
            rule.EndInit();

            var result = (UIPropertyValue)UIPropertyDataProducer.CreateUIPropertyValue(context, id, cache, QueryProjectPropertiesContext.ProjectFile, property, order: 42, requestedProperties: properties);

            Assert.IsType <PropertyProviderState>(((IEntityValueFromProvider)result).ProviderState);
        }
示例#9
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);
        }
示例#10
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);
            }
        }