Ejemplo n.º 1
0
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus(includeAllProperties: true);

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

            InitializeFakeRuleForProperty(property);

            var result = (UIPropertyValue)UIPropertyDataProducer.CreateUIPropertyValue(runtimeModel, id, cache, property, order: 42, 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.Equal(expected: 42, actual: result.Order);
            Assert.Equal(expected: "string", actual: result.Type);
        }
        public async Task WhenPropertyIsAnIEvaluatedProperty_GetUnevaluatedValueAsyncIsCalled()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyValuePropertiesAvailableStatus(
                includeEvaluatedValue: false,
                includeUnevaluatedValue: true);

            var mockEvaluatedProperty = new Mock <IEvaluatedProperty>();

            mockEvaluatedProperty.Setup(m => m.GetUnevaluatedValueAsync()).ReturnsAsync("unevaluated value");
            var property = mockEvaluatedProperty.Object;

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var id            = new EntityIdentity(key: "A", value: "B");
            var configuration = ProjectConfigurationFactory.Create(configuration: "Alpha|Beta|Gamma");

            var result = (UIPropertyValueValue)await UIPropertyValueDataProducer.CreateUIPropertyValueValueAsync(
                entityRuntime,
                id,
                configuration,
                property,
                properties);

            Assert.Equal(expected: "unevaluated value", actual: result.UnevaluatedValue);
            mockEvaluatedProperty.Verify(m => m.GetUnevaluatedValueAsync());
        }
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var dimension     = new KeyValuePair <string, string>("AlphaDimension", "AlphaDimensionValue");

            var result = (ConfigurationDimensionValue)ConfigurationDimensionDataProducer.CreateProjectConfigurationDimension(entityRuntime, dimension, properties);

            Assert.Equal(expected: "AlphaDimension", actual: result.Name);
            Assert.Equal(expected: "AlphaDimensionValue", actual: result.Value);
        }
        public void WhenPropertiesAreNotRequested_PropertyValuesAreNotReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus();

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var dimension     = new KeyValuePair <string, string>("AlphaDimension", "AlphaDimensionValue");

            var result = (ConfigurationDimensionValue)ConfigurationDimensionDataProducer.CreateProjectConfigurationDimension(entityRuntime, dimension, properties);

            Assert.Throws <MissingDataException>(() => result.Name);
            Assert.Throws <MissingDataException>(() => result.Value);
        }
Ejemplo n.º 5
0
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateSupportedValuesPropertiesAvailableStatus();

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var enumValue     = IEnumValueFactory.Create(displayName: "Hello", name: "MyValue");

            var result = (SupportedValueValue)SupportedValueDataProducer.CreateSupportedValue(entityRuntime, enumValue, properties);

            Assert.Equal(expected: "Hello", actual: result.DisplayName);
            Assert.Equal(expected: "MyValue", actual: result.Value);
        }
Ejemplo n.º 6
0
        public void WhenCreatingEntitiesFromAProjectConfiguration_OneEntityIsCreatedPerDimension()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

            var entityRuntimeModel = IEntityRuntimeModelFactory.Create();
            var configuration      = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C");
            var results            = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(entityRuntimeModel, configuration, 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 dimension && dimension.Name == "Alpha" && dimension.Value == "A");
            Assert.Contains(results, entity => entity is ConfigurationDimensionValue dimension && dimension.Name == "Beta" && dimension.Value == "B");
            Assert.Contains(results, entity => entity is ConfigurationDimensionValue dimension && dimension.Name == "Gamma" && dimension.Value == "C");
        }
        public static IQueryExecutionContext Create(IEntityRuntimeModel?runtimeModel = null)
        {
            var mock = new Mock <IQueryExecutionContext>();

            if (runtimeModel is null)
            {
                runtimeModel = IEntityRuntimeModelFactory.Create();
            }

            mock.SetupGet(m => m.EntityRuntime).Returns(runtimeModel);

            return(mock.Object);
        }
        public void WhenThePropertyIsConfigurationIndependent_ThenNoDimensionsAreProduced()
        {
            var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true);

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

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

            Assert.Empty(results);
        }
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: true);

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

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

            Assert.Equal(expected: "My.Editor.Type", actual: result.Name);
        }
        public void WhenAnEditorValueIsCreated_TheEditorIsTheProviderState()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyEditorPropertiesAvailableStatus(includeName: true);

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

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

            Assert.Equal(expected: editor, actual: ((IEntityValueFromProvider)result).ProviderState);
        }
        public void WhenPropertiesAreNotRequested_PropertyValuesAreNotReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIEditorMetadataAvailableStatus(includeAllProperties: false);

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var metadata      = new NameValuePair {
                Name = "Alpha", Value = "AlphaValue"
            };

            var result = (UIEditorMetadataValue)UIEditorMetadataProducer.CreateMetadataValue(entityRuntime, metadata, properties);

            Assert.Throws <MissingDataException>(() => result.Name);
            Assert.Throws <MissingDataException>(() => result.Value);
        }
        public void WhenCreatingAModel_ProviderStateConsistsOfCacheAndRule()
        {
            var properties = PropertiesAvailableStatusFactory.CreatePropertyPagePropertiesAvailableStatus();

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

            Assert.IsType <(IPropertyPageQueryCache, Rule)>(propertyPage.ProviderState);
        }
        public void WhenCategoryValueCreated_TheCategoryIsTheProviderState()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var id            = new EntityIdentity(key: "A", value: "B");
            var category      = new Category {
                DisplayName = "CategoryDisplayName", Name = "CategoryName"
            };
            var order = 42;

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

            Assert.Equal(expected: category, actual: ((IEntityValueFromProvider)result).ProviderState);
        }
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIEditorMetadataAvailableStatus(
                includeName: true,
                includeValue: true);

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var metadata      = new NameValuePair {
                Name = "Alpha", Value = "AlphaValue"
            };

            var result = (UIEditorMetadataValue)UIEditorMetadataProducer.CreateMetadataValue(entityRuntime, metadata, properties);

            Assert.Equal(expected: "Alpha", actual: result.Name);
            Assert.Equal(expected: "AlphaValue", actual: result.Value);
        }
        public void WhenPropertiesAreRequested_PropertyValuesAreReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateCategoryPropertiesAvailableStatus(includeAllProperties: true);

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var id            = new EntityIdentity(key: "A", value: "B");
            var category      = new Category {
                DisplayName = "CategoryDisplayName", Name = "CategoryName"
            };
            var order = 42;

            var result = (CategoryValue)CategoryDataProducer.CreateCategoryValue(entityRuntime, id, 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();

            var propertyPage = (PropertyPageValue)PropertyPageDataProducer.CreatePropertyPageValue(
                IEntityRuntimeModelFactory.Create(),
                new EntityIdentity(key: "A", value: "B"),
                IPropertyPageQueryCacheFactory.Create(),
                new Rule {
                Name = "MyRule", DisplayName = "My Rule Display Name", Order = 42, PageTemplate = "generic"
            },
                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);
        }
Ejemplo n.º 17
0
        public async Task WhenCreatingValuesFromAnIProperty_WeGetOneValuePerIEnumValue()
        {
            var properties = PropertiesAvailableStatusFactory.CreateSupportedValuesPropertiesAvailableStatus();

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            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(entityRuntime, 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")
            });
Ejemplo n.º 18
0
        public void WhenTheEntityIsCreated_TheProviderStateIsTheExpectedType()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyPropertiesAvailableStatus();

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

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

            var result = (UIPropertyValue)UIPropertyDataProducer.CreateUIPropertyValue(runtimeModel, id, cache, property, order: 42, properties);

            Assert.IsType <PropertyProviderState>(((IEntityValueFromProvider)result).ProviderState);
        }
        public async Task WhenThePropertyIsAnIIntProperty_ThenTheEvaluatedValueIsAnInt()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIPropertyValuePropertiesAvailableStatus(includeEvaluatedValue: true);

            var mockIntProperty = new Mock <IIntProperty>();

            mockIntProperty.Setup(m => m.GetValueAsIntAsync()).ReturnsAsync(42);
            var property = mockIntProperty.Object;

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var id            = new EntityIdentity(key: "A", value: "B");
            var configuration = ProjectConfigurationFactory.Create(configuration: "Alpha|Beta|Gamma");

            var result = (UIPropertyValueValue)await UIPropertyValueDataProducer.CreateUIPropertyValueValueAsync(
                entityRuntime,
                id,
                configuration,
                property,
                properties);

            Assert.Equal(expected: 42, actual: result.EvaluatedValue);
        }
        public void WhenCreatingMetadataFromAnEditor_AllMetadataIsReturned()
        {
            var properties = PropertiesAvailableStatusFactory.CreateUIEditorMetadataAvailableStatus(
                includeName: true,
                includeValue: true);

            var entityRuntime = IEntityRuntimeModelFactory.Create();
            var editor        = new ValueEditor
            {
                Metadata =
                {
                    new() { Name = "Alpha", Value = "A" },
                    new() { Name = "Beta",  Value = "B" }
                }
            };

            var results = UIEditorMetadataProducer.CreateMetadataValues(
                entityRuntime,
                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");
        }