Exemplo n.º 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 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]);
        }
        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);
        }
Exemplo n.º 4
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 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]);
        }
Exemplo n.º 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 WhenAnEditorValueIsCreated_TheEditorIsTheProviderState()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: true);

            var context = IQueryExecutionContextFactory.Create();
            var id      = new EntityIdentity(key: "EditorKey", value: "bbb");
            var editor  = new ValueEditor {
                EditorType = "My.Editor.Type"
            };

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

            Assert.Equal(expected: editor, actual: ((IEntityValueFromProvider)result).ProviderState);
        }
        public void WhenCreatingAnEntityFromAParentAndEditor_TheIdIsTheEditorType()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: false);

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

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

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

            var context = IQueryExecutionContextFactory.Create();
            var id      = new EntityIdentity(key: "EditorKey", value: "bbb");
            var editor  = new ValueEditor {
                EditorType = "My.Editor.Type"
            };

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

            Assert.Equal(expected: "My.Editor.Type", actual: result.Name);
        }
Exemplo n.º 10
0
        public void WhenCategoryValueCreated_TheCategoryIsTheProviderState()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var context      = IQueryExecutionContextFactory.Create();
            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(context, parentEntity, rule, category, order, properties);

            Assert.Equal(expected: category, actual: ((IEntityValueFromProvider)result).ProviderState);
        }
        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 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]);
        }
Exemplo n.º 13
0
        public void WhenCreatingACategory_TheIdIsTheCategoryName()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

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

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

            Assert.True(result.Id.TryGetValue(ProjectModelIdentityKeys.CategoryName, out string name));
            Assert.Equal(expected: "MyCategoryName", actual: name);
        }
Exemplo n.º 14
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]);
        }
Exemplo n.º 15
0
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var context      = IQueryExecutionContextFactory.Create();
            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(context, 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);
        }
        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);
        }
Exemplo n.º 17
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);
        }
        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 WhenCreatingEditorsFromAProperty_OneEntityIsReturnedPerEditor()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: true);

            var context      = IQueryExecutionContextFactory.Create();
            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(context, 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")
            });