public void VerifyThatCategoriesFromExistingRdlsAreLoaded() { var siterefenceDataLibrary = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null); var rule1 = new BinaryRelationshipRule(Guid.NewGuid(), null, null); var rule2 = new MultiRelationshipRule(Guid.NewGuid(), null, null); siterefenceDataLibrary.Rule.Add(rule1); siterefenceDataLibrary.Rule.Add(rule2); this.siteDir.SiteReferenceDataLibrary.Add(siterefenceDataLibrary); var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), null, null); var modelReferenceDataLibrary = new ModelReferenceDataLibrary(Guid.NewGuid(), null, null); var rule3 = new BinaryRelationshipRule(Guid.NewGuid(), null, null); var rule4 = new MultiRelationshipRule(Guid.NewGuid(), null, null); modelReferenceDataLibrary.Rule.Add(rule3); modelReferenceDataLibrary.Rule.Add(rule4); engineeringModelSetup.RequiredRdl.Add(modelReferenceDataLibrary); this.siteDir.Model.Add(engineeringModelSetup); this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary) { modelReferenceDataLibrary }); var browser = new RulesBrowserViewModel(this.session.Object, this.siteDir, null, null, null, null); Assert.AreEqual(4, browser.Rules.Count); }
public void VerifyThatIfRuleIsNotInChainOfRdlOfRuleVerificationListDraggedDropEffectIsNone() { var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri) { Owner = this.domain }; this.iteration.RuleVerificationList.Add(ruleVerificationList); var listRowViewModel = new RuleVerificationListRowViewModel(ruleVerificationList, this.session.Object, null); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var siteRDL = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); siteRDL.Rule.Add(binaryRelationshipRule); this.sitedir.SiteReferenceDataLibrary.Add(siteRDL); var dropInfo = new Mock <IDropInfo>(); dropInfo.Setup(x => x.Payload).Returns(binaryRelationshipRule); dropInfo.SetupProperty(x => x.Effects); listRowViewModel.DragOver(dropInfo.Object); Assert.AreEqual(DragDropEffects.None, dropInfo.Object.Effects); }
public void VerifyThatThePropertiesAreUpdateWhenRuleIsUpdated() { var shortName = "simplerulehortname"; var name = "simple rule name"; var rule = new BinaryRelationshipRule(Guid.NewGuid(), null, this.uri) { ShortName = shortName, Name = name, }; var RuleRowViewModel = new RuleRowViewModel(rule, this.session.Object, null); var updatedShortName = "update simpleruleshortname"; var updatedName = "update simple rule name"; rule.ShortName = updatedShortName; rule.Name = updatedName; // workaround to modify a read-only field var type = rule.GetType(); type.GetProperty("RevisionNumber").SetValue(rule, 50); CDPMessageBus.Current.SendObjectChangeEvent(rule, EventKind.Updated); Assert.AreEqual(rule, RuleRowViewModel.Thing); Assert.AreEqual(updatedShortName, RuleRowViewModel.ShortName); Assert.AreEqual(updatedName, RuleRowViewModel.Name); Assert.AreEqual(string.Empty, RuleRowViewModel.ContainerRdl); Assert.AreEqual(ClassKind.BinaryRelationshipRule.ToString(), RuleRowViewModel.ClassKind); }
/// <summary> /// Resolve the properties of the current <see cref="StakeHolderValueMapSettings"/> from its <see cref="DTO.Thing"/> counter-part /// </summary> /// <param name="dtoThing">The source <see cref="DTO.Thing"/></param> internal override void ResolveProperties(DTO.Thing dtoThing) { if (dtoThing == null) { throw new ArgumentNullException("dtoThing"); } var dto = dtoThing as DTO.StakeHolderValueMapSettings; if (dto == null) { throw new InvalidOperationException(string.Format("The DTO type {0} does not match the type of the current StakeHolderValueMapSettings POCO.", dtoThing.GetType())); } this.ExcludedDomain.ResolveList(dto.ExcludedDomain, dto.IterationContainerId, this.Cache); this.ExcludedPerson.ResolveList(dto.ExcludedPerson, dto.IterationContainerId, this.Cache); this.GoalToValueGroupRelationship = (dto.GoalToValueGroupRelationship.HasValue) ? this.Cache.Get <BinaryRelationshipRule>(dto.GoalToValueGroupRelationship.Value, dto.IterationContainerId) : null; this.ModifiedOn = dto.ModifiedOn; this.RevisionNumber = dto.RevisionNumber; this.StakeholderValueToRequirementRelationship = (dto.StakeholderValueToRequirementRelationship.HasValue) ? this.Cache.Get <BinaryRelationshipRule>(dto.StakeholderValueToRequirementRelationship.Value, dto.IterationContainerId) : null; this.ThingPreference = dto.ThingPreference; this.ValueGroupToStakeholderValueRelationship = (dto.ValueGroupToStakeholderValueRelationship.HasValue) ? this.Cache.Get <BinaryRelationshipRule>(dto.ValueGroupToStakeholderValueRelationship.Value, dto.IterationContainerId) : null; this.ResolveExtraProperties(); }
public void VerifyThatUserRuleVerificationCanBeExecutedAndMessageBusMessagesAreReceived() { var messageReceivedCounter = 0; var service = new RuleVerificationService(new List <Lazy <IBuiltInRule, IBuiltInRuleMetaData> >()); var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri); this.iteration.RuleVerificationList.Add(ruleVerificationList); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri) { IsActive = true, Rule = binaryRelationshipRule }; ruleVerificationList.RuleVerification.Add(userRuleVerification); var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(userRuleVerification) .Subscribe( x => { messageReceivedCounter++; }); service.Execute(this.session.Object, ruleVerificationList); Assert.AreEqual(2, messageReceivedCounter); }
public void VerifyThatRdlShortnameIsUpdated() { var vm = new RulesBrowserViewModel(this.session.Object, this.siteDir, null, null, null, null); var sRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri); sRdl.Container = this.siteDir; var cat = new BinaryRelationshipRule(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "cat1", ShortName = "1", Container = sRdl }; var cat2 = new BinaryRelationshipRule(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "cat2", ShortName = "2", Container = sRdl }; CDPMessageBus.Current.SendObjectChangeEvent(cat, EventKind.Added); CDPMessageBus.Current.SendObjectChangeEvent(cat2, EventKind.Added); var rev = typeof(Thing).GetProperty("RevisionNumber"); rev.SetValue(sRdl, 3); sRdl.ShortName = "test"; CDPMessageBus.Current.SendObjectChangeEvent(sRdl, EventKind.Updated); Assert.IsTrue(vm.Rules.Count(x => x.ContainerRdl == "test") == 2); }
public async Task VerifyThatUserRuleVerificationCanBeExecutedAndMessageBusMessagesAreReceived() { var messageReceivedCounter = 0; var service = new RuleVerificationService(new List <Lazy <IBuiltInRule, IBuiltInRuleMetaData> >()); var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri); this.iteration.RuleVerificationList.Add(ruleVerificationList); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri) { IsActive = true, Rule = binaryRelationshipRule }; this.session.Setup(s => s.Write(It.IsAny <OperationContainer>())) .Callback(() => { CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated); }); ruleVerificationList.RuleVerification.Add(userRuleVerification); var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(userRuleVerification) .Subscribe( x => { messageReceivedCounter++; }); await service.Execute(this.session.Object, ruleVerificationList); Assert.AreEqual(3, messageReceivedCounter); }
public void VerifyThatConvertProvidesTheExpectedString() { const string Binrelstring = "Binary Relationship Rule"; var brr = new BinaryRelationshipRule(); var converterResult = this.converter.Convert(brr.ClassKind, null, null, null); Assert.AreEqual(Binrelstring, converterResult); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryRelationshipRuleDialogViewModel"/> class. /// </summary> /// <param name="binaryRelationshipRule"> /// The <see cref="BinaryRelationshipRule"/> that is the subject of the current view-model. This is the object /// that will be either created, or edited. /// </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="MultiRelationshipRuleDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="MultiRelationshipRuleDialogViewModel"/> performs /// </param> /// <param name="thingDialogNavigationService">The <see cref="IThingDialogNavigationService"/></param> /// <param name="container">The Container <see cref="Thing"/> of the created <see cref="Thing"/></param> /// <param name="chainOfContainers"> /// The optional chain of containers that contains the <paramref name="container"/> argument /// </param> public BinaryRelationshipRuleDialogViewModel(BinaryRelationshipRule binaryRelationshipRule, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(binaryRelationshipRule, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { this.WhenAnyValue(vm => vm.Container).Subscribe(_ => { this.RepopulatePossibleCategories(); this.UpdateOkCanExecute(); }); this.WhenAnyValue(vm => vm.SelectedRelationshipCategory).Subscribe(_ => this.UpdateOkCanExecute()); this.WhenAnyValue(vm => vm.SelectedSourceCategory).Subscribe(_ => this.UpdateOkCanExecute()); this.WhenAnyValue(vm => vm.SelectedTargetCategory).Subscribe(_ => this.UpdateOkCanExecute()); }
public async Task VerifyThatArgumentNullExceptionsAreThrowForCreateBuiltInRuleVerificationWhenRuleNull() { var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, null); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, null); Assert.ThrowsAsync <ArgumentNullException>(async() => await this.thingCreator.CreateBuiltInRuleVerification(null, null, null)); Assert.ThrowsAsync <ArgumentException>(async() => await this.thingCreator.CreateBuiltInRuleVerification(ruleVerificationList, null, null)); Assert.ThrowsAsync <ArgumentNullException>(async() => await this.thingCreator.CreateBuiltInRuleVerification(ruleVerificationList, "test", null)); }
public void VerifyThatArgumentNullExceptionsAreThrowForCreateUserRuleVerification() { var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, null); var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, null); Assert.ThrowsAsync <ArgumentNullException>(async() => await this.thingCreator.CreateUserRuleVerification(null, null, null)); Assert.ThrowsAsync <ArgumentNullException>(async() => await this.thingCreator.CreateUserRuleVerification(ruleVerificationList, null, null)); Assert.ThrowsAsync <ArgumentNullException>(async() => await this.thingCreator.CreateUserRuleVerification(ruleVerificationList, binaryRelationshipRule, null)); }
public void SetUp() { this.binaryRelationshipRuleRuleChecker = new BinaryRelationshipRuleRuleChecker(); this.modelReferenceDataLibrary = new ModelReferenceDataLibrary(); this.binaryRelationshipRule = new BinaryRelationshipRule { Iid = Guid.Parse("426f4e96-dcfd-4589-bce0-856bea40495b"), ShortName = "BINRULE" }; this.modelReferenceDataLibrary.Rule.Add(this.binaryRelationshipRule); }
public void VerifyThatExistingMapIsApplied() { var category = new Category(Guid.NewGuid(), this.assembler.Cache, this.uri); var rule = new ParameterizedCategoryRule(Guid.NewGuid(), this.assembler.Cache, this.uri) { Category = category }; var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.assembler.Cache, this.uri) { RelationshipCategory = category, TargetCategory = category, SourceCategory = category }; var categoryVm = new CategoryComboBoxItemViewModel(category, true); Dictionary <RelationGroupType, RelationGroupTypeMap> RelationGroupTypeMaps = null; var datatypeDefinitionMaps = new Dictionary <DatatypeDefinition, DatatypeDefinitionMap> { { this.stringDatadef, new DatatypeDefinitionMap(this.stringDatadef, this.pt, null) } }; var newDialog = new RelationGroupTypeMappingDialogViewModel(new List <RelationGroupType> { this.spectype }, RelationGroupTypeMaps, datatypeDefinitionMaps, this.iteration, this.session.Object, this.thingDialogNavigationService.Object, "en"); Assert.IsEmpty(newDialog.SpecTypes.SelectMany(x => x.SelectedCategories)); Assert.IsNull(newDialog.SpecTypes[0].SelectedRules); Assert.IsNull(newDialog.SpecTypes[0].SelectedBinaryRelationshipRules); var row = newDialog.SpecTypes.First(); row.PossibleBinaryRelationshipRules.Add(binaryRelationshipRule); row.PossibleCategories.Add(categoryVm); row.PossibleRules.Add(rule); RelationGroupTypeMaps = new Dictionary <RelationGroupType, RelationGroupTypeMap>() { { this.spectype, new RelationGroupTypeMap( this.spectype, new[] { rule }, new[] { category }, new List <AttributeDefinitionMap>() { new AttributeDefinitionMap(this.attribute, AttributeDefinitionMapKind.SHORTNAME) }, new[] { binaryRelationshipRule }) } }; newDialog.PopulateRelationGroupTypeMapProperties(RelationGroupTypeMaps); Assert.IsNotEmpty(newDialog.SpecTypes.SelectMany(x => x.SelectedCategories)); Assert.IsNotEmpty(newDialog.SpecTypes.SelectMany(x => x.SelectedRules)); Assert.IsNotEmpty(newDialog.SpecTypes.SelectMany(x => x.SelectedBinaryRelationshipRules)); }
public void VerifyThatIfRelationshipRuleDoesNotHaveRelationshipCategorySetThatNoViolationsAreReturned() { var rule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var binaryRelationShip = new BinaryRelationship(Guid.NewGuid(), this.cache, this.uri); this.iteration.Relationship.Add(binaryRelationShip); var violations = rule.Verify(this.iteration); CollectionAssert.IsEmpty(violations); }
public void VerifyThatIfRuleIsViolatedViolationsAreReturned() { var relationshipCategory = new Category(Guid.NewGuid(), this.cache, this.uri) { ShortName = "link", Name = "a link" }; var sourceAndTargetCategory = new Category(Guid.NewGuid(), this.cache, this.uri); sourceAndTargetCategory.ShortName = "SOURCEANDTARGET"; var lazySourceAndTargetCategory = new Lazy <Thing>(() => sourceAndTargetCategory); this.cache.TryAdd(new CDP4Common.Types.CacheKey(sourceAndTargetCategory.Iid, null), lazySourceAndTargetCategory); var rule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri) { ShortName = "BinRule", Name = "Binary Relationship Rule", RelationshipCategory = relationshipCategory }; rule.SourceCategory = sourceAndTargetCategory; rule.TargetCategory = sourceAndTargetCategory; var elementDefinitionBattery1 = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); var elementDefinitionBattery2 = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); var binaryRelationship = new BinaryRelationship(Guid.NewGuid(), this.cache, this.uri) { Source = elementDefinitionBattery1, Target = elementDefinitionBattery2 }; binaryRelationship.Category.Add(relationshipCategory); this.iteration.Relationship.Add(binaryRelationship); var violations = rule.Verify(this.iteration); Assert.IsNotEmpty(violations); var sourceViolation = violations.Single(x => x.ViolatingThing.Contains(binaryRelationship.Iid) && x.Description.Contains("The Source")); Assert.IsNotNull(sourceViolation); Assert.IsTrue(sourceViolation.ViolatingThing.Contains(elementDefinitionBattery1.Iid)); Console.WriteLine(sourceViolation.Description); var targetViolation = violations.Single(x => x.ViolatingThing.Contains(binaryRelationship.Iid) && x.Description.Contains("The Target")); Assert.IsNotNull(targetViolation); Assert.IsTrue(targetViolation.ViolatingThing.Contains(elementDefinitionBattery2.Iid)); Console.WriteLine(targetViolation.Description); }
public void VerifyThatIfTheIterationContainsNoBinaryRelationShipsAnEmptyResultIsReturned() { var rule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var multiRelationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri); this.iteration.Relationship.Add(multiRelationship); var violations = rule.Verify(this.iteration); CollectionAssert.IsEmpty(violations); }
public void VerifyThatCreateUserRuleVerificationExecutesWriteSessionThrowsException() { var engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, null); var iteration = new Iteration(Guid.NewGuid(), this.cache, null); engineeringModel.Iteration.Add(iteration); var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, null); iteration.RuleVerificationList.Add(ruleVerificationList); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, null); Assert.ThrowsAsync <Exception>(async() => await this.thingCreator.CreateUserRuleVerification(ruleVerificationList, binaryRelationshipRule, this.sessionThatThrowsException.Object)); }
public void Verify_that_QueryRulesFromChainOfRdls_returns_expected_result() { var mRdl_Rule = new BinaryRelationshipRule(Guid.NewGuid(), null, null); var sRdl1_Rule = new BinaryRelationshipRule(Guid.NewGuid(), null, null); var sRdl11_Rule = new BinaryRelationshipRule(Guid.NewGuid(), null, null); this.mRdl.Rule.Add(mRdl_Rule); this.sRdl1.Rule.Add(sRdl1_Rule); this.sRdl11.Rule.Add(sRdl11_Rule); Assert.That(new List <Rule> { mRdl_Rule, sRdl1_Rule, sRdl11_Rule }, Is.EquivalentTo(this.mRdl.QueryRulesFromChainOfRdls())); }
public void VerifyThatTheConstructorSetsTheProperties() { var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri); var binrule = new BinaryRelationshipRule(Guid.NewGuid(), null, this.uri) { Name = "simple rule name", ShortName = "simplerulehortname" }; var RuleRowViewModel = new RuleRowViewModel(binrule, this.session.Object, null); Assert.AreEqual(binrule.ShortName, RuleRowViewModel.ShortName); Assert.AreEqual(binrule.Name, RuleRowViewModel.Name); Assert.AreEqual(string.Empty, RuleRowViewModel.ContainerRdl); }
public void Setup() { this.sitedir = new SiteDirectory(); this.srdl = new SiteReferenceDataLibrary(); sitedir.SiteReferenceDataLibrary.Add(srdl); this.cat1 = new Category(); this.cat2 = new Category(); this.rule1 = new BinaryRelationshipRule { RelationshipCategory = cat1 }; this.rule2 = new BinaryRelationshipRule { RelationshipCategory = cat2 }; srdl.DefinedCategory.Add(cat1); srdl.DefinedCategory.Add(cat2); srdl.Rule.Add(rule1); srdl.Rule.Add(rule2); this.modelSetup = new EngineeringModelSetup(); this.mrdl = new ModelReferenceDataLibrary { RequiredRdl = srdl }; modelSetup.RequiredRdl.Add(mrdl); this.cat3 = new Category(); this.rule3 = new BinaryRelationshipRule { RelationshipCategory = cat3 }; this.rule11 = new BinaryRelationshipRule { RelationshipCategory = cat1 }; mrdl.DefinedCategory.Add(cat3); mrdl.Rule.Add(rule3); mrdl.Rule.Add(rule11); this.iterationSetup = new IterationSetup(); modelSetup.IterationSetup.Add(iterationSetup); this.model = new EngineeringModel { EngineeringModelSetup = modelSetup }; this.iteration = new Iteration { IterationSetup = iterationSetup }; model.Iteration.Add(iteration); }
public async Task VerifyThatCreateUserRuleVerificationExecutesWrite() { var engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, null); var iteration = new Iteration(Guid.NewGuid(), this.cache, null); engineeringModel.Iteration.Add(iteration); var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, null); iteration.RuleVerificationList.Add(ruleVerificationList); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, null); await this.thingCreator.CreateUserRuleVerification(ruleVerificationList, binaryRelationshipRule, this.session.Object); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>())); }
public void VerifyThatBinaryRelationshipIsAddedAndRemovedWhenItIsSentAsAObjectChangeMethod() { Assert.AreEqual(0, this.RulesViewModel.Rules.Count); var binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "simple rule name", ShortName = "simpleruleshortname" }; CDPMessageBus.Current.SendObjectChangeEvent(binaryRelationshipRule, EventKind.Added); Assert.AreEqual(1, this.RulesViewModel.Rules.Count); Assert.IsTrue(this.RulesViewModel.Rules.Any(x => x.Thing == binaryRelationshipRule)); CDPMessageBus.Current.SendObjectChangeEvent(binaryRelationshipRule, EventKind.Removed); Assert.IsFalse(this.RulesViewModel.Rules.Any(x => x.Thing == binaryRelationshipRule)); }
/// <summary> /// Execute the <see cref="ICommand"/> to create a <see cref="Category"/> /// </summary> private void ExecuteCreateBinaryRelationshipRuleCommand() { var rule = new BinaryRelationshipRule(); var siteDirectory = this.Session.RetrieveSiteDirectory(); var transactionContext = TransactionContextResolver.ResolveContext(siteDirectory); var thingTransaction = new ThingTransaction(transactionContext); var res = this.ThingDialogNavigationService.Navigate(rule, thingTransaction, this.Session, true, ThingDialogKind.Create, this.ThingDialogNavigationService); // refresh parameter type list and set the mapping to the new parameter type if (res != null && res.Value) { foreach (var binaryRelationshipRuleMappingRowViewModel in this.SpecTypes) { binaryRelationshipRuleMappingRowViewModel.PopulatePossibleRules(); } } }
public void VerifyThatIfSourceOrTargetIsNotCategorizableViolationIsCreated() { var relationshipCategory = new Category(Guid.NewGuid(), this.cache, this.uri) { ShortName = "link", Name = "a link" }; var rule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri) { ShortName = "BinRule", Name = "Binary Relationship Rule", RelationshipCategory = relationshipCategory }; var sourceAlias = new Alias(Guid.NewGuid(), this.cache, this.uri); var targetAlias = new Alias(Guid.NewGuid(), this.cache, this.uri); var binaryRelationship = new BinaryRelationship(Guid.NewGuid(), this.cache, this.uri) { Source = sourceAlias, Target = targetAlias }; binaryRelationship.Category.Add(relationshipCategory); this.iteration.Relationship.Add(binaryRelationship); var violations = rule.Verify(this.iteration); CollectionAssert.IsNotEmpty(violations); var sourceViolation = violations.Single(x => x.ViolatingThing.Contains(binaryRelationship.Iid) && x.Description.Contains("The Source")); Assert.IsNotNull(sourceViolation); Console.WriteLine(sourceViolation.Description); var targetViolation = violations.Single(x => x.ViolatingThing.Contains(binaryRelationship.Iid) && x.Description.Contains("The Target")); Assert.IsNotNull(targetViolation); Console.WriteLine(targetViolation.Description); }
/// <summary> /// Refresh the content of the cells /// </summary> public void RefreshMatrix(BinaryRelationshipRule relationshipRule) { var updatedRelationships = this.QueryBinaryRelationshipInContext(relationshipRule).ToList(); var displayedRelationships = this.currentCells.Values.SelectMany(x => x.Relationships).ToList(); var oldRelationships = displayedRelationships.Except(updatedRelationships); var newRelationships = updatedRelationships.Except(displayedRelationships); foreach (var relationship in oldRelationships.Union(newRelationships)) { var definedSource = relationship.Source as DefinedThing; var definedTarget = relationship.Target as DefinedThing; if (definedSource == null || definedTarget == null) { continue; } var sourceRow = this.QueryRow(relationship.Source.Iid); var targetRow = this.QueryRow(relationship.Target.Iid); if (sourceRow != null) { var cellValue = this.ComputeCell(definedSource, definedTarget, updatedRelationships, relationshipRule); sourceRow[definedTarget.ShortName] = cellValue; this.UpdateCurrentCell(definedSource, definedTarget, cellValue); } if (targetRow != null) { var cellValue = this.ComputeCell(definedTarget, definedSource, updatedRelationships, relationshipRule); targetRow[definedSource.ShortName] = cellValue; this.UpdateCurrentCell(definedTarget, definedSource, cellValue); } } }
public void VerifyThatSubscriptionsWork() { var viewmodel = new RelationshipEditorViewModel(this.iteration, this.participant, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); Assert.AreEqual(0, viewmodel.RelationshipRules.Count); var newBinaryRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var newMultiRule = new MultiRelationshipRule(Guid.NewGuid(), this.cache, this.uri); CDPMessageBus.Current.SendObjectChangeEvent(newBinaryRule, EventKind.Added); Assert.AreEqual(1, viewmodel.RelationshipRules.Count); CDPMessageBus.Current.SendObjectChangeEvent(newMultiRule, EventKind.Added); Assert.AreEqual(2, viewmodel.RelationshipRules.Count); CDPMessageBus.Current.SendObjectChangeEvent(newBinaryRule, EventKind.Removed); Assert.AreEqual(1, viewmodel.RelationshipRules.Count); CDPMessageBus.Current.SendObjectChangeEvent(newMultiRule, EventKind.Removed); Assert.AreEqual(0, viewmodel.RelationshipRules.Count); }
public void VerifyThatWhenContainerRdlIsSetPropertiesAreSet() { var rdlshortnamename = "rdl shortname"; var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri) { ShortName = rdlshortnamename, }; var rule = new BinaryRelationshipRule(Guid.NewGuid(), null, this.uri) { Name = "simple rule name", ShortName = "simpleruleshortname" }; rdl.Rule.Add(rule); var RuleRowViewModel = new RuleRowViewModel(rule, this.session.Object, null); Assert.AreEqual(rule.ShortName, RuleRowViewModel.ShortName); Assert.AreEqual(rule.Name, RuleRowViewModel.Name); Assert.AreEqual(rdlshortnamename, RuleRowViewModel.ContainerRdl); }
public void VerifyThatWhenARuleIsDroppedARuleVerificationIsCreated() { var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri) { Owner = this.domain }; this.iteration.RuleVerificationList.Add(ruleVerificationList); var listRowViewModel = new RuleVerificationListRowViewModel(ruleVerificationList, this.session.Object, null); listRowViewModel.ThingCreator = this.thingCreator.Object; var payload = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); var dropInfo = new Mock <IDropInfo>(); dropInfo.Setup(x => x.Payload).Returns(payload); dropInfo.SetupProperty(x => x.Effects); listRowViewModel.Drop(dropInfo.Object); this.thingCreator.Verify(x => x.CreateUserRuleVerification(ruleVerificationList, payload, this.session.Object)); }
public void VerifyThatGetRequiredRdlsReturnsExpectedResults() { var srdl1 = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); var srdl1_1 = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); var mrdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); var srdl2 = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); var rule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri); srdl1_1.RequiredRdl = srdl1; mrdl.RequiredRdl = srdl1_1; srdl2.RequiredRdl = srdl1; mrdl.Rule.Add(rule); var requiredRdls = rule.RequiredRdls.ToList(); Assert.IsTrue(requiredRdls.Contains(mrdl)); Assert.IsTrue(requiredRdls.Contains(srdl1_1)); Assert.IsTrue(requiredRdls.Contains(srdl1)); Assert.IsFalse(requiredRdls.Contains(srdl2)); }
/// <summary> /// Serialize the <see cref="BinaryRelationshipRule"/> /// </summary> /// <param name="binaryRelationshipRule">The <see cref="BinaryRelationshipRule"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(BinaryRelationshipRule binaryRelationshipRule) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](binaryRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationshipRule.ClassKind))); jsonObject.Add("definition", this.PropertySerializerMap["definition"](binaryRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("forwardRelationshipName", this.PropertySerializerMap["forwardRelationshipName"](binaryRelationshipRule.ForwardRelationshipName)); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](binaryRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationshipRule.Iid)); jsonObject.Add("inverseRelationshipName", this.PropertySerializerMap["inverseRelationshipName"](binaryRelationshipRule.InverseRelationshipName)); jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](binaryRelationshipRule.IsDeprecated)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationshipRule.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationshipRule.Name)); jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](binaryRelationshipRule.RelationshipCategory)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationshipRule.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryRelationshipRule.ShortName)); jsonObject.Add("sourceCategory", this.PropertySerializerMap["sourceCategory"](binaryRelationshipRule.SourceCategory)); jsonObject.Add("targetCategory", this.PropertySerializerMap["targetCategory"](binaryRelationshipRule.TargetCategory)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationshipRule.ThingPreference)); return(jsonObject); }