Beispiel #1
0
        public void WhenCreatingCategoriesFromARule_OneEntityIsCreatedPerCategory()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var context      = IQueryExecutionContextFactory.Create();
            var parentEntity = IEntityWithIdFactory.Create(key: "A", value: "B");
            var rule         = new Rule
            {
                Categories =
                {
                    new()
                    {
                        Name        = "Alpha",
                        DisplayName = "First category"
                    },
                    new()
                    {
                        Name        = "Beta",
                        DisplayName = "Second category"
                    }
                }
            };

            var result = CategoryDataProducer.CreateCategoryValues(context, parentEntity, rule, properties);

            Assert.Collection(result, new Action <IEntityValue>[]
            {
                entity => { assertEqual(entity, expectedName: "Alpha", expectedDisplayName: "First category"); },
                entity => { assertEqual(entity, expectedName: "Beta", expectedDisplayName: "Second category"); }
            });
        public async Task WhenAddingANewProfile_AndAProfileNameIsProvided_TheProvidedNameIsUsed()
        {
            var            project    = UnconfiguredProjectFactory.Create();
            ILaunchProfile?newProfile = null;

            var profiles = new List <ILaunchProfile>();
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                addOrUpdateProfileCallback: (profile, addToFront) => { profiles.Add(profile); newProfile = profile; },
                getProfilesCallback: (p) => ImmutableList.CreateRange(profiles));

            var queryVersionProvider = new LaunchSettingsQueryVersionProvider();
            var tracker = new LaunchSettingsTracker(project, launchSettingsProvider, queryVersionProvider);

            var handler = new ProjectLaunchProfileHandler(project, launchSettingsProvider, tracker);

            var context = IQueryExecutionContextFactory.Create();
            var parent  = IEntityWithIdFactory.Create("Project", "MyProject");

            var newProfileId = await handler.AddLaunchProfileAsync(context, parent, commandName : "Alpha", newProfileName : "Beta");

            Assert.NotNull(newProfile);
            Assert.Equal(expected: "Beta", actual: newProfile.Name);
            Assert.Equal(expected: "Alpha", actual: newProfile.CommandName);
            Assert.Single(profiles);

            Assert.NotNull(newProfileId);
            Assert.Equal(expected: "LaunchProfile", actual: newProfileId[ProjectModelIdentityKeys.SourceItemType]);
            Assert.Equal(expected: "Beta", actual: newProfileId[ProjectModelIdentityKeys.SourceItemName]);
        }
        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);
        }
        public void WhenCreatingEditorsFromAProperty_OneEntityIsReturnedPerEditor()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: true);

            var parentEntity = IEntityWithIdFactory.Create(key: "parentKey", value: "parentId");
            var rule         = new Rule();

            rule.BeginInit();
            rule.Properties.Add(
                new TestProperty
            {
                Name         = "MyProperty",
                ValueEditors =
                {
                    new ValueEditor {
                        EditorType = "Alpha"
                    },
                    new ValueEditor {
                        EditorType = "Beta"
                    },
                    new ValueEditor {
                        EditorType = "Gamma"
                    }
                }
            });
            rule.EndInit();

            var results = UIPropertyEditorDataProducer.CreateEditorValues(parentEntity, rule, "MyProperty", properties);

            Assert.Collection(results, new Action <IEntityValue>[]
            {
                entity => assertEqual(entity, expectedName: "Alpha"),
                entity => assertEqual(entity, expectedName: "Beta"),
                entity => assertEqual(entity, expectedName: "Gamma")
            });
        public async Task WhenDuplicatingAProfile_AndNameAndCommandAreProvided_TheNameAndCommandAreUsed()
        {
            var            project           = UnconfiguredProjectFactory.Create();
            ILaunchProfile?duplicatedProfile = null;

            var profiles = new List <ILaunchProfile>
            {
                new WritableLaunchProfile {
                    Name = "Alpha", CommandName = "Beta", ExecutablePath = @"C:\iguana\aardvark.exe"
                }.ToLaunchProfile()
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: profiles,
                addOrUpdateProfileCallback: (profile, addToFront) => { profiles.Add(profile); duplicatedProfile = profile; },
                getProfilesCallback: (p) => ImmutableList.CreateRange(profiles));

            var queryVersionProvider = new LaunchSettingsQueryVersionProvider();
            var tracker = new LaunchSettingsTracker(project, launchSettingsProvider, queryVersionProvider);

            var handler = new ProjectLaunchProfileHandler(project, launchSettingsProvider, tracker);

            var context = IQueryExecutionContextFactory.Create();
            var parent  = IEntityWithIdFactory.Create("Project", "MyProject");

            var duplicatedProfileId = await handler.DuplicateLaunchProfileAsync(context, parent, currentProfileName : "Alpha", newProfileName : "Gamma", newProfileCommandName : "Delta");

            Assert.Equal(expected: "Gamma", actual: duplicatedProfile !.Name);
            Assert.Equal(expected: "Delta", actual: duplicatedProfile !.CommandName);
            Assert.Equal(expected: @"C:\iguana\aardvark.exe", actual: duplicatedProfile !.ExecutablePath);
            Assert.Equal(expected: 2, actual: profiles.Count);

            Assert.NotNull(duplicatedProfileId);
            Assert.Equal(expected: "LaunchProfile", actual: duplicatedProfileId[ProjectModelIdentityKeys.SourceItemType]);
            Assert.Equal(expected: duplicatedProfile.Name, actual: duplicatedProfileId[ProjectModelIdentityKeys.SourceItemName]);
        }
