public void VerifyThatPropertiesArePopulated() { var decomposition = new DecompositionRule { Name = "name", ShortName = "shortname", MinContained = 3, }; var vm = new DecompositionRuleDialogViewModel(decomposition, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogService.Object); Assert.AreEqual(decomposition.Name, vm.Name); Assert.AreEqual(decomposition.ShortName, vm.ShortName); Assert.AreEqual(decomposition.MinContained, vm.MinContained); Assert.IsNull(vm.MaxContained); Assert.AreEqual(1, vm.PossibleContainer.Count); vm.Container = vm.PossibleContainer.Single(); Assert.AreEqual(1, vm.PossibleContainedCategory.Count); Assert.AreEqual(1, vm.PossibleContainingCategory.Count); Assert.IsFalse(vm.OkCommand.CanExecute(null)); vm.SelectedContainingCategory = vm.PossibleContainingCategory.Single(); vm.ContainedCategory = new ReactiveList <Category>(vm.PossibleContainedCategory); vm.MaxContainedString = Int32.MaxValue.ToString() + "1"; Assert.AreEqual(vm.MaxContained, null); vm.MaxContainedString = "5"; Assert.AreEqual(vm.MaxContained, 5); Assert.IsTrue(vm.OkCommand.CanExecute(null)); }
public void VerifyThatIfNoDecompositionRuleIsViolatedNoViolationsAreReturned() { var rule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri); rule.ContainingCategory = this.systemCategory; rule.ContainedCategory.Add(this.functionCategory); rule.MinContained = 1; rule.MaxContained = 2; var satellite = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); satellite.Category.Add(this.systemCategory); this.iteration.Element.Add(satellite); var electricalStorage = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); electricalStorage.Category.Add(this.electricalPowerStorageCategory); this.iteration.Element.Add(electricalStorage); var elementUsage = new ElementUsage(Guid.NewGuid(), this.cache, this.uri); elementUsage.ElementDefinition = electricalStorage; satellite.ContainedElement.Add(elementUsage); var violations = rule.Verify(this.iteration); Assert.IsEmpty(violations); }
public void VerifyThatIfDecompositionIsSatisfiedButMaxContainedNotViolationIsReturned() { var rule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri); rule.ContainingCategory = this.systemCategory; rule.ContainedCategory.Add(this.productCategory); rule.MinContained = 1; rule.MaxContained = 2; var satelliteElementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { Name = "satellite", ShortName = "SAT" }; satelliteElementDefinition.Category.Add(this.systemCategory); this.iteration.Element.Add(satelliteElementDefinition); var batteryElementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { Name = "Battery", ShortName = "BAT" }; batteryElementDefinition.Category.Add(this.productCategory); this.iteration.Element.Add(batteryElementDefinition); var batteryUsage1 = new ElementUsage(Guid.NewGuid(), this.cache, this.uri) { Name = "battery 1", ShortName = "bat_1" }; batteryUsage1.ElementDefinition = batteryElementDefinition; satelliteElementDefinition.ContainedElement.Add(batteryUsage1); var batteryUsage2 = new ElementUsage(Guid.NewGuid(), this.cache, this.uri) { Name = "battery 2", ShortName = "bat_2" }; batteryUsage2.ElementDefinition = batteryElementDefinition; satelliteElementDefinition.ContainedElement.Add(batteryUsage2); var batteryUsage3 = new ElementUsage(Guid.NewGuid(), this.cache, this.uri) { Name = "battery 3", ShortName = "bat_3" }; batteryUsage3.ElementDefinition = batteryElementDefinition; satelliteElementDefinition.ContainedElement.Add(batteryUsage3); var violations = rule.Verify(this.iteration); Assert.AreEqual(1, violations.Count()); var violation = violations.Single(); Assert.IsTrue(violation.Description.Contains("contains more Element Usages than the maximum of 2")); }
public void Verify_that_IsRuleInChainOfRdls_returns_expected_result() { var decompositionRule = new DecompositionRule(); Assert.That(this.mRdl.IsRuleInChainOfRdls(decompositionRule), Is.False); this.sRdl1.Rule.Add(decompositionRule); Assert.That(this.mRdl.IsRuleInChainOfRdls(decompositionRule), Is.True); }
public void VerifyThatIfThereAreNoElementDefinitionsContainedByAnITerationAnEmptyResultIsReturned() { var rule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri); CollectionAssert.IsEmpty(this.iteration.Element); var violations = rule.Verify(this.iteration); CollectionAssert.IsEmpty(violations); }
public void VerifyThatIfTheIterationContainsNoBinaryRelationShipsAnEmptyResultIsReturned() { var rule = new DecompositionRule(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 SetUp() { this.decompositionRuleRuleChecker = new DecompositionRuleRuleChecker(); this.decompositionRule = new DecompositionRule { Iid = Guid.Parse("93db34a8-251d-40aa-bd68-1e38574f585a"), ShortName = "DECOMPRULE" }; this.siteReferenceDataLibrary = new SiteReferenceDataLibrary(); this.siteReferenceDataLibrary.Rule.Add(this.decompositionRule); }
public void Verify_that_when_Rule_is_in_chain_of_Rdls_no_result_is_returned() { var rule = new DecompositionRule { Iid = Guid.Parse("3c44c0e3-d2de-43f9-9636-8235984dc4bf"), ShortName = "RULE" }; this.modelReferenceDataLibrary.Rule.Add(rule); this.userRuleVerification.Rule = rule; var results = this.userRuleVerificationRuleChecker.CheckWhetherReferencedRuleIsInChainOfRlds(this.userRuleVerification); Assert.That(results, Is.Empty); }
public void Verify_that_when_referenced_DeprecatableThing_Is_not_Deprecated_no_result_is_returned() { var rule = new DecompositionRule { Iid = Guid.Parse("3c44c0e3-d2de-43f9-9636-8235984dc4bf"), ShortName = "RULE", IsDeprecated = false }; this.userRuleVerification.Rule = rule; var results = this.userRuleVerificationRuleChecker.ChecksWhetherAReferencedDeprecatableThingIsDeprecated(this.userRuleVerification); Assert.That(results, Is.Empty); }
public void VerifyThatIfRuleIsViolatedExpectedViolationsAreReturned() { var rule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri) { ContainingCategory = this.systemCategory }; rule.ContainedCategory.Add(this.functionCategory); rule.ContainedCategory.Add(this.productCategory); var spaceMissionElementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { Name = "Space Mission", ShortName = "SpaceMission" }; spaceMissionElementDefinition.Category.Add(this.systemCategory); var satelliteElementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { Name = "satellite", ShortName = "SAT" }; satelliteElementDefinition.Category.Add(this.systemCategory); var satelliteElementUsage = new ElementUsage(Guid.NewGuid(), this.cache, this.uri) { ElementDefinition = satelliteElementDefinition }; spaceMissionElementDefinition.ContainedElement.Add(satelliteElementUsage); this.iteration.Element.Add(spaceMissionElementDefinition); this.iteration.Element.Add(satelliteElementDefinition); var violations = rule.Verify(this.iteration); var violation = violations.SingleOrDefault(); Assert.IsNotNull(violation); Assert.IsTrue(violation.Description.Contains("of an incorrect type")); CollectionAssert.Contains(violation.ViolatingThing, spaceMissionElementDefinition.Iid); CollectionAssert.Contains(violation.ViolatingThing, satelliteElementUsage.Iid); }
public void Verify_that_when_Rule_is_not_in_chain_of_Rdls_result_is_returned() { var otherSiteReferenceDataLibrary = new SiteReferenceDataLibrary(); var rule = new DecompositionRule { Iid = Guid.Parse("3c44c0e3-d2de-43f9-9636-8235984dc4bf"), ShortName = "RULE" }; otherSiteReferenceDataLibrary.Rule.Add(rule); this.userRuleVerification.Rule = rule; var result = this.userRuleVerificationRuleChecker.CheckWhetherReferencedRuleIsInChainOfRlds(this.userRuleVerification).Single(); Assert.That(result.Id, Is.EqualTo("MA-0250")); Assert.That(result.Description, Is.EqualTo("The referenced Rule 3c44c0e3-d2de-43f9-9636-8235984dc4bf:RULE of UserRuleVerification.Rule is not in the chain of Reference Data Libraries")); Assert.That(result.Severity, Is.EqualTo(SeverityKind.Error)); Assert.That(result.Thing, Is.EqualTo(this.userRuleVerification)); }
public void Verify_that_when_referenced_DeprecatableThing_Is_Deprecated_result_is_returned() { var rule = new DecompositionRule { Iid = Guid.Parse("3c44c0e3-d2de-43f9-9636-8235984dc4bf"), ShortName = "RULE", IsDeprecated = true }; this.userRuleVerification.Rule = rule; var results = this.userRuleVerificationRuleChecker.ChecksWhetherAReferencedDeprecatableThingIsDeprecated(this.userRuleVerification); var first = results.First(); Assert.That(first.Id, Is.EqualTo("MA-0500")); Assert.That(first.Description, Is.EqualTo("The referenced Rule 3c44c0e3-d2de-43f9-9636-8235984dc4bf:RULE of UserRuleVerification.Rule is deprecated")); Assert.That(first.Thing, Is.EqualTo(this.userRuleVerification)); Assert.That(first.Severity, Is.EqualTo(SeverityKind.Warning)); }
/// <summary> /// Serialize the <see cref="DecompositionRule"/> /// </summary> /// <param name="decompositionRule">The <see cref="DecompositionRule"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(DecompositionRule decompositionRule) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](decompositionRule.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), decompositionRule.ClassKind))); jsonObject.Add("containedCategory", this.PropertySerializerMap["containedCategory"](decompositionRule.ContainedCategory.OrderBy(x => x, this.guidComparer))); jsonObject.Add("containingCategory", this.PropertySerializerMap["containingCategory"](decompositionRule.ContainingCategory)); jsonObject.Add("definition", this.PropertySerializerMap["definition"](decompositionRule.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](decompositionRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](decompositionRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](decompositionRule.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](decompositionRule.Iid)); jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](decompositionRule.IsDeprecated)); jsonObject.Add("maxContained", this.PropertySerializerMap["maxContained"](decompositionRule.MaxContained)); jsonObject.Add("minContained", this.PropertySerializerMap["minContained"](decompositionRule.MinContained)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](decompositionRule.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](decompositionRule.Name)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](decompositionRule.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](decompositionRule.ShortName)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](decompositionRule.ThingPreference)); return(jsonObject); }
public void SetUp() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); this.siteDirectory = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); this.systemDomainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri) { Name = "System", ShortName = "SYS" }; this.siteDirectory.Domain.Add(this.systemDomainOfExpertise); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.session = new Mock <ISession>(); this.permissionService = new Mock <IPermissionService>(); var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri); var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri) { Name = "testRDL", ShortName = "test" }; this.binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri) { Name = "binary", ShortName = "binary" }; srdl.Rule.Add(this.binaryRelationshipRule); var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri) { RequiredRdl = srdl }; mrdl.RequiredRdl = srdl; engineeringModelSetup.RequiredRdl.Add(mrdl); this.decompositionRule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri) { Name = "decomposition", ShortName = "decomposition" }; mrdl.Rule.Add(this.decompositionRule); this.engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); this.engineeringModel.EngineeringModelSetup = engineeringModelSetup; this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri); this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri); this.iteration.IterationSetup = this.iterationSetup; this.engineeringModel.Iteration.Add(iteration); this.ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri) { Owner = this.systemDomainOfExpertise }; iteration.RuleVerificationList.Add(this.ruleVerificationList); this.userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri) { Rule = this.binaryRelationshipRule }; this.ruleVerificationList.RuleVerification.Add(this.userRuleVerification); this.cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration)); var chainOfRdls = new List <ReferenceDataLibrary>(); chainOfRdls.Add(mrdl); chainOfRdls.Add(srdl); this.session.Setup(x => x.GetEngineeringModelRdlChain(It.IsAny <EngineeringModel>())).Returns(chainOfRdls); var transactionContext = TransactionContextResolver.ResolveContext(this.iteration); 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> /// Initializes a new instance of the <see cref="DecompositionRuleDialogViewModel"/> class. /// </summary> /// <param name="decompositionRule"> /// The <see cref="DecompositionRule"/> 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 DecompositionRuleDialogViewModel(DecompositionRule decompositionRule, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(decompositionRule, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { }
public void VerifyThatViolationAreAddedRemoved() { var decompositionRule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri) { Name = "decomposition" }; var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri) { Owner = this.domain }; this.iteration.RuleVerificationList.Add(ruleVerificationList); // add a rule verification var builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), this.cache, this.uri) { Name = "BuiltIn", Status = RuleVerificationStatusKind.INCONCLUSIVE, IsActive = true, }; var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri) { IsActive = true, Rule = decompositionRule }; ruleVerificationList.RuleVerification.Add(userRuleVerification); ruleVerificationList.RuleVerification.Add(builtInRuleVerification); var listRowViewModel = new RuleVerificationListRowViewModel(ruleVerificationList, this.session.Object, null); var violation = new RuleViolation(Guid.NewGuid(), this.cache, this.uri) { Description = "violation", }; var builtinRow = listRowViewModel.ContainedRows.Single(x => x.Thing.ClassKind == ClassKind.BuiltInRuleVerification); var userRow = listRowViewModel.ContainedRows.Single(x => x.Thing.ClassKind == ClassKind.UserRuleVerification); Assert.IsEmpty(builtinRow.ContainedRows); Assert.IsEmpty(userRow.ContainedRows); builtInRuleVerification.Violation.Add(violation); this.revision.SetValue(builtInRuleVerification, 10); CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated); Assert.IsNotEmpty(builtinRow.ContainedRows); builtInRuleVerification.Violation.Clear(); this.revision.SetValue(builtInRuleVerification, 20); CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated); Assert.IsEmpty(builtinRow.ContainedRows); userRuleVerification.Violation.Add(violation); this.revision.SetValue(userRuleVerification, 10); CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated); Assert.IsNotEmpty(userRow.ContainedRows); userRuleVerification.Violation.Clear(); this.revision.SetValue(userRuleVerification, 20); CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated); Assert.IsEmpty(userRow.ContainedRows); }
public void VerifyThatNullIterationThrowsArgumentException() { var rule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri); Assert.Throws <ArgumentNullException>(() => rule.Verify(null)); }
/// <summary> /// Persist the DTO composition to the ORM layer. /// </summary> /// <param name="transaction"> /// The transaction object. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="decompositionRule"> /// The decompositionRule instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool CreateContainment(NpgsqlTransaction transaction, string partition, DecompositionRule decompositionRule) { var results = new List <bool>(); foreach (var alias in this.ResolveFromRequestCache(decompositionRule.Alias)) { results.Add(this.AliasService.CreateConcept(transaction, partition, alias, decompositionRule)); } foreach (var definition in this.ResolveFromRequestCache(decompositionRule.Definition)) { results.Add(this.DefinitionService.CreateConcept(transaction, partition, definition, decompositionRule)); } foreach (var hyperLink in this.ResolveFromRequestCache(decompositionRule.HyperLink)) { results.Add(this.HyperLinkService.CreateConcept(transaction, partition, hyperLink, decompositionRule)); } return(results.All(x => x)); }