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 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); }
protected override Task <IEnumerable <IEntityValue> > CreateValuesAsync(IQueryExecutionContext queryExecutionContext, IEntityValue parent, ContextAndRuleProviderState providerState) { (string versionKey, long versionNumber) = providerState.ProjectState.GetUnconfiguredProjectVersion(); queryExecutionContext.ReportInputDataVersion(versionKey, versionNumber); return(Task.FromResult(UIPropertyDataProducer.CreateUIPropertyValues(queryExecutionContext, parent, providerState.ProjectState, providerState.PropertiesContext, providerState.Rule, _properties))); }
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 } }; 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); }
protected override async Task <IEnumerable <IEntityValue> > CreateValuesAsync(IQueryExecutionContext queryExecutionContext, IEntityValue parent, ContextAndRuleProviderState providerState) { if (await providerState.ProjectState.GetMetadataVersionAsync() is (string versionKey, long versionNumber)) { queryExecutionContext.ReportInputDataVersion(versionKey, versionNumber); } return(UIPropertyDataProducer.CreateUIPropertyValues(queryExecutionContext, parent, providerState.ProjectState, providerState.PropertiesContext, providerState.Rule, _properties)); }
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 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]); }
protected override Task <IEntityValue?> TryCreateEntityOrNullAsync(IQueryExecutionContext queryExecutionContext, EntityIdentity id) { if (QueryProjectPropertiesContext.TryCreateFromEntityId(id, out QueryProjectPropertiesContext? propertiesContext) && id.TryGetValue(ProjectModelIdentityKeys.PropertyPageName, out string?propertyPageName) && id.TryGetValue(ProjectModelIdentityKeys.UIPropertyName, out string?propertyName)) { return(UIPropertyDataProducer.CreateUIPropertyValueAsync( queryExecutionContext, id, _projectService, propertiesContext, propertyPageName, propertyName, _properties)); } return(NullEntityValue); }
protected override Task <IEntityValue?> TryCreateEntityOrNullAsync(IEntityRuntimeModel runtimeModel, EntityIdentity id) { if (id.KeysCount == 3 && id.TryGetValue(ProjectModelIdentityKeys.ProjectPath, out string projectPath) && id.TryGetValue(ProjectModelIdentityKeys.PropertyPageName, out string propertyPageName) && id.TryGetValue(ProjectModelIdentityKeys.UIPropertyName, out string propertyName)) { return(UIPropertyDataProducer.CreateUIPropertyValueAsync( runtimeModel, id, _projectService, _queryCacheProvider, projectPath, propertyPageName, propertyName, _properties)); } return(NullEntityValue); }
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 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 SendRequestAsync(QueryProcessRequest <IEntityValue> request) { Requires.NotNull(request, nameof(request)); if ((request.RequestData as IEntityValueFromProvider)?.ProviderState is (IPropertyPageQueryCache cache, Rule rule)) { try { foreach (IEntityValue propertyValue in UIPropertyDataProducer.CreateUIPropertyValues(request.RequestData, cache, rule, _properties)) { await ResultReceiver.ReceiveResultAsync(new QueryProcessResult <IEntityValue>(propertyValue, request, ProjectModelZones.Cps)); } } catch (Exception ex) { request.QueryExecutionContext.ReportError(ex); } } await ResultReceiver.OnRequestProcessFinishedAsync(request); }
public async Task SendRequestAsync(QueryProcessRequest <IReadOnlyCollection <EntityIdentity> > request) { Requires.NotNull(request, nameof(request)); foreach (EntityIdentity requestId in request.RequestData) { if (requestId.KeysCount == 3 && requestId.TryGetValue(ProjectModelIdentityKeys.ProjectPath, out string path) && requestId.TryGetValue(ProjectModelIdentityKeys.PropertyPageName, out string propertyPageName) && requestId.TryGetValue(ProjectModelIdentityKeys.UIPropertyName, out string propertyName)) { try { IEntityValue?propertyValue = await UIPropertyDataProducer.CreateUIPropertyValueAsync( request.QueryExecutionContext.EntityRuntime, requestId, _projectService, _queryCacheProvider, path, propertyPageName, propertyName, _properties); if (propertyValue is not null) { await ResultReceiver.ReceiveResultAsync(new QueryProcessResult <IEntityValue>(propertyValue, request, ProjectModelZones.Cps)); } } catch (Exception ex) { request.QueryExecutionContext.ReportError(ex); } } } await ResultReceiver.OnRequestProcessFinishedAsync(request); }
protected override Task <IEnumerable <IEntityValue> > CreateValuesAsync(IEntityValue parent, PropertyPageProviderState providerState) { return(Task.FromResult(UIPropertyDataProducer.CreateUIPropertyValues(parent, providerState.Cache, providerState.Rule, _properties))); }