public void VerifyThatGroupPathReturnsExpectedResultWhenGroupedAndNonDefaultDelimiterIsUsed() { var requirementsSpecification = new RequirementsSpecification() { ShortName = "spec" }; var requirement = new Requirement() { ShortName = "req" }; requirementsSpecification.Requirement.Add(requirement); var requirementsGroupA = new RequirementsGroup() { ShortName = "a" }; var requirementsGroupAA = new RequirementsGroup() { ShortName = "a_a" }; requirementsGroupA.Group.Add(requirementsGroupAA); requirementsSpecification.Group.Add(requirementsGroupA); requirement.Group = requirementsGroupAA; Assert.AreEqual("spec;a;a_a;req", requirement.GroupPath(';')); }
public void VerifyThatPathReturnsTheExpectedResultWithDefaultDelimiter() { var iteration = new Iteration(); var spec = new RequirementsSpecification() { ShortName = "spec" }; var group_a = new RequirementsGroup() { ShortName = "a" }; var group_a_a = new RequirementsGroup() { ShortName = "a_a" }; var group_a_a_a = new RequirementsGroup() { ShortName = "a_a_a" }; iteration.RequirementsSpecification.Add(spec); Assert.AreEqual("a", group_a.Path()); Assert.AreEqual("a_a", group_a_a.Path()); Assert.AreEqual("a_a_a", group_a_a_a.Path()); group_a_a.Group.Add(group_a_a_a); Assert.AreEqual("a_a.a_a_a", group_a_a_a.Path()); group_a.Group.Add(group_a_a); Assert.AreEqual("a.a_a.a_a_a", group_a_a_a.Path()); spec.Group.Add(group_a); Assert.AreEqual("spec.a.a_a.a_a_a", group_a_a_a.Path()); }
public void VerifyThatAddingRequirementGroupUpdatesRequirementsSpecificationContainedRows() { var row = new RequirementsSpecificationRowViewModel(this.reqSpec, this.session.Object, this.requirementBrowserViewModel); var groups = row.ContainedRows.Where(x => x.Thing is RequirementsGroup); Assert.AreEqual(2, groups.Count()); var grp1Row = row.ContainedRows.Single(x => x.Thing.Iid == this.grp1.Iid); Assert.AreEqual(2, grp1Row.ContainedRows.Count); var newgrp = new RequirementsGroup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.grp1.Group.Add(newgrp); this.revision.SetValue(this.grp1, 2); this.revision.SetValue(this.reqSpec, 2); CDPMessageBus.Current.SendObjectChangeEvent(this.grp1, EventKind.Updated); CDPMessageBus.Current.SendObjectChangeEvent(this.reqSpec, EventKind.Updated); Assert.AreEqual(3, grp1Row.ContainedRows.Count); this.reqSpec.Group.Remove(this.grp2); this.revision.SetValue(this.reqSpec, 3); CDPMessageBus.Current.SendObjectChangeEvent(this.reqSpec, EventKind.Updated); groups = row.ContainedRows.Where(x => x.Thing is RequirementsGroup); Assert.AreEqual(1, groups.Count()); }
public void VerifyThatContainedGroupsReturnsExpectedResult() { var topGroup = new RequirementsGroup(); var group_1 = new RequirementsGroup(); var group_2 = new RequirementsGroup(); var group_1_1 = new RequirementsGroup(); var group_1_2 = new RequirementsGroup(); topGroup.Group.Add(group_1); topGroup.Group.Add(group_2); group_1.Group.Add(group_1_1); group_1.Group.Add(group_1_2); var containedGroups = new List <RequirementsGroup>(); containedGroups.Add(group_1); containedGroups.Add(group_2); containedGroups.Add(group_1_1); containedGroups.Add(group_1_2); var actualContainedGroups = topGroup.ContainedGroup().ToList(); CollectionAssert.AreEquivalent(containedGroups, actualContainedGroups); }
/// <summary> /// Returns a <see cref="SpecObjectType"/> associated to a <see cref="RequirementsGroup"/> and a set of rules /// </summary> /// <param name="group">The <see cref="RequirementsGroup"/></param> /// <param name="appliedRules">The set of <see cref="ParameterizedCategoryRule"/></param> /// <param name="parameterTypeMap">The map of <see cref="ParameterType"/> to <see cref="DatatypeDefinition"/></param> /// <returns>The <see cref="SpecObjectType"/></returns> public SpecObjectType ToReqIfSpecObjectType(RequirementsGroup group, IReadOnlyCollection <ParameterizedCategoryRule> appliedRules, IReadOnlyDictionary <ParameterType, DatatypeDefinition> parameterTypeMap) { if (group == null) { throw new ArgumentNullException("group"); } var specObjectType = new SpecObjectType { Identifier = Guid.NewGuid().ToString(), LongName = GroupNamePrefix + (appliedRules.Any() ? string.Join(", ", appliedRules.Select(r => r.ShortName)) : group.ClassKind.ToString()), LastChange = DateTime.UtcNow, Description = appliedRules.Any() ? string.Join(", ", appliedRules.Select(r => r.Name)) : group.ClassKind.ToString() }; this.AddCommonAttributeDefinition(specObjectType); var parameterTypes = appliedRules.SelectMany(r => r.ParameterType).Distinct(); foreach (var parameterType in parameterTypes) { var attibuteDef = this.ToReqIfAttributeDefinition(parameterType, parameterTypeMap); specObjectType.SpecAttributes.Add(attibuteDef); } return(specObjectType); }
public void VerifyThatComparerWorks() { var spec = new RequirementsSpecification(); var grp = new RequirementsGroup() { ShortName = "a" }; var req1 = new Requirement { ShortName = "a" }; var req2 = new Requirement { ShortName = "b" }; var req3 = new Requirement { ShortName = "x" }; spec.Requirement.Add(req1); spec.Requirement.Add(req2); spec.Requirement.Add(req3); var specRow = new RequirementsSpecificationRowViewModel(spec, this.session.Object, null); var grprow = new RequirementsGroupRowViewModel(grp, this.session.Object, null, specRow); var reqrow = new RequirementRowViewModel(req1, this.session.Object, specRow); var reqrow2 = new RequirementRowViewModel(req2, this.session.Object, specRow); var reqrow3 = new RequirementRowViewModel(req3, this.session.Object, specRow); Assert.AreEqual(-1, comparer.Compare(reqrow, reqrow2)); Assert.AreEqual(-1, comparer.Compare(reqrow, grprow)); Assert.AreEqual(1, comparer.Compare(grprow, reqrow)); Assert.AreEqual(-1, comparer.Compare(reqrow3, grprow)); Assert.AreEqual(1, comparer.Compare(grprow, reqrow3)); }
public void VerifyCreateNewDefinitionDialogViewModel() { var group = new RequirementsGroup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.assembler.Cache.TryAdd(new CacheKey(group.Iid, null), new Lazy <Thing>(() => group)); var clone = group.Clone(false); clone.Definition.Add(this.simpleDefinition); this.transaction.CreateOrUpdate(clone); this.viewmodel = new DefinitionDialogViewModel(this.simpleDefinition, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone, null); Assert.IsNotNull(this.viewmodel); //Test Note features this.viewmodel.CreateNoteCommand.Execute(null); Assert.AreEqual(this.viewmodel.Note.Count, 2); this.viewmodel.SelectedNote = this.viewmodel.Note[0]; Assert.IsTrue(this.viewmodel.SelectedNote.Value.Equals(this.simpleDefinition.Note[0])); this.viewmodel.DeleteNoteCommand.Execute(null); Assert.AreEqual(this.viewmodel.Note.Count, 1); //Test Example features this.viewmodel.CreateExampleCommand.Execute(null); Assert.AreEqual(this.viewmodel.Example.Count, 2); this.viewmodel.SelectedExample = this.viewmodel.Example[0]; Assert.IsTrue(this.viewmodel.SelectedExample.Value.Equals(this.simpleDefinition.Example[0])); this.viewmodel.DeleteExampleCommand.Execute(null); Assert.AreEqual(this.viewmodel.Example.Count, 1); }
/// <summary> /// Build the <see cref="SpecHierarchy"/> object for a <see cref="RequirementsGroup"/> /// </summary> /// <param name="reqSpec">The <see cref="RequirementsSpecification"/> containing the <see cref="Requirement"/>s</param> /// <param name="requirementGroup">The <see cref="RequirementsGroup"/> associated with the <see cref="SpecHierarchy"/> to build</param> /// <returns>The <see cref="SpecHierarchy"/></returns> private SpecHierarchy BuildGroupHierarchy(RequirementsSpecification reqSpec, RequirementsGroup requirementGroup) { var specHierarchy = new SpecHierarchy { Identifier = Guid.NewGuid().ToString(), LastChange = DateTime.UtcNow, Object = this.requirementsGroupMap[requirementGroup] }; foreach (var group in requirementGroup.Group) { var child = this.BuildGroupHierarchy(reqSpec, group); specHierarchy.Children.Add(child); } foreach (var requirement in reqSpec.Requirement.Where(x => x.Group == requirementGroup)) { var child = new SpecHierarchy { Identifier = Guid.NewGuid().ToString(), LastChange = DateTime.UtcNow, Object = this.requirementMap[requirement] }; specHierarchy.Children.Add(child); } return(specHierarchy); }
/// <summary> /// Performs the drop operation for a <see cref="RequirementsGroup"/> payload /// </summary> /// <param name="requirementGroupPayload"> /// The <see cref="RequirementsGroup"/> that was dropped into this <see cref="RequirementsSpecification"/> /// </param> private async Task OnRequirementGroupDrop(RequirementsGroup requirementGroupPayload) { var context = TransactionContextResolver.ResolveContext(this.Thing); var transaction = new ThingTransaction(context); var previousRequirementSpec = requirementGroupPayload.GetContainerOfType <RequirementsSpecification>(); // Add the RequirementGroup to the RequirementsSpecification represented by this RowViewModel var requirementsSpecificationClone = this.Thing.Clone(false); requirementsSpecificationClone.Group.Add(requirementGroupPayload); transaction.CreateOrUpdate(requirementsSpecificationClone); if (previousRequirementSpec != this.Thing) { // Update the requirements that were inside any of the groups that have been dropped var previousRequirementSpecRow = ((RequirementsBrowserViewModel)this.ContainerViewModel).ReqSpecificationRows.Single(x => x.Thing == previousRequirementSpec); var droppedRequirementGroups = requirementGroupPayload.ContainedGroup().ToList(); droppedRequirementGroups.Add(requirementGroupPayload); foreach (var keyValuePair in previousRequirementSpecRow.requirementContainerGroupCache) { if (!droppedRequirementGroups.Contains(keyValuePair.Value)) { continue; } var requirementClone = keyValuePair.Key.Clone(false); requirementClone.Group = null; transaction.CreateOrUpdate(requirementClone); } } await this.DalWrite(transaction); }
public void Setup() { this.npgsqlTransaction = null; this.securityContext = new Mock <ISecurityContext>(); // There is a chain d -> e -> f this.requirementsGroupA = new RequirementsGroup { Iid = Guid.NewGuid() }; this.requirementsGroupB = new RequirementsGroup { Iid = Guid.NewGuid() }; this.requirementsGroupC = new RequirementsGroup { Iid = Guid.NewGuid() }; this.requirementsGroupF = new RequirementsGroup { Iid = Guid.NewGuid() }; this.requirementsGroupE = new RequirementsGroup { Iid = Guid.NewGuid(), Group = { this.requirementsGroupF.Iid } }; this.requirementsGroupD = new RequirementsGroup { Iid = Guid.NewGuid(), Group = { this.requirementsGroupE.Iid } }; this.requirementsSpecification = new RequirementsSpecification { Iid = Guid.NewGuid(), Group = { this.requirementsGroupA.Iid, this.requirementsGroupB.Iid, this.requirementsGroupC.Iid, this.requirementsGroupD.Iid, this.requirementsGroupE.Iid, this.requirementsGroupF.Iid } }; this.requirementsSpecificationService = new Mock <IRequirementsSpecificationService>(); this.requirementsSpecificationService .Setup( x => x.GetDeep( this.npgsqlTransaction, It.IsAny <string>(), null, It.IsAny <ISecurityContext>())).Returns( new List <RequirementsGroup> { this.requirementsGroupA, this.requirementsGroupB, this.requirementsGroupC, this.requirementsGroupD, this.requirementsGroupE, this.requirementsGroupF }); }
/// <summary> /// Add a nested <see cref="RequirementsContainer"/> row /// </summary> /// <param name="group">The <see cref="RequirementsContainer"/> to add</param> private void AddReqGroupRow(RequirementsGroup group) { var row = new RequirementsGroupRowViewModel(group, this.Session, this, this.TopParentRow); this.ContainedRows.SortedInsert(row, ChildRowComparer); this.TopParentRow.GroupCache[group] = row; }
public void VerifyThatRequirementsAreSortedBeforeGroups() { var requirement = new Requirement() { ShortName = "REQ", Owner = this.domain }; var requirementsGroup = new RequirementsGroup() { ShortName = "GRP", Owner = this.domain }; this.requirementsSpecification.Group.Add(requirementsGroup); this.requirementsSpecification.Requirement.Add(requirement); var vm = new RequirementsSpecificationEditorViewModel(this.requirementsSpecification, this.session.Object, null, null, null, null); Assert.AreEqual(3, vm.ContainedRows.Count); var specRow = vm.ContainedRows[0]; Assert.AreEqual(this.requirementsSpecification, specRow.Thing); var reqRow = vm.ContainedRows[1]; Assert.AreEqual(requirement, reqRow.Thing); var reqGroupRow = vm.ContainedRows[2]; Assert.AreEqual(requirementsGroup, reqGroupRow.Thing); }
public void VerifyThatGetContainerOfTypeWorks() { var sitedir = new SiteDirectory(Guid.NewGuid(), null, null); var siterdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null); var unit = new DerivedUnit(Guid.NewGuid(), null, null); sitedir.SiteReferenceDataLibrary.Add(siterdl); siterdl.Unit.Add(unit); Assert.AreSame(siterdl, unit.GetContainerOfType(typeof(ReferenceDataLibrary))); Assert.AreSame(siterdl, unit.GetContainerOfType(typeof(SiteReferenceDataLibrary))); Assert.AreSame(siterdl, unit.GetContainerOfType(typeof(ModelReferenceDataLibrary))); Assert.AreSame(sitedir, unit.GetContainerOfType(typeof(SiteDirectory))); Assert.IsNull(unit.GetContainerOfType(typeof(Iteration))); Assert.AreSame(siterdl, unit.GetContainerOfType <SiteReferenceDataLibrary>()); Assert.AreSame(sitedir, unit.GetContainerOfType <SiteDirectory>()); Assert.IsNull(unit.GetContainerOfType <ModelReferenceDataLibrary>()); Assert.AreSame(siterdl, unit.GetContainerOfType <ReferenceDataLibrary>()); var requirementsgroup1 = new RequirementsGroup(Guid.NewGuid(), null, null); var requirementsgroup2 = new RequirementsGroup(Guid.NewGuid(), null, null); requirementsgroup1.Group.Add(requirementsgroup2); Assert.AreSame(requirementsgroup1, requirementsgroup2.GetContainerOfType <RequirementsGroup>()); Assert.AreSame(requirementsgroup1, requirementsgroup2.GetContainerOfType(typeof(RequirementsGroup))); }
public void VerifyThatGroupsCanBeAddedOrRemoved() { var row = new RequirementsSpecificationRowViewModel(this.spec2, this.session.Object, this.requirementBrowserViewModel); row.IsParametricConstraintDisplayed = true; row.IsSimpleParameterValuesDisplayed = true; var groups = row.ContainedRows.Where(x => x.Thing is RequirementsGroup); Assert.AreEqual(3, groups.Count()); var grp1Row = row.ContainedRows.Single(x => x.Thing.Iid == this.grp1.Iid); Assert.AreEqual(5, grp1Row.ContainedRows.Count); var newgrp = new RequirementsGroup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.grp1.Group.Add(newgrp); this.revision.SetValue(this.grp1, 2); this.revision.SetValue(this.spec2, 2); CDPMessageBus.Current.SendObjectChangeEvent(this.grp1, EventKind.Updated); CDPMessageBus.Current.SendObjectChangeEvent(this.spec2, EventKind.Updated); Assert.AreEqual(6, grp1Row.ContainedRows.Count); this.spec2.Group.Remove(this.grp2); this.revision.SetValue(this.spec2, 3); CDPMessageBus.Current.SendObjectChangeEvent(this.spec2, EventKind.Updated); groups = row.ContainedRows.Where(x => x.Thing is RequirementsGroup); Assert.AreEqual(2, groups.Count()); }
public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.session = new Mock <ISession>(); this.assembler = new Assembler(this.uri); this.cache = this.assembler.Cache; 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.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true); this.session = new Mock <ISession>(); this.person = new Person(Guid.NewGuid(), this.cache, this.uri) { ShortName = "test" }; this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri) { SelectedDomain = null, Person = this.person }; this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); this.modelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri) { Name = "model" }; this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri); this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri); this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri); this.reqGroup = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri); this.modelSetup.IterationSetup.Add(this.iterationSetup); this.modelSetup.Participant.Add(this.participant); this.panelNavigation = new Mock <IPanelNavigationService>(); this.dialogNavigation = new Mock <IThingDialogNavigationService>(); this.domain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri) { Name = "test" }; this.reqSpec.Owner = this.domain; this.iteration.RequirementsSpecification.Add(this.reqSpec); this.iteration.IterationSetup = this.iterationSetup; this.model.EngineeringModelSetup = this.modelSetup; this.model.Iteration.Add(this.iteration); this.reqSpec.Group.Add(this.reqGroup); this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString()); this.session.Setup(x => x.ActivePerson).Returns(this.person); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > { { this.iteration, new Tuple <DomainOfExpertise, Participant>(null, this.participant) } }); }
public void Setup() { this.session = new Mock <ISession>(); this.permissionService = new Mock <IPermissionService>(); this.uri = new Uri("http://test.com"); this.siteDir = new SiteDirectory(Guid.NewGuid(), null, this.uri); this.domain = new DomainOfExpertise(Guid.NewGuid(), null, this.uri); this.siteDir.Domain.Add(this.domain); this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), null, this.uri); this.modelsetup.ActiveDomain.Add(this.domain); this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), null, this.uri); this.reqGroup = new RequirementsGroup(Guid.NewGuid(), null, this.uri); this.engineeringModel = new EngineeringModel(Guid.NewGuid(), null, this.uri) { EngineeringModelSetup = this.modelsetup }; this.iteration = new Iteration(Guid.NewGuid(), null, this.uri); this.requirementsSpecification = new RequirementsSpecification(Guid.NewGuid(), null, this.uri); this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), null, this.uri); this.iterationSetup = new IterationSetup(Guid.NewGuid(), null, this.uri); this.iteration.IterationSetup = this.iterationSetup; var person = new Person(Guid.NewGuid(), null, this.uri); this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), null, this.uri) { Name = "test" }; person.DefaultDomain = this.domainOfExpertise; this.engineeringModelSetup.ActiveDomain.Add(this.domainOfExpertise); this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); this.session.Setup(x => x.ActivePerson).Returns(person); this.siteDir.Domain.Add(this.domainOfExpertise); this.engineeringModel.Iteration.Add(this.iteration); this.iteration.RequirementsSpecification.Add(this.requirementsSpecification); this.iteration.RequirementsSpecification.Add(this.reqSpec); this.requirementsSpecification.Group.Add(this.reqGroup); this.engineeringModel.EngineeringModelSetup = this.engineeringModelSetup; var transactionContext = TransactionContextResolver.ResolveContext(this.engineeringModel); this.thingTransaction = new ThingTransaction(transactionContext, null); 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()); }
/// <summary> /// Removes a <see cref="RequirementsGroup"/> from the <see cref="ContainedRows"/> /// </summary> /// <param name="requirementsGroup"> /// The <see cref="RequirementsGroup"/> that is to be removed /// </param> private void RemoveRequirementsGroupRow(RequirementsGroup requirementsGroup) { var row = this.ContainedRows.SingleOrDefault(x => x.Thing == requirementsGroup); if (row != null) { this.ContainedRows.RemoveAndDispose(row); } }
public void Setup() { this.session = new Mock <ISession>(); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); var dal = new Mock <IDal>(); dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider()); this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0)); this.session.Setup(x => x.Dal).Returns(dal.Object); this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri); this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri); this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri) { RequiredRdl = this.srdl }; this.siteDir.Model.Add(this.modelsetup); this.modelsetup.IterationSetup.Add(this.iterationsetup); this.siteDir.SiteReferenceDataLibrary.Add(this.srdl); this.modelsetup.RequiredRdl.Add(this.mrdl); this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri) { EngineeringModelSetup = this.modelsetup }; this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri) { IterationSetup = this.iterationsetup }; this.requirement = new Requirement(Guid.NewGuid(), this.cache, this.uri); this.relationalExpression = new RelationalExpression(Guid.NewGuid(), this.cache, this.uri); this.parametricConstraint = new ParametricConstraint(Guid.NewGuid(), this.cache, this.uri); this.requirement.ParametricConstraint.Add(this.parametricConstraint); this.parametricConstraint.Expression.Add(this.relationalExpression); this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri); this.reqSpec.Requirement.Add(this.requirement); this.grp = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri); this.reqSpec.Group.Add(this.grp); this.cache.TryAdd(new CacheKey(this.reqSpec.Iid, null), new Lazy <Thing>(() => this.reqSpec)); this.model.Iteration.Add(this.iteration); this.iteration.RequirementsSpecification.Add(this.reqSpec); this.clone = this.parametricConstraint.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.iteration); this.thingTransaction = new ThingTransaction(transactionContext, this.clone); this.dateRelationalExpression = new RelationalExpression(Guid.NewGuid(), this.cache, this.uri); this.dateRelationalExpression.ParameterType = new DateParameterType(); this.dateRelationalExpression.Value = new ValueArray <string>(new[] { "2019-12-31" }); }
/// <summary> /// Returns a <see cref="RequirementsGroup"/> out of an <see cref="SpecObject"/> /// </summary> /// <param name="specObject">The <see cref="SpecObject"/></param> /// <returns>The <see cref="RequirementsGroup"/></returns> private RequirementsGroup CreateRequirementGroup(SpecObject specObject) { SpecTypeMap specTypeMapping; if (!this.typeMap.TryGetValue(specObject.Type, out specTypeMapping)) { // The instance of this type shall not be generated return(null); } var reqNumber = this.groupMap.Count + 1; var name = grpPrefix + reqNumber.ToString("D4"); var group = new RequirementsGroup { Name = string.IsNullOrWhiteSpace(specObject.LongName) ? name : specObject.LongName, ShortName = name, Owner = this.Owner }; group.Category.AddRange(specTypeMapping.Categories); foreach (var value in specObject.Values) { var attributeMap = specTypeMapping.AttributeDefinitionMap.SingleOrDefault(x => x.AttributeDefinition == value.AttributeDefinition); if (attributeMap == null || attributeMap.MapKind == AttributeDefinitionMapKind.NONE) { continue; } string theValue; switch (attributeMap.MapKind) { case AttributeDefinitionMapKind.FIRST_DEFINITION: this.SetDefinition(group, value); break; case AttributeDefinitionMapKind.NAME: theValue = this.GetAttributeValue(value); group.Name = theValue; break; case AttributeDefinitionMapKind.SHORTNAME: theValue = this.GetAttributeValue(value); group.ShortName = theValue; break; case AttributeDefinitionMapKind.PARAMETER_VALUE: this.SetParameterValue(group, value); break; } } this.groupMap.Add(specObject, group); return(group); }
/// <summary> /// Removes a nested <see cref="RequirementsContainer"/> row /// </summary> /// <param name="group">The <see cref="RequirementsContainer"/> to remove</param> private void RemoveReqGroupRow(RequirementsGroup group) { var row = this.ContainedRows.SingleOrDefault(x => x.Thing == group); if (row != null) { this.TopParentRow.GroupCache.Remove(group); this.ContainedRows.Remove(row); row.Dispose(); } }
/// <summary> /// Performs the drop operation for a <see cref="RequirementsGroup"/> payload /// </summary> /// <param name="requirementGroupPayload"> /// The <see cref="RequirementsGroup"/> that was dropped into this <see cref="RequirementsSpecification"/> /// </param> private async Task OnRequirementGroupDrop(RequirementsGroup requirementGroupPayload) { var firstRow = this.ContainedRows.OfType <RequirementsGroupRowViewModel>().FirstOrDefault(); if (firstRow == null) { var context = TransactionContextResolver.ResolveContext(this.Thing); var transaction = new ThingTransaction(context); var previousRequirementSpec = requirementGroupPayload.GetContainerOfType <RequirementsSpecification>(); // Add the RequirementGroup to the RequirementsSpecification represented by this RowViewModel var requirementsSpecificationClone = this.Thing.Clone(false); requirementsSpecificationClone.Group.Add(requirementGroupPayload); transaction.CreateOrUpdate(requirementsSpecificationClone); if (previousRequirementSpec != this.Thing) { // Update the requirements that were inside any of the groups that have been dropped var previousRequirementSpecRow = (RequirementsSpecificationRowViewModel)((RequirementsBrowserViewModel)this.ContainerViewModel) .ReqSpecificationRows.Single(x => x.Thing == previousRequirementSpec); var droppedRequirementGroups = requirementGroupPayload.ContainedGroup().ToList(); droppedRequirementGroups.Add(requirementGroupPayload); foreach (var keyValuePair in previousRequirementSpecRow.requirementContainerGroupCache) { if (!droppedRequirementGroups.Contains(keyValuePair.Value)) { continue; } var requirementClone = keyValuePair.Key.Clone(false); requirementClone.Group = null; transaction.CreateOrUpdate(requirementClone); } } await this.DalWrite(transaction); } else { // insert before first var model = (EngineeringModel)this.Thing.TopContainer; var orderPt = OrderHandlerService.GetOrderParameterType(model); if (orderPt == null) { return; } var orderService = new RequirementsGroupOrderHandlerService(this.Session, orderPt); var transaction = orderService.Insert(requirementGroupPayload, firstRow.Thing, InsertKind.InsertBefore); await this.Session.Write(transaction.FinalizeTransaction()); } }
public void Setup() { this.assembler = new Assembler(this.uri); RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.session = new Mock <ISession>(); 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.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString); this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri); this.modelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "model" }; this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri); this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "rs1", ShortName = "1" }; this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "test" }; this.reqSpec.Owner = this.domain; this.iteration.RequirementsSpecification.Add(this.reqSpec); this.iteration.IterationSetup = this.iterationSetup; this.model.EngineeringModelSetup = this.modelSetup; this.model.Iteration.Add(this.iteration); this.grp1 = new RequirementsGroup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.grp11 = new RequirementsGroup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.grp2 = new RequirementsGroup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.reqSpec.Group.Add(this.grp1); this.reqSpec.Group.Add(this.grp2); this.grp1.Group.Add(this.grp11); this.req = new Requirement(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "requirement1", ShortName = "r1", Owner = this.domain }; this.def = new Definition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Content = "def" }; this.reqSpec.Requirement.Add(this.req); this.req.Definition.Add(this.def); }
public void VerifyThatBreadCrumOfNonGroupedRequirementGroupCanBeComputed() { var requirementsGroup = new RequirementsGroup() { ShortName = "GRP1" }; this.requirementsSpecification.Group.Add(requirementsGroup); Assert.AreEqual("S:URD.RG:GRP1", requirementsGroup.BreadCrumb()); }
public void SetUp() { this.parametricConstraint = new ParametricConstraint(Guid.NewGuid(), null, null); this.relationalExpression = new RelationalExpressionBuilder() .WithSimpleQuantityKindParameterType() .WithValue("10") .Build(); this.parametricConstraint.Expression.Add(this.relationalExpression); this.requirement1 = new Requirement(Guid.NewGuid(), null, null); this.requirement1.ParametricConstraint.Add(this.parametricConstraint); this.requirementsSpecification = new RequirementsSpecification(Guid.NewGuid(), null, null); this.requirementsSpecification.Requirement.Add(this.requirement1); this.requirementsGroup1 = new RequirementsGroup(Guid.NewGuid(), null, null); this.requirementsGroup2 = new RequirementsGroup(Guid.NewGuid(), null, null); this.requirementsSpecification.Group.Add(this.requirementsGroup1); this.requirementsGroup1.Group.Add(this.requirementsGroup2); this.requirement1.Group = this.requirementsGroup1; this.requirementsContainerVerifier = new RequirementsContainerVerifier(this.requirementsSpecification); this.requirementsGroupVerifier1 = new RequirementsContainerVerifier(this.requirementsGroup1); this.requirementsGroupVerifier2 = new RequirementsContainerVerifier(this.requirementsGroup2); this.iteration = new Iteration(Guid.NewGuid(), null, null); this.elementDefinition = new ElementDefinition(Guid.NewGuid(), null, null); var elementUsage = new ElementUsage(Guid.NewGuid(), null, null) { ElementDefinition = this.elementDefinition }; this.elementDefinition.ContainedElement.Add(elementUsage); var parameter = new ParameterBuilder() .WithSimpleQuantityKindParameterType() .WithValue("10") .AddToElementDefinition(this.elementDefinition) .Build(); this.iteration.Element.Add(this.elementDefinition); this.RegisterBinaryRelationShip(parameter, this.relationalExpression); }
public void VerifyThatBreadCrumOfGroupedRequirementGroupCanBeComputed() { var requirementsGroupA = new RequirementsGroup() { ShortName = "GRPA" }; var requirementsGroupA_A = new RequirementsGroup() { ShortName = "GRPA_A" }; this.requirementsSpecification.Group.Add(requirementsGroupA); requirementsGroupA.Group.Add(requirementsGroupA_A); Assert.AreEqual("S:URD.RG:GRPA", requirementsGroupA.BreadCrumb()); Assert.AreEqual("S:URD.RG:GRPA.RG:GRPA_A", requirementsGroupA_A.BreadCrumb()); }
/// <summary> /// Compares 2 <see cref="RequirementsGroup"/> /// </summary> /// <param name="x">The first group</param> /// <param name="y">The second group</param> /// <returns> /// Less than zero : x is "lower" than y /// Zero: x "equals" y. /// Greater than zero: x is "greater" than y. /// </returns> private int CompareOrderValue(RequirementsGroup x, RequirementsGroup y) { if (RequirementsModule.PluginSettings?.OrderSettings != null && RequirementsModule.PluginSettings.OrderSettings.ParameterType != Guid.Empty) { var xOrder = x.ParameterValue.FirstOrDefault(z => z.ParameterType.Iid == RequirementsModule.PluginSettings.OrderSettings.ParameterType)?.Value.FirstOrDefault(); var yOrder = y.ParameterValue.FirstOrDefault(z => z.ParameterType.Iid == RequirementsModule.PluginSettings.OrderSettings.ParameterType)?.Value.FirstOrDefault(); int xOrderKey, yOrderKey; if (xOrder != null && int.TryParse(xOrder, out xOrderKey) && yOrder != null && int.TryParse(yOrder, out yOrderKey)) { return(xOrderKey > yOrderKey ? 1 : xOrderKey < yOrderKey ? -1 : shortNameThingComparer.Compare(x, y)); } } return(shortNameThingComparer.Compare(x, y)); }
public void VerifyThatBreadCrumbOfGroupRequirementCanBeComputed() { var requirement = new Requirement() { ShortName = "REQA" }; this.requirementsSpecification.Requirement.Add(requirement); var requirementsGroupA = new RequirementsGroup() { ShortName = "GRPA" }; this.requirementsSpecification.Group.Add(requirementsGroupA); requirement.Group = requirementsGroupA; Assert.AreEqual("S:URD.RG:GRPA.R:REQA", requirement.BreadCrumb()); }
/// <summary> /// Serialize the <see cref="RequirementsGroup"/> /// </summary> /// <param name="requirementsGroup">The <see cref="RequirementsGroup"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(RequirementsGroup requirementsGroup) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsGroup.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsGroup.Category.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsGroup.ClassKind))); jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsGroup.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsGroup.Group.OrderBy(x => x, this.guidComparer))); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsGroup.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsGroup.Iid)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsGroup.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsGroup.Name)); jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsGroup.Owner)); jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsGroup.ParameterValue.OrderBy(x => x, this.guidComparer))); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsGroup.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsGroup.ShortName)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsGroup.ThingPreference)); return(jsonObject); }
/// <summary> /// Returns the <see cref="SpecObject"/> representation of a <see cref="RequirementsGroup"/> /// </summary> /// <param name="requirementsGroup">The <see cref="RequirementsGroup"/></param> /// <param name="specObjectType">The associated <see cref="SpecObjectType"/></param> /// <returns>The associated <see cref="SpecObject"/></returns> public SpecObject ToReqIfSpecObject(RequirementsGroup requirementsGroup, SpecObjectType specObjectType) { if (requirementsGroup == null) { throw new ArgumentNullException("requirementsGroup"); } var specObject = new SpecObject(); this.SetIdentifiableProperties(specObject, requirementsGroup); specObject.Type = specObjectType; this.SetCommonAttributeValues(specObject, requirementsGroup); foreach (var parameterValue in requirementsGroup.ParameterValue) { var attributeDef = specObjectType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString()); var value = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale); specObject.Values.Add(value); } return(specObject); }
public void VerifyThatGetAllGroupsWorks() { var spec = new RequirementsSpecification(); var grp1 = new RequirementsGroup(); var grp11 = new RequirementsGroup(); var grp111 = new RequirementsGroup(); var grp12 = new RequirementsGroup(); var grp2 = new RequirementsGroup(); var grp21 = new RequirementsGroup(); var grp3 = new RequirementsGroup(); spec.Group.Add(grp1); spec.Group.Add(grp2); spec.Group.Add(grp3); grp1.Group.Add(grp11); grp1.Group.Add(grp12); grp11.Group.Add(grp111); grp2.Group.Add(grp21); var specAllGroups = spec.GetAllContainedGroups(); Assert.AreEqual(7, specAllGroups.Count()); var grp1AllGroup = grp1.GetAllContainedGroups(); Assert.AreEqual(3, grp1AllGroup.Count()); var grp2AllGroup = grp2.GetAllContainedGroups(); Assert.AreEqual(1, grp2AllGroup.Count()); }