Beispiel #6
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"); }
            });
        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 WhenCreatingAnEntityFromAParentAndEditor_TheIdIsTheEditorType()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: false);

            var parentEntity = IEntityWithIdFactory.Create(key: "parentId", value: "aaa");
            var editor       = new ValueEditor {
                EditorType = "My.Editor.Type"
            };

            var result = (UIPropertyEditorValue)UIPropertyEditorDataProducer.CreateEditorValue(parentEntity, editor, properties);

            Assert.Equal(expected: "My.Editor.Type", actual: result.Id[ProjectModelIdentityKeys.EditorName]);
        }
        public void WhenCreatingFromAParentAndRule_TheRuleNameIsTheEntityId()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus();

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

            Assert.Equal(expected: "MyRule", actual: propertyPage.Id[ProjectModelIdentityKeys.PropertyPageName]);
        }
        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"
            });
        public void WhenCategoryValueCreated_TheCategoryIsTheProviderState()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var parentEntity = IEntityWithIdFactory.Create(key: "Parent", value: "KeyValue");
            var rule         = new Rule();
            var category     = new Category {
                DisplayName = "CategoryDisplayName", Name = "CategoryName"
            };
            var order = 42;

            var result = (CategoryValue)CategoryDataProducer.CreateCategoryValue(parentEntity, rule, category, order, properties);

            Assert.Equal(expected: category, actual: ((IEntityValueFromProvider)result).ProviderState);
        }
        public void WhenCreatingFromAParentAndProperty_ThePropertyNameIsTheEntityId()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus();

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

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

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

            var parentEntity = IEntityWithIdFactory.Create(key: "A", value: "B");
            var category     = new Category {
                DisplayName = "CategoryDisplayName", Name = "MyCategoryName"
            };
            var order = 42;

            var result = (CategoryValue)CategoryDataProducer.CreateCategoryValue(parentEntity, category, order, properties);

            Assert.True(result.Id.TryGetValue(ProjectModelIdentityKeys.CategoryName, out string name));
            Assert.Equal(expected: "MyCategoryName", actual: name);
        }
Beispiel #14
0
        public void WhenCreatingAModel_ProviderStateIsTheCorrectType()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus(includeAllProperties: true);

            var propertyPage = (IEntityValueFromProvider)PropertyPageDataProducer.CreatePropertyPageValue(
                IEntityWithIdFactory.Create(key: "A", value: "B"),
                IPropertyPageQueryCacheFactory.Create(),
                new Rule {
                Name = "MyRule", DisplayName = "My Rule Display Name", Order = 42, PageTemplate = "generic"
            },
                debugChildRules: new List <Rule>(),
                properties);

            Assert.IsType <PropertyPageProviderState>(propertyPage.ProviderState);
        }
        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);
        }
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var parentEntity = IEntityWithIdFactory.Create(key: "Parent", value: "KeyValue");
            var rule         = new Rule();
            var category     = new Category {
                DisplayName = "CategoryDisplayName", Name = "CategoryName"
            };
            var order = 42;

            var result = (CategoryValue)CategoryDataProducer.CreateCategoryValue(parentEntity, rule, category, order, properties);

            Assert.Equal(expected: "CategoryDisplayName", actual: result.DisplayName);
            Assert.Equal(expected: "CategoryName", actual: result.Name);
            Assert.Equal(expected: 42, actual: result.Order);
        }
Beispiel #18
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]);
        }
Beispiel #19
0
        public void WhenPropertyValuesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus(includeAllProperties: true);

            var propertyPage = (PropertyPageValue)PropertyPageDataProducer.CreatePropertyPageValue(
                IEntityWithIdFactory.Create(key: "A", value: "B"),
                IPropertyPageQueryCacheFactory.Create(),
                new Rule {
                Name = "MyRule", DisplayName = "My Rule Display Name", Order = 42, PageTemplate = "generic"
            },
                debugChildRules: new List <Rule>(),
                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);
        }
        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);
        }
        public async Task WhenCreatingValuesFromAnIProperty_WeGetOneValuePerIEnumValue()
        {
            var properties = PropertiesAvailableStatusFactory.CreateSupportedValuesPropertiesAvailableStatus(includeAllProperties: true);

            var parentEntity = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue");
            var iproperty    = IPropertyFactory.CreateEnum(new[]
            {
                IEnumValueFactory.Create(displayName: "Alpha", name: "a"),
                IEnumValueFactory.Create(displayName: "Beta", name: "b"),
                IEnumValueFactory.Create(displayName: "Gamma", name: "c")
            });

            var result = await SupportedValueDataProducer.CreateSupportedValuesAsync(parentEntity, iproperty, properties);

            Assert.Collection(result, new Action <IEntityValue>[]
            {
                entity => assertEqual(entity, expectedDisplayName: "Alpha", expectedValue: "a"),
                entity => assertEqual(entity, expectedDisplayName: "Beta", expectedValue: "b"),
                entity => assertEqual(entity, expectedDisplayName: "Gamma", expectedValue: "c")
            });
        public async Task WhenRenamingAProfile_TheOldProfileIsRemovedAndTheNewProfileIsAdded()
        {
            var            project            = UnconfiguredProjectFactory.Create();
            ILaunchProfile?addedProfile       = null;
            string?        removedProfileName = null;

            var profiles = new List <ILaunchProfile>
            {
                new WritableLaunchProfile {
                    Name = "Alpha", CommandName = "Beta", ExecutablePath = @"C:\iguana\aardvark.exe"
                }.ToLaunchProfile()
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: profiles,
                addOrUpdateProfileCallback: (profile, addToFront) => { profiles.Add(profile); addedProfile = profile; },
                removeProfileCallback: (profileName) => { removedProfileName = profileName; profiles.RemoveAll(p => p.Name == profileName); },
                getProfilesCallback: (p) => ImmutableList.CreateRange(profiles));

            var queryVersionProvider = new LaunchSettingsQueryVersionProvider();
            var tracker = new LaunchSettingsTracker(project, launchSettingsProvider, queryVersionProvider);

            var handler = new ProjectLaunchProfileHandler(project, launchSettingsProvider, tracker);

            var context = IQueryExecutionContextFactory.Create();
            var parent  = IEntityWithIdFactory.Create("Project", "MyProject");

            var changes = await handler.RenameLaunchProfileAsync(context, parent, currentProfileName : "Alpha", newProfileName : "Gamma");

            Assert.True(changes.HasValue);

            (EntityIdentity removedProfileId, EntityIdentity addedProfileId) = changes.Value;

            Assert.Equal(expected: "Gamma", actual: addedProfile !.Name);
            Assert.Equal(expected: "Beta", actual: addedProfile !.CommandName);
            Assert.Equal(expected: @"C:\iguana\aardvark.exe", actual: addedProfile !.ExecutablePath);
            Assert.Single(profiles);

            Assert.Equal(expected: "LaunchProfile", actual: removedProfileId ![ProjectModelIdentityKeys.SourceItemType]);
        public void WhenCreatingMetadataFromAnEditor_AllMetadataIsReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIEditorMetadataAvailableStatus(
                includeName: true,
                includeValue: true);

            var parentEntity = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue");
            var editor       = new ValueEditor
            {
                Metadata =
                {
                    new() { Name = "Alpha", Value = "A" },
                    new() { Name = "Beta",  Value = "B" }
                }
            };

            var results = UIEditorMetadataProducer.CreateMetadataValues(
                parentEntity,
                editor,
                properties);

            Assert.Contains(results, entity => entity is UIEditorMetadataValue metadata && metadata.Name == "Alpha" && metadata.Value == "A");
            Assert.Contains(results, entity => entity is UIEditorMetadataValue metadata && metadata.Name == "Beta" && metadata.Value == "B");
        }