public void VerifyFormatOfEnumerationParameterType() { var enumerationParameterType = new EnumerationParameterType(); var format = NumberFormat.Format(enumerationParameterType); Assert.AreEqual("@", format); }
public void TestComparer() { var type1 = new EnumerationParameterType { Name = "a" }; var type2 = new EnumerationParameterType { Name = "c" }; var para1 = new Parameter { ParameterType = type1 }; var para2 = new Parameter { ParameterType = type2 }; var comparer = new ParameterBaseComparer(); Assert.AreEqual(-2, comparer.Compare(para1, para2)); type1.Name = "d"; Assert.AreEqual(1, comparer.Compare(para1, para2)); type2.Name = "d"; Assert.AreEqual(0, comparer.Compare(para1, para2)); }
public void SetUp() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; this.uri = new Uri("http://www.rheagroup.com"); this.cache = new ConcurrentDictionary <CDP4Common.Types.CacheKey, Lazy <Thing> >(); this.ratioScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri); var valuedefLow = new EnumerationValueDefinition(Guid.NewGuid(), this.cache, this.uri); valuedefLow.ShortName = "low"; var valuedefMedium = new EnumerationValueDefinition(Guid.NewGuid(), this.cache, this.uri); valuedefMedium.ShortName = "medium"; this.booleanParameterType = new BooleanParameterType(Guid.NewGuid(), this.cache, this.uri); this.dateParameterType = new DateParameterType(Guid.NewGuid(), this.cache, this.uri); this.dateTimeParameterType = new DateTimeParameterType(Guid.NewGuid(), this.cache, this.uri); this.enumerationParameterType = new EnumerationParameterType(Guid.NewGuid(), this.cache, this.uri); this.enumerationParameterType.Name = "test"; this.enumerationParameterType.ValueDefinition.Add(valuedefLow); this.enumerationParameterType.ValueDefinition.Add(valuedefMedium); this.simpleQuantityKind = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri); this.simpleQuantityKind.PossibleScale.Add(this.ratioScale); this.simpleQuantityKind.DefaultScale = this.ratioScale; this.textParameterType = new TextParameterType(Guid.NewGuid(), this.cache, this.uri); this.timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), this.cache, this.uri); }
/// <summary> /// Returns the <see cref="DatatypeDefinitionEnumeration"/> representation of a <see cref="EnumerationParameterType"/> /// </summary> /// <param name="enumerationParameterType">The <see cref="EnumerationParameterType"/></param> /// <returns>the <see cref="DatatypeDefinitionEnumeration"/></returns> private DatatypeDefinitionEnumeration ToReqIfDatatypeDefinitionEnumeration(EnumerationParameterType enumerationParameterType) { var datatype = new DatatypeDefinitionEnumeration(); this.SetIdentifiableProperties(datatype, enumerationParameterType); for (var i = 0; i < enumerationParameterType.ValueDefinition.Count; i++) { var enumerationValueDefinition = enumerationParameterType.ValueDefinition[i]; var enumvalue = new EnumValue(); this.SetIdentifiableProperties(enumvalue, enumerationValueDefinition); enumvalue.LongName = enumerationValueDefinition.Name; enumvalue.Properties = new EmbeddedValue { OtherContent = enumerationValueDefinition.ShortName, Key = i }; datatype.SpecifiedValues.Add(enumvalue); } return(datatype); }
/// <summary> /// Validates the <param name="value"></param> to check whether it is a valid <see cref="EnumerationValueDefinition"/> of the <see cref="EnumerationParameterType"/> /// </summary> /// <param name="parameterType"> /// A <see cref="EnumerationParameterType"/> /// </param> /// <param name="value"> /// the string representation of a <see cref="EnumerationValueDefinition"/> value /// </param> /// <returns> /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message. /// </returns> public static ValidationResult Validate(this EnumerationParameterType parameterType, object value) { ValidationResult result; var stringValue = value as string; if (stringValue != null) { if (stringValue == DefaultValue) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } var values = stringValue.Split(Constants.MultiValueEnumSeparator); if (!parameterType.AllowMultiSelect && values.Count() > 1) { result.ResultKind = ValidationResultKind.Invalid; result.Message = $"The {parameterType.Name} Enumeration Parametertype does not allow multi-selection, multiple values seem to be selected"; return(result); } foreach (var enumerationValue in values) { var any = parameterType.ValueDefinition.Any(x => x.ShortName == enumerationValue.Trim()); if (!any) { var joinedShortnames = string.Empty; var sortedItems = parameterType.ValueDefinition.SortedItems.Values; foreach (var enumerationValueDefinition in sortedItems) { if (joinedShortnames == string.Empty) { joinedShortnames = enumerationValueDefinition.ShortName; } else { joinedShortnames = joinedShortnames + ", " + enumerationValueDefinition.ShortName; } } result.ResultKind = ValidationResultKind.Invalid; result.Message = $"The {parameterType.Name} Enumeration Parametertype does not contain the following value definition {enumerationValue}, allowed values are: {joinedShortnames}"; return(result); } } result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } result.ResultKind = ValidationResultKind.Invalid; result.Message = $"The {parameterType.Name} Enumeration Parametertype does not contain the following value definition {value}"; return(result); }
public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.permissionService = new Mock <IPermissionService>(); this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.serviceLocator = new Mock <IServiceLocator>(); this.navigation = new Mock <IThingDialogNavigationService>(); ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object); this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>()).Returns(this.navigation.Object); this.session = new Mock <ISession>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); var person = new Person(Guid.NewGuid(), null, null) { Container = this.siteDir }; this.session.Setup(x => x.ActivePerson).Returns(person); this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null); this.siteDir.Person.Add(person); var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null) { Name = "testRDL", ShortName = "test" }; this.enumerationParameterType = new EnumerationParameterType(Guid.NewGuid(), null, null) { Name = "enumerationParameterType", ShortName = "cat" }; var testValueDefinition = new EnumerationValueDefinition { Name = "definition1", ShortName = "def" }; this.enumerationParameterType.ValueDefinition.Add(testValueDefinition); this.siteDir.SiteReferenceDataLibrary.Add(rdl); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir); this.transaction = new ThingTransaction(transactionContext, null); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary)); var dal = new Mock <IDal>(); this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0)); this.session.Setup(x => x.Dal).Returns(dal.Object); dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider()); this.viewmodel = new EnumerationParameterTypeDialogViewModel(this.enumerationParameterType, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object); }
/// <summary> /// Validates the <param name="value"></param> to check whether it is a valid <see cref="EnumerationValueDefinition"/> of the <see cref="EnumerationParameterType"/> /// </summary> /// <param name="parameterType"> /// A <see cref="EnumerationParameterType"/> /// </param> /// <param name="value"> /// the string representation of a <see cref="EnumerationValueDefinition"/> value /// </param> /// <returns> /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message. /// </returns> public static ValidationResult Validate(this EnumerationParameterType parameterType, string value) { ValidationResult result; if (value == DefaultValue) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } var values = value.Split(','); if (!parameterType.AllowMultiSelect && values.Count() > 1) { result.ResultKind = ValidationResultKind.Invalid; result.Message = string.Format("The {0} Enumeration Parametertype does not allow multi-selection, multiple values seem to be selected", parameterType.Name); return(result); } foreach (var enumerationValue in values) { var any = parameterType.ValueDefinition.Any(x => x.ShortName == enumerationValue); if (!any) { var joinedShortnames = string.Empty; var sortedItems = parameterType.ValueDefinition.SortedItems.Values; foreach (var enumerationValueDefinition in sortedItems) { if (joinedShortnames == string.Empty) { joinedShortnames = enumerationValueDefinition.ShortName; } else { joinedShortnames = joinedShortnames + ", " + enumerationValueDefinition.ShortName; } } result.ResultKind = ValidationResultKind.Invalid; result.Message = string.Format("The {0} Enumeration Parametertype does not contain the following value definition {1}, allowed valuse are: {2}", parameterType.Name, enumerationValue, joinedShortnames); return(result); } } result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); }
/// <summary> /// Queries the <see cref="EnumerationValueDefinition"/> of the provided <see cref="EnumerationParameterType"/> /// and returns a formula containing the short-names as a string /// </summary> /// <param name="enumerationParameterType"> /// The <see cref="EnumerationParameterType"/> for which the <see cref="EnumerationValueDefinition"/> short-names are queried /// </param> /// <returns> /// a string containing the short-names of the <see cref="EnumerationValueDefinition"/>s, the string will be empty if the /// <see cref="EnumerationParameterType"/> does not contain any <see cref="EnumerationValueDefinition"/>s /// </returns> private string ValueDefinitionValidationFormula(EnumerationParameterType enumerationParameterType) { if (enumerationParameterType.ValueDefinition.Count != 0) { var valueDefinitions = new List <string> { "-" }; foreach (var enumerationValueDefinition in enumerationParameterType.ValueDefinition) { valueDefinitions.Add(((EnumerationValueDefinition)enumerationValueDefinition).ShortName); } return(string.Join(this.listSeparator, valueDefinitions.ToArray())); } return(string.Empty); }
/// <summary> /// Initializes a new instance of the <see cref="BudgetConfig"/> class /// </summary> /// <param name="elements">The root <see cref="ElementDefinition"/>s for which the budget is calculated</param> /// <param name="subSystemDef">The sub-system definition</param> /// <param name="parameterWithMargin">The parameter to used in the budget calculation</param> /// <param name="numberOfElementParameterType">The number of element parameter-type</param> /// <param name="systemLevel">The Parameter-type representing the system-level to use in the budget calculation by default</param> /// <param name="subsysLevelDef">The <see cref="EnumerationValueDefinition"/> representing a sub-system</param> /// <param name="equipmentLevelDef">The <see cref="EnumerationValueDefinition"/> representing an equipment</param> public BudgetConfig( IReadOnlyList <ElementDefinition> elements, IReadOnlyList <SubSystemDefinition> subSystemDef, BudgetParameterConfigBase parameterWithMargin, QuantityKind numberOfElementParameterType, EnumerationParameterType systemLevel, EnumerationValueDefinition subsysLevelDef, EnumerationValueDefinition equipmentLevelDef) { this.Elements = elements; this.NumberOfElementParameterType = numberOfElementParameterType; this.BudgetParameterConfig = parameterWithMargin; this.SubSystemDefinition = subSystemDef; this.SystemLevelToUse = systemLevel; this.SubSystemLevelEnum = subsysLevelDef; this.EquipmentLevelEnum = equipmentLevelDef; }
/// <summary> /// Execute the <see cref="ICommand"/> to create a <see cref="ParameterType"/> /// </summary> /// <typeparam name="TParameterType">A kind of <see cref="ParameterType"/></typeparam> /// <remarks> /// A new transaction is created to allow a <see cref="ParameterType"/> to be created "on the fly" /// </remarks> private void ExecuteCreateGenericParameterTypeCommand <TParameterType>() where TParameterType : ParameterType, new() { ParameterType parameterType; parameterType = new TParameterType(); parameterType.Name = this.SelectedRow.Identifiable.LongName; var enumDatatype = this.SelectedRow.Identifiable as DatatypeDefinitionEnumeration; if (enumDatatype != null) { var enumParameterType = new EnumerationParameterType { Name = enumDatatype.LongName }; foreach (var specifiedValue in enumDatatype.SpecifiedValues.OrderBy(x => x.Properties.Key)) { var enumerationDefinition = new EnumerationValueDefinition { Name = specifiedValue.LongName, ShortName = specifiedValue.Properties.OtherContent }; enumParameterType.ValueDefinition.Add(enumerationDefinition); } parameterType = enumParameterType; } var siteDirectory = this.Session.RetrieveSiteDirectory(); var transactionContext = TransactionContextResolver.ResolveContext(siteDirectory); var parameterTypeTransaction = new ThingTransaction(transactionContext); this.AddContainedThingToTransaction(parameterTypeTransaction, parameterType); var result = this.ThingDialogNavigationService.Navigate(parameterType, parameterTypeTransaction, this.Session, true, ThingDialogKind.Create, this.ThingDialogNavigationService); if (!result.HasValue || !result.Value) { return; } // refresh parameter type list and set the mapping to the new parameter type this.PopulateParameterTypes(); ((DatatypeDefinitionMappingRowViewModel)this.SelectedRow).FilterPossibleParameterTypes(); this.CastSelectedRow.MappedThing = this.ParameterTypes.Single(x => x.Iid == parameterType.Iid); }
public void VerifyThatAListOfEnumerationValueDefinitionsIsConverted() { var enumeration = new EnumerationParameterType { Name = "Technology Readiness Level", ShortName = "TRL" }; var level1 = new EnumerationValueDefinition { Name = "1", ShortName = "1" }; var level2 = new EnumerationValueDefinition { Name = "2", ShortName = "2" }; enumeration.ValueDefinition.Add(level1); enumeration.ValueDefinition.Add(level2); var result = this.converter.Convert(enumeration.ValueDefinition, null, null, null); Assert.AreEqual("1 | 2", result); }
public void VerifyThatParametersAreCorrectlyHandled() { var revisionProperty = typeof(ElementDefinition).GetProperty("RevisionNumber"); var group1 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri); var group11 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { ContainingGroup = group1 }; this.elementDef.ParameterGroup.Add(group1); this.elementDef.ParameterGroup.Add(group11); var type1 = new EnumerationParameterType(Guid.NewGuid(), this.cache, this.uri) { Name = "type1" }; var parameter1 = new Parameter(Guid.NewGuid(), this.cache, this.uri) { ParameterType = type1, Owner = this.domain }; var valueset = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri); valueset.Published = new ValueArray <string>(new List <string> { "1" }); valueset.Manual = new ValueArray <string>(new List <string> { "1" }); valueset.ValueSwitch = ParameterSwitchKind.MANUAL; parameter1.ValueSet.Add(valueset); this.elementDef.Parameter.Add(parameter1); var vm = new ElementDefinitionRowViewModel(this.elementDef, this.option, this.session.Object, null); var param1row = vm.ContainedRows.OfType <ParameterRowViewModel>().Single(); Assert.AreSame(parameter1, param1row.Thing); }
/// <summary> /// Serialize the <see cref="EnumerationParameterType"/> /// </summary> /// <param name="enumerationParameterType">The <see cref="EnumerationParameterType"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(EnumerationParameterType enumerationParameterType) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationParameterType.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("allowMultiSelect", this.PropertySerializerMap["allowMultiSelect"](enumerationParameterType.AllowMultiSelect)); jsonObject.Add("category", this.PropertySerializerMap["category"](enumerationParameterType.Category.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationParameterType.ClassKind))); jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationParameterType.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationParameterType.Iid)); jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](enumerationParameterType.IsDeprecated)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationParameterType.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationParameterType.Name)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationParameterType.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationParameterType.ShortName)); jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](enumerationParameterType.Symbol)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationParameterType.ThingPreference)); jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](enumerationParameterType.ValueDefinition.OrderBy(x => x, this.orderedItemComparer))); return(jsonObject); }
public void VerifyThatNumberOfValuesIsCorrect() { var compound = new CompoundParameterType(); var compound2 = new CompoundParameterType(); var scalar = new EnumerationParameterType(); var scalarc1 = new ParameterTypeComponent() { ParameterType = scalar }; compound2.Component.Add(scalarc1); var compound2Component = new ParameterTypeComponent() { ParameterType = compound2 }; compound.Component.Add(compound2Component); compound.Component.Add(scalarc1); Assert.AreEqual(2, compound.NumberOfValues); }
/// <summary> /// Initializes an instance of <see cref="BudgetConfig"/> from this <see cref="BudgetConfigDto"/> given the available <see cref="QuantityKind"/>, <see cref="EnumerationParameterType"/> and <see cref="Category"/> /// </summary> /// <param name="usedQuantityKinds">The available <see cref="QuantityKind"/></param> /// <param name="enumerationParameterTypes">The available <see cref="EnumerationParameterType"/></param> /// <param name="usedCategories">The available <see cref="Category"/></param> /// <returns>The <see cref="BudgetConfig"/></returns> public BudgetConfig ToBudgetConfig(IReadOnlyList <QuantityKind> usedQuantityKinds, IReadOnlyList <EnumerationParameterType> enumerationParameterTypes, IReadOnlyList <Category> usedCategories) { QuantityKind numberOfElementPt = null; EnumerationParameterType systemLevelPt = null; EnumerationValueDefinition subSystemLevelEnum = null; EnumerationValueDefinition equipmentLevelEnum = null; if (this.NumberOfElement.HasValue) { numberOfElementPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == this.NumberOfElement.Value); } if (this.SystemLevel.HasValue) { systemLevelPt = enumerationParameterTypes.FirstOrDefault(x => x.Iid == this.SystemLevel.Value); if (this.SubSystemLevelEnum.HasValue && systemLevelPt != null) { subSystemLevelEnum = systemLevelPt.ValueDefinition.FirstOrDefault(x => x.Iid == this.SubSystemLevelEnum.Value); } if (this.EquipmentLevelEnum.HasValue && systemLevelPt != null) { equipmentLevelEnum = systemLevelPt.ValueDefinition.FirstOrDefault(x => x.Iid == this.EquipmentLevelEnum.Value);; } } // resolve Parameter-Configuration var massConfig = this.ParameterConfig as MassParameterConfigDto; QuantityKind configMarginPt = null; BudgetParameterConfigBase parameterConfigBase = null; if (massConfig != null) { var configPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == massConfig.ParameterType); if (massConfig.MarginParameterType.HasValue) { configMarginPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == massConfig.MarginParameterType.Value); } var extraConfigList = new List <ExtraMassContributionConfiguration>(); foreach (var extraContributionDto in massConfig.ExtraContribution) { QuantityKind extraContributionMarginPt = null; var extraContributionPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == extraContributionDto.ParameterType); if (extraContributionDto.MarginParameterType.HasValue) { extraContributionMarginPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == extraContributionDto.MarginParameterType.Value); } var extraContributionCategories = new List <Category>(); foreach (var categoryId in extraContributionDto.Categories) { var category = usedCategories.FirstOrDefault(x => x.Iid == categoryId); if (category != null) { extraContributionCategories.Add(category); } } var extraContributionConfig = new ExtraMassContributionConfiguration(extraContributionCategories, extraContributionPt, extraContributionMarginPt); extraConfigList.Add(extraContributionConfig); } parameterConfigBase = new MassBudgetParameterConfig(new BudgetParameterMarginPair(configPt, configMarginPt), extraConfigList); } // resolve Parameter-Configuration var genericConfig = this.ParameterConfig as GenericParameterConfigDto; if (genericConfig != null) { var configPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == genericConfig.ParameterType); if (genericConfig.MarginParameterType.HasValue) { configMarginPt = usedQuantityKinds.FirstOrDefault(x => x.Iid == genericConfig.MarginParameterType.Value); } parameterConfigBase = new GenericBudgetParameterConfig(new BudgetParameterMarginPair(configPt, configMarginPt)); } // resolve sub-systems var subSystemDef = new List <SubSystemDefinition>(); foreach (var subSystemDefinitionDto in this.SubSystemDefinition) { var subSysCat = new List <Category>(); var equipmentCat = new List <Category>(); foreach (var catId in subSystemDefinitionDto.Categories) { var category = usedCategories.FirstOrDefault(x => x.Iid == catId); if (category != null) { subSysCat.Add(category); } } foreach (var catId in subSystemDefinitionDto.ElementCategories) { var category = usedCategories.FirstOrDefault(x => x.Iid == catId); if (category != null) { equipmentCat.Add(category); } } subSystemDef.Add(new SubSystemDefinition(subSysCat, equipmentCat)); } return(new BudgetConfig(null, subSystemDef, parameterConfigBase, numberOfElementPt, systemLevelPt, subSystemLevelEnum, equipmentLevelEnum)); }
public void Setup() { this.permissionService = new Mock <IPermissionService>(); this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true); this.thingDialognavigationService = new Mock <IThingDialogNavigationService>(); this.session = new Mock <ISession>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.stateList = new ActualFiniteStateList(Guid.NewGuid(), null, this.uri); this.state1 = new PossibleFiniteState(Guid.NewGuid(), null, this.uri) { Name = "state1" }; this.state2 = new PossibleFiniteState(Guid.NewGuid(), null, this.uri) { Name = "state2" }; this.posStateList = new PossibleFiniteStateList(Guid.NewGuid(), null, this.uri); this.posStateList.PossibleState.Add(this.state1); this.posStateList.PossibleState.Add(this.state2); this.posStateList.DefaultState = this.state1; this.actualState1 = new ActualFiniteState(Guid.NewGuid(), null, this.uri) { PossibleState = new List <PossibleFiniteState> { this.state1 }, Kind = ActualFiniteStateKind.MANDATORY }; this.actualState2 = new ActualFiniteState(Guid.NewGuid(), null, this.uri) { PossibleState = new List <PossibleFiniteState> { this.state2 }, Kind = ActualFiniteStateKind.MANDATORY }; this.stateList.ActualState.Add(this.actualState1); this.stateList.ActualState.Add(this.actualState2); this.stateList.PossibleFiniteStateList.Add(this.posStateList); this.option1 = new Option(Guid.NewGuid(), null, this.uri) { Name = "option1" }; this.option2 = new Option(Guid.NewGuid(), null, this.uri) { Name = "option2" }; this.qqParamType = new SimpleQuantityKind(Guid.NewGuid(), null, this.uri) { Name = "PTName", ShortName = "PTShortName" }; this.enum1 = new EnumerationValueDefinition(Guid.NewGuid(), null, this.uri) { Name = "enum1" }; this.enum2 = new EnumerationValueDefinition(Guid.NewGuid(), null, this.uri) { Name = "enum2" }; this.enumPt = new EnumerationParameterType(Guid.NewGuid(), null, this.uri); this.enumPt.ValueDefinition.Add(this.enum1); this.enumPt.ValueDefinition.Add(this.enum2); this.cptType = new CompoundParameterType(Guid.NewGuid(), null, this.uri) { Name = "APTName", ShortName = "APTShortName" }; this.cptType.Component.Add(new ParameterTypeComponent(Guid.NewGuid(), null, this.uri) { Iid = Guid.NewGuid(), ParameterType = this.qqParamType, ShortName = "c1" }); this.cptType.Component.Add(new ParameterTypeComponent(Guid.NewGuid(), null, this.uri) { Iid = Guid.NewGuid(), ParameterType = this.enumPt, ShortName = "c2" }); this.activeDomain = new DomainOfExpertise(Guid.NewGuid(), null, this.uri) { Name = "active", ShortName = "active" }; this.someotherDomain = new DomainOfExpertise(Guid.NewGuid(), null, this.uri) { Name = "other", ShortName = "other" }; this.parameter = new Parameter(Guid.NewGuid(), null, this.uri) { Owner = this.activeDomain, ParameterType = this.qqParamType }; this.cptParameter = new Parameter(Guid.NewGuid(), null, this.uri) { Owner = this.activeDomain, ParameterType = this.cptType, IsOptionDependent = true, StateDependence = this.stateList }; this.cptParameter.ValueSet.Add(this.GetNewParameterValueSet(this.option1, this.stateList.ActualState.First())); this.cptParameter.ValueSet.Add(this.GetNewParameterValueSet(this.option1, this.stateList.ActualState.Last())); this.cptParameter.ValueSet.Add(this.GetNewParameterValueSet(this.option2, this.stateList.ActualState.First())); this.cptParameter.ValueSet.Add(this.GetNewParameterValueSet(this.option2, this.stateList.ActualState.Last())); this.elementDefinition = new ElementDefinition(Guid.NewGuid(), null, this.uri) { Owner = this.activeDomain }; this.elementDefinitionForUsage1 = new ElementDefinition(Guid.NewGuid(), null, this.uri); this.elementUsage1 = new ElementUsage(Guid.NewGuid(), null, this.uri) { ElementDefinition = this.elementDefinitionForUsage1 }; this.elementDefinition.ContainedElement.Add(this.elementUsage1); this.elementDefinitionForUsage1.Parameter.Add(this.parameter); this.elementDefinitionForUsage1.Parameter.Add(this.cptParameter); this.iteration = new Iteration(Guid.NewGuid(), null, this.uri); this.iteration.Element.Add(this.elementDefinition); this.iteration.Element.Add(this.elementDefinitionForUsage1); this.iteration.Option.Add(this.option1); this.iteration.Option.Add(this.option2); this.model = new EngineeringModel(Guid.NewGuid(), null, this.uri); this.model.Iteration.Add(this.iteration); this.person = new Person(Guid.NewGuid(), null, this.uri) { GivenName = "test", Surname = "test" }; this.participant = new Participant(Guid.NewGuid(), null, this.uri) { Person = this.person, SelectedDomain = this.activeDomain }; this.session.Setup(x => x.ActivePerson).Returns(this.person); this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), null, this.uri); this.modelsetup.Participant.Add(this.participant); this.model.EngineeringModelSetup = this.modelsetup; this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.assembler = new Assembler(this.uri); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >()); }
public void VerifyThatPopulateParameterOrOverrideWorks(IViewModelBase <Thing> container, string scenario) { var revisionProperty = typeof(ElementUsage).GetProperty("RevisionNumber"); // TEST DATA var group1 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri); var group11 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { ContainingGroup = group1 }; this.elementDef.ParameterGroup.Add(group1); this.elementDef.ParameterGroup.Add(group11); this.elementUsage.ElementDefinition = this.elementDef; this.elementDef.ContainedElement.Clear(); var type1 = new EnumerationParameterType(Guid.NewGuid(), this.cache, this.uri) { Name = "type1" }; var parameter1 = new Parameter(Guid.NewGuid(), this.cache, this.uri) { ParameterType = type1, Owner = this.domain }; parameter1.ValueSet.Add(this.valueSet); var parameter2 = new Parameter(Guid.NewGuid(), this.cache, this.uri) { ParameterType = type1, Owner = this.domain }; parameter2.ValueSet.Add(this.valueSet); this.elementDef.Parameter.Add(parameter2); this.elementDef.Parameter.Add(parameter1); var override1 = new ParameterOverride(Guid.NewGuid(), this.cache, this.uri) { Parameter = parameter1, Owner = this.domain }; override1.ValueSet.Add(this.valueSetOverride); this.elementUsage.ParameterOverride.Add(override1); var vm = new ElementUsageRowViewModel(this.elementUsage, this.option, this.session.Object, container); // ************************************************************************************** // check added parameter Assert.AreEqual(2, vm.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Count()); var param2row = vm.ContainedRows.OfType <ParameterRowViewModel>().Single(); var override1row = vm.ContainedRows.OfType <ParameterOverrideRowViewModel>().Single(); Assert.AreSame(param2row.Thing, parameter2); Assert.AreSame(override1, override1row.Thing); // move parameter1, check update is correct parameter1.Group = group11; revisionProperty.SetValue(parameter1, 10); CDPMessageBus.Current.SendObjectChangeEvent(parameter1, EventKind.Updated); Assert.AreEqual(1, vm.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Count()); var group11row = vm.ContainedRows.OfType <ParameterGroupRowViewModel>().Single().ContainedRows.OfType <ParameterGroupRowViewModel>().Single(); Assert.AreSame(override1, group11row.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Single().Thing); // move parameter1 under group1, check update parameter1.Group = group1; revisionProperty.SetValue(parameter1, 20); CDPMessageBus.Current.SendObjectChangeEvent(parameter1, EventKind.Updated); Assert.AreEqual(1, vm.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Count()); var group1row = vm.ContainedRows.OfType <ParameterGroupRowViewModel>().Single(); Assert.AreSame(override1, group1row.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Single().Thing); // move parameter1 back to top, check update is correct parameter1.Group = null; revisionProperty.SetValue(parameter1, 30); CDPMessageBus.Current.SendObjectChangeEvent(parameter1, EventKind.Updated); Assert.AreEqual(2, vm.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Count()); Assert.AreEqual(0, group11row.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Count()); // remove override1 this.elementUsage.ParameterOverride.Clear(); revisionProperty.SetValue(this.elementUsage, 40); CDPMessageBus.Current.SendObjectChangeEvent(this.elementUsage, EventKind.Updated); Assert.AreEqual(2, vm.ContainedRows.OfType <ParameterOrOverrideBaseRowViewModel>().Count()); var param1row = vm.ContainedRows.OfType <ParameterRowViewModel>().SingleOrDefault(x => x.Thing == parameter1); Assert.IsNotNull(param1row); }
/// <summary> /// Persist the <see cref="EnumerationParameterType"/> containment tree to the ORM layer. Update if it already exists. /// This is typically used during the import of existing data to the Database. /// </summary> /// <param name="transaction"> /// The current <see cref="NpgsqlTransaction"/> to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="enumerationParameterType"> /// The <see cref="EnumerationParameterType"/> instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool UpsertContainment(NpgsqlTransaction transaction, string partition, EnumerationParameterType enumerationParameterType) { var results = new List <bool>(); foreach (var alias in this.ResolveFromRequestCache(enumerationParameterType.Alias)) { results.Add(this.AliasService.UpsertConcept(transaction, partition, alias, enumerationParameterType)); } foreach (var definition in this.ResolveFromRequestCache(enumerationParameterType.Definition)) { results.Add(this.DefinitionService.UpsertConcept(transaction, partition, definition, enumerationParameterType)); } foreach (var hyperLink in this.ResolveFromRequestCache(enumerationParameterType.HyperLink)) { results.Add(this.HyperLinkService.UpsertConcept(transaction, partition, hyperLink, enumerationParameterType)); } foreach (var valueDefinition in this.ResolveFromRequestCache(enumerationParameterType.ValueDefinition)) { results.Add(this.ValueDefinitionService.UpsertConcept(transaction, partition, (EnumerationValueDefinition)valueDefinition.V, enumerationParameterType, valueDefinition.K)); } return(results.All(x => x)); }
/// <summary> /// Initializes a new instance of the <see cref="EnumerationParameterTypeDialogViewModel"/> class. /// </summary> /// <param name="enumerationParameterType"> /// The text Parameter Type. /// </param> /// <param name="transaction"> /// The <see cref="ThingTransaction"/> that contains the log of recorded changes. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated /// </param> /// <param name="isRoot"> /// Assert if this <see cref="EnumerationParameterTypeDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="EnumerationParameterTypeDialogViewModel"/> performs /// </param> /// <param name="thingDialogNavigationService"> /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>. /// </param> /// <param name="container"> /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog /// </param> /// <param name="chainOfContainers"> /// The optional chain of containers that contains the <paramref name="container"/> argument /// </param> /// <exception cref="ArgumentException"> /// The container must be of type <see cref="ReferenceDataLibrary"/>. /// </exception> public EnumerationParameterTypeDialogViewModel(EnumerationParameterType enumerationParameterType, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(enumerationParameterType, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { this.ValueDefinition.CountChanged.Subscribe(_ => this.UpdateOkCanExecute()); }