Beispiel #1
0
        public void InitForBooleanPropertyChange(ushort id, ushort pid, EModelPropertyType modelpropertytype, EModificationType modificationtype, bool value)
        {
            if (!IsInitialized)
            {
                Id               = id;
                TargetId         = pid;
                TargetItemType   = ETargetItemType.Property;
                ModificationType = modificationtype;

                ModificationDetails = (IModificationDetails)propertyFactory.Create(pid, value);

                IsInitialized = true;
            }
        }
        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 = IPropertyPageQueryCacheFactory.Create(
                projectConfigurations: ImmutableHashSet <ProjectConfiguration> .Empty.Add(defaultConfiguration).Add(otherConfiguration),
                defaultConfiguration: defaultConfiguration,
                bindToRule: (config, schemaName) => 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(
                parent,
                cache,
                schema,
                propertyName,
                requestedProperties);

            Assert.Single(results);
        }
        /// <inheritdoc />
        public void Add(PropertyInfo property, JsonSchema jsonSchema)
        {
            if (_thing == null)
            {
                throw new InvalidOperationException($"Thing is null, call {nameof(SetThing)} before build");
            }

            if (_properties == null || _option == null)
            {
                throw new InvalidOperationException($"ThingOption is null, call {nameof(SetThingOption)} before add");
            }

            var getter       = GetGetMethod(property);
            var propertyName = _option.PropertyNamingPolicy.ConvertName(jsonSchema.Name);

            if (jsonSchema.IsReadOnly.GetValueOrDefault())
            {
                _properties.Add(propertyName,
                                new ThingProperty(_thing, jsonSchema.IsReadOnly.GetValueOrDefault(), jsonSchema.IsWriteOnly.GetValueOrDefault(),
                                                  getter, null, null, null, null, property.Name));
                return;
            }

            var setter = GetSetMethod(property);

            _properties.Add(_option.PropertyNamingPolicy.ConvertName(jsonSchema.Name),
                            _factory.Create(property.PropertyType, jsonSchema, _thing, setter, getter, property.Name));
Beispiel #4
0
        private IProperty CreateProperty(
            ILocation declaration,
            ILocation bodyStart,
            ILocation bodyEnd,
            ArrowExpressionClauseSyntax expressionBody)
        {
            var underlyingSyntaxNode = underlyingObjectFactory.Create(expressionBody);

            return(propertyFactory.Create(declaration, bodyStart, bodyEnd, underlyingSyntaxNode));
        }
        public void WhenThePropertyIsConfigurationIndependent_ThenNoDimensionsAreProduced()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

            var parentEntity  = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue");
            var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C");
            var property      = IPropertyFactory.Create(
                dataSource: IDataSourceFactory.Create(hasConfigurationCondition: false));

            var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(parentEntity, configuration, property, properties);

            Assert.Empty(results);
        }
        public void WhenThePropertyIsConfigurationDependent_OneEntityIsCreatedPerDimension()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

            var parentEntity  = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue");
            var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C");
            var property      = IPropertyFactory.Create(
                dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true));

            var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(parentEntity, configuration, property, properties);

            // We can't guarantee an order for the dimensions, so just check that all the expected values are present.
            Assert.Contains(results, entity => entity is ConfigurationDimensionValue {
                Name: "Alpha", Value: "A"
            });
Beispiel #7
0
        public async Task WhenDimensionsAreGiven_ThenThePropertyIsOnlySetInTheMatchingConfigurations()
        {
            var project = UnconfiguredProjectFactory.Create(fullPath: @"C:\alpha\beta\MyProject.csproj");

            var projectConfigurations = GetConfigurations();

            var affectedConfigs = new List <string>();

            var queryCacheProvider = IPropertyPageQueryCacheProviderFactory.Create(
                IPropertyPageQueryCacheFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create("MyProperty", 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 });

            await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.Single(affectedConfigs);
            Assert.Contains("Release|x86", affectedConfigs);
        }
Beispiel #8
0
 // Creates a ConfiguredProject with a given ProjectConfiguration, and a method to
 // call when a property is set in that configuration.
 private static ConfiguredProject CreateConfiguredProject(ProjectConfiguration configuration, Action <string, object?> setValueCallback)
 {
     return(ConfiguredProjectFactory.Create(
                projectConfiguration: configuration,
                services: ConfiguredProjectServicesFactory.Create(
                    IPropertyPagesCatalogProviderFactory.Create(new()
     {
         {
             "Project",
             IPropertyPagesCatalogFactory.Create(new Dictionary <string, ProjectSystem.Properties.IRule>()
             {
                 { "MyPage", IRuleFactory.CreateFromRule(new Rule
                     {
                         Name = "MyPage",
                         Properties = new()
                         {
                             new TestProperty
                             {
                                 Name = "MyProperty",
                                 DataSource = new() { HasConfigurationCondition = true }
                             },
                             new TestProperty
                             {
                                 Name = "MyOtherProperty",
                                 DataSource = new() { HasConfigurationCondition = true }
                             }
                         }
                     },
                                                         properties: new[]
                     {
                         IPropertyFactory.Create(
                             "MyProperty",
                             dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                             setValue: v => setValueCallback("MyProperty", v)),
                         IPropertyFactory.Create(
                             "MyOtherProperty",
                             dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true),
                             setValue: v => setValueCallback("MyOtherProperty", v))
                     }) }
Beispiel #9
0
        public IProperty Map(string line)
        {
            // Assume line is csv
            var parts = line.Split(',');

            if (!int.TryParse(RemoveQuotes(parts[0]), out var propertyNumber))
            {
                // TODO: handle invalid or missing data
            }

            if (!double.TryParse(RemoveQuotes(parts[1]), out var propertySquareMeters))
            {
                // TODO: handle invalid or missing data
            }

            if (!double.TryParse(RemoveQuotes(parts[2]), out var propertyRooms))
            {
                // TODO: handle invalid or missing data
            }

            return(_propertyFactory.Create(propertyNumber, propertySquareMeters, propertyRooms));
        }
Beispiel #10
0
        public async Task WhenARuleContainsMultipleProperties_ThenOnlyTheSpecifiedPropertyIsSet()
        {
            var project = UnconfiguredProjectFactory.Create(fullPath: @"C:\alpha\beta\MyProject.csproj");
            var projectConfigurations = GetConfigurations();

            var unrelatedPropertySet = false;

            var queryCacheProvider = IPropertyPageQueryCacheProviderFactory.Create(
                IPropertyPageQueryCacheFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create("MyProperty", setValue: o => { }),
                IPropertyFactory.Create("NotTheCorrectProperty", setValue: o => unrelatedPropertySet = true)
            })));
            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 });

            await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.False(unrelatedPropertySet);
        }
Beispiel #11
0
        public async Task WhenNoDimensionsAreGiven_ThenThePropertyIsSetInAllConfigurations()
        {
            var project = UnconfiguredProjectFactory.Create(fullPath: @"C:\alpha\beta\MyProject.csproj");

            var projectConfigurations = GetConfigurations();

            var affectedConfigs = new List <string>();

            var queryCacheProvider = IPropertyPageQueryCacheProviderFactory.Create(
                IPropertyPageQueryCacheFactory.Create(
                    projectConfigurations,
                    bindToRule: (config, schemaName) => IRuleFactory.Create(
                        name: "MyPage",
                        properties: new[]
            {
                IPropertyFactory.Create("MyProperty", 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 });

            await coreActionExecutor.ExecuteAsync(project);

            coreActionExecutor.OnAfterExecutingBatch();

            Assert.Equal(expected: 4, actual: affectedConfigs.Count);
            foreach (var configuration in projectConfigurations)
            {
                Assert.Contains(configuration.Name, affectedConfigs);
            }
        }
Beispiel #12
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 #13
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);
            }
        }