Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void VerifyThatIfRuleVerificationListIsSelecedTheRulesCanBeVerified()
        {
            this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, null) }
            });


            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var vm = new RuleVerificationListBrowserViewModel(this.iteration, this.participant, this.session.Object, null, null, null, null);

            vm.SelectedThing = vm.RuleVerificationListRowViewModels.FirstOrDefault();
            vm.ComputePermission();

            Assert.IsTrue(vm.VerifyRuleVerificationList.CanExecute(null));
            vm.VerifyRuleVerificationList.Execute(null);

            this.ruleVerificationService.Verify(x => x.Execute(this.session.Object, ruleVerificationList));
        }
Esempio n. 3
0
        public void VerifyThatWhenAIBuiltInRuleMetaDataIsDroppedARuleVerificationIsCreated()
        {
            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 metaData = new Mock <IBuiltInRuleMetaData>();

            metaData.Setup(x => x.Name).Returns("test");

            var dropInfo = new Mock <IDropInfo>();

            dropInfo.Setup(x => x.Payload).Returns(metaData.Object);
            dropInfo.SetupProperty(x => x.Effects);

            listRowViewModel.Drop(dropInfo.Object);

            this.thingCreator.Verify(x => x.CreateBuiltInRuleVerification(ruleVerificationList, "test", this.session.Object));
        }
        /// <summary>
        /// Execute the verification of the provided <see cref="RuleVerificationList"/>
        /// </summary>
        /// <param name="session">
        /// The <see cref="ISession"/> instance used to update the contained <see cref="RuleVerification"/> instances on the data-source.
        /// </param>
        /// <param name="verificationList">
        /// The <see cref="RuleVerificationList"/> that needs to be verified.
        /// </param>
        /// <returns>An awaitable <see cref="Task"/></returns>
        public async Task Execute(ISession session, RuleVerificationList verificationList)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session", "The session may not be null");
            }

            if (verificationList == null)
            {
                throw new ArgumentNullException("verificationList", "The verificationList may not be null");
            }

            foreach (var ruleVerification in verificationList.RuleVerification)
            {
                var builtInRuleVerification = ruleVerification as BuiltInRuleVerification;
                if (builtInRuleVerification != null && builtInRuleVerification.IsActive)
                {
                    this.Execute(session, builtInRuleVerification, verificationList);
                }

                var userRuleVerification = ruleVerification as UserRuleVerification;
                if (userRuleVerification != null && userRuleVerification.IsActive)
                {
                    await this.Execute(session, userRuleVerification, verificationList);
                }
            }
        }
Esempio n. 5
0
        public void VerifyThatArgumentNotNullExceptionIsThrownWhenSessionIsNull()
        {
            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri);
            var service = new RuleVerificationService(this.builtInRules);

            Assert.Throws <ArgumentNullException>(() => service.Execute(null, ruleVerificationList));
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        public void VerifyThatBuiltInRulesCanBeExecutedAndMessageBusMessagesAreReceived()
        {
            var messageReceivedCounter = 0;

            var service = new RuleVerificationService(this.builtInRules);

            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri);

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                Name     = this.builtInRuleName,
                IsActive = true
            };

            ruleVerificationList.RuleVerification.Add(builtInRuleVerification);

            var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(builtInRuleVerification)
                           .Subscribe(
                x => { messageReceivedCounter++; });

            service.Execute(this.session.Object, ruleVerificationList);

            Assert.IsTrue(builtInRuleVerification.Violation.Any());

            Assert.AreEqual(2, messageReceivedCounter);
        }
        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);
        }
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
        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 TestGetOwner()
        {
            var thing = new UserRuleVerification();
            var list  = new RuleVerificationList();

            list.Owner = new DomainOfExpertise();
            list.RuleVerification.Add(thing);

            Assert.IsTrue(ReferenceEquals(list.Owner, thing.Owner));
        }
Esempio n. 12
0
        public void VerifyThatCreateBuiltInRuleVerificationExecutesWriteSessionException()
        {
            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);

            Assert.ThrowsAsync <Exception>(async() => await this.thingCreator.CreateBuiltInRuleVerification(ruleVerificationList, "testrule", this.sessionThatThrowsException.Object));
        }
Esempio n. 13
0
        public void VerifyThatBrowserIsNotEmptyOnInitialLoad()
        {
            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var viewmodel = new RuleVerificationListBrowserViewModel(this.iteration, this.participant, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null);

            CollectionAssert.IsNotEmpty(viewmodel.RuleVerificationListRowViewModels);
        }
Esempio n. 14
0
        public async Task VerifyThatCreateBuiltInRuleVerificationExecutesWrite()
        {
            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);

            await this.thingCreator.CreateBuiltInRuleVerification(ruleVerificationList, "testrule", this.session.Object);

            this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()));
        }
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.assembler = new Assembler(this.uri);
            this.cache     = this.assembler.Cache;

            this.serviceLocator = new Mock <IServiceLocator>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);

            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();

            this.SetupIRuleVerificationService();

            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);

            var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);

            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.engineeringModel.Iteration.Add(this.iteration);

            this.ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.systemDomainOfExpertise
            };

            this.builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), this.cache, this.uri);
            this.ruleVerificationList.RuleVerification.Add(this.builtInRuleVerification);

            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());
        }
        public void SetUp()
        {
            this.userRuleVerificationRuleChecker = new UserRuleVerificationRuleChecker();

            this.modelReferenceDataLibrary = new ModelReferenceDataLibrary();
            this.engineeringModelSetup     = new EngineeringModelSetup();
            this.engineeringModel          = new EngineeringModel();
            this.iteration            = new Iteration();
            this.ruleVerificationList = new RuleVerificationList();
            this.userRuleVerification = new UserRuleVerification();

            this.engineeringModelSetup.RequiredRdl.Add(this.modelReferenceDataLibrary);
            this.engineeringModel.EngineeringModelSetup = this.engineeringModelSetup;
            this.engineeringModel.Iteration.Add(this.iteration);
            this.iteration.RuleVerificationList.Add(this.ruleVerificationList);
            this.ruleVerificationList.RuleVerification.Add(this.userRuleVerification);
        }
Esempio n. 17
0
        /// <summary>
        /// Create a new <see cref="UserRuleVerification"/>
        /// </summary>
        /// <param name="ruleVerificationList">
        /// The container <see cref="RuleVerificationList"/> of the <see cref="UserRuleVerification"/> that is to be created.
        /// </param>
        /// <param name="rule">
        /// The <see cref="Rule"/> that the new <see cref="UserRuleVerification"/> references.
        /// </param>
        /// <param name="session">
        /// The <see cref="ISession"/> in which the new <see cref="UserRuleVerification"/> is to be added
        /// </param>
        public async Task CreateUserRuleVerification(RuleVerificationList ruleVerificationList, Rule rule, ISession session)
        {
            if (ruleVerificationList == null)
            {
                throw new ArgumentNullException("ruleVerificationList", "The ruleVerificationList must not be null");
            }

            if (rule == null)
            {
                throw new ArgumentNullException("rule", "The rule must not be null");
            }

            if (session == null)
            {
                throw new ArgumentNullException("session", "The session may not be null");
            }

            var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), null, null)
            {
                Rule     = rule,
                IsActive = false,
                Status   = RuleVerificationStatusKind.NONE
            };

            var clone = ruleVerificationList.Clone(false);

            clone.RuleVerification.Add(userRuleVerification);

            var transactionContext = TransactionContextResolver.ResolveContext(ruleVerificationList);
            var transaction        = new ThingTransaction(transactionContext, clone);

            transaction.Create(userRuleVerification);

            try
            {
                var operationContainer = transaction.FinalizeTransaction();
                await session.Write(operationContainer);
            }
            catch (Exception ex)
            {
                logger.Error("The UserRuleVerification could not be created", ex);
                throw ex;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Create a new <see cref="BuiltInRuleVerification"/>
        /// </summary>
        /// <param name="ruleVerificationList">
        /// The container <see cref="RuleVerificationList"/> of the <see cref="BuiltInRuleVerification"/> that is to be created.
        /// </param>
        /// <param name="name">
        /// The name for the <see cref="BuiltInRuleVerification"/>
        /// </param>
        /// <param name="session">
        /// The <see cref="ISession"/> in which the new <see cref="UserRuleVerification"/> is to be added
        /// </param>
        public async Task CreateBuiltInRuleVerification(RuleVerificationList ruleVerificationList, string name, ISession session)
        {
            if (ruleVerificationList == null)
            {
                throw new ArgumentNullException(nameof(ruleVerificationList), "The ruleVerificationList must not be null");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("The name may not be null or empty");
            }

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session), "The session may not be null");
            }

            var builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), null, null)
            {
                Name     = name,
                IsActive = false,
                Status   = RuleVerificationStatusKind.NONE
            };

            var clone = ruleVerificationList.Clone(false);

            clone.RuleVerification.Add(builtInRuleVerification);

            var transactionContext = TransactionContextResolver.ResolveContext(ruleVerificationList);
            var transaction        = new ThingTransaction(transactionContext, clone);

            transaction.Create(builtInRuleVerification);

            try
            {
                var operationContainer = transaction.FinalizeTransaction();
                await session.Write(operationContainer);
            }
            catch (Exception ex)
            {
                logger.Error("The BuiltInRuleVerification could not be created", ex);
                throw ex;
            }
        }
        public void VerifyThatIfRuleVerificationListIsSelecedTheRulesCanBeVerified()
        {
            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var vm = new RuleVerificationListBrowserViewModel(this.iteration, this.participant, this.session.Object, null, null, null, null);

            vm.SelectedThing = vm.RuleVerificationListRowViewModels.FirstOrDefault();
            vm.ComputePermission();

            Assert.IsTrue(vm.VerifyRuleVerificationList.CanExecute(null));
            vm.VerifyRuleVerificationList.Execute(null);

            this.ruleVerificationService.Verify(x => x.Execute(this.session.Object, ruleVerificationList));
        }
Esempio n. 20
0
        public void VerifyThatIfNothingIsSelectedThenVerifyCanNotBeExecuted()
        {
            this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, null) }
            });

            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);

            var vm = new RuleVerificationListBrowserViewModel(this.iteration, this.participant, this.session.Object, null, null, null, null);

            vm.SelectedThing = null;
            Assert.IsFalse(vm.VerifyRuleVerificationList.CanExecute(null));
        }
Esempio n. 21
0
        public void VerifytThatWhenNotARuleIsDraggedDropEffectIsNone()
        {
            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 payload  = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);
            var dropInfo = new Mock <IDropInfo>();

            dropInfo.Setup(x => x.Payload).Returns(payload);
            dropInfo.SetupProperty(x => x.Effects);

            listRowViewModel.DragOver(dropInfo.Object);

            Assert.AreEqual(DragDropEffects.None, dropInfo.Object.Effects);
        }
Esempio n. 22
0
        /// <summary>
        /// Serialize the <see cref="RuleVerificationList"/>
        /// </summary>
        /// <param name="ruleVerificationList">The <see cref="RuleVerificationList"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(RuleVerificationList ruleVerificationList)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](ruleVerificationList.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleVerificationList.ClassKind)));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](ruleVerificationList.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ruleVerificationList.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleVerificationList.Iid));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleVerificationList.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](ruleVerificationList.Name));
            jsonObject.Add("owner", this.PropertySerializerMap["owner"](ruleVerificationList.Owner));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleVerificationList.RevisionNumber));
            jsonObject.Add("ruleVerification", this.PropertySerializerMap["ruleVerification"](ruleVerificationList.RuleVerification.OrderBy(x => x, this.orderedItemComparer)));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ruleVerificationList.ShortName));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleVerificationList.ThingPreference));
            return(jsonObject);
        }
Esempio n. 23
0
        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));
        }
Esempio n. 24
0
        public void VerifyThatWhenIBuiltInRuleMetaDataIsDraggedDropEffectIsCopy()
        {
            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 metaData = new Mock <IBuiltInRuleMetaData>();

            metaData.Setup(x => x.Name).Returns("test");

            var dropInfo = new Mock <IDropInfo>();

            dropInfo.Setup(x => x.Payload).Returns(metaData.Object);
            dropInfo.SetupProperty(x => x.Effects);

            listRowViewModel.DragOver(dropInfo.Object);

            Assert.AreEqual(DragDropEffects.Copy, dropInfo.Object.Effects);
        }
Esempio n. 25
0
        public void VerifyThatRuleIsAddedToViewModel()
        {
            var viewmodel = new RuleVerificationListBrowserViewModel(this.iteration, this.participant, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null);

            var ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = this.domain
            };

            this.iteration.RuleVerificationList.Add(ruleVerificationList);
            this.revision.SetValue(this.iteration, 2);
            CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated);

            var row = viewmodel.RuleVerificationListRowViewModels.Single(x => x.Thing == ruleVerificationList);

            Assert.AreEqual(row.Owner, this.domain);

            this.iteration.RuleVerificationList.Remove(ruleVerificationList);
            this.revision.SetValue(this.iteration, 3);
            CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated);

            Assert.IsEmpty(viewmodel.RuleVerificationListRowViewModels);
        }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuleVerificationListRowViewModel"/> class.
 /// </summary>
 /// <param name="ruleVerificationList">
 /// The <see cref="CDP4Common.EngineeringModelData.RuleVerificationList"/> that is represented by the current row-view-model.
 /// </param>
 /// <param name="session">
 /// The current active <see cref="ISession"/>
 /// </param>
 /// <param name="containerViewModel">
 /// The view-model that is the container of the current row-view-model.
 /// </param>
 public RuleVerificationListRowViewModel(RuleVerificationList ruleVerificationList, ISession session, IViewModelBase <Thing> containerViewModel)
     : base(ruleVerificationList, session, containerViewModel)
 {
     this.UpdateProperties();
 }
Esempio n. 27
0
        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);
        }
        /// <summary>
        /// Execute the <see cref="BuiltInRuleVerification"/>.
        /// </summary>
        /// <param name="session">
        /// The <see cref="ISession"/> instance used to update the contained <see cref="RuleVerification"/> instances on the data-source.
        /// </param>
        /// <param name="builtInRuleVerification">
        /// The <see cref="BuiltInRuleVerification"/> that needs to be verified.
        /// </param>
        /// <param name="container">
        /// The container <see cref="RuleVerificationList"/> of the <paramref name="userRuleVerification"/>
        /// </param>
        private void Execute(ISession session, BuiltInRuleVerification builtInRuleVerification, RuleVerificationList container)
        {
            var iteration = (Iteration)container.Container;

            if (iteration == null)
            {
                throw new ContainmentException(string.Format("The container Iteration of the RuleVerificationList {0} has not been set", container.Iid));
            }

            foreach (var violation in builtInRuleVerification.Violation)
            {
                CDPMessageBus.Current.SendObjectChangeEvent(violation, EventKind.Removed);
            }

            builtInRuleVerification.Violation.Clear();
            CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated);

            var builtInRule = this.QueryBuiltInRule(builtInRuleVerification);

            if (builtInRule == null)
            {
                logger.Debug("The BuiltInRule with name {0} is not registered with the Service. The BuiltInRuleVerification cannot be executed", builtInRuleVerification.Name);
                return;
            }

            IEnumerable <RuleViolation> violations = builtInRule.Verify(iteration);

            this.UpdateExecutedOn(session, builtInRuleVerification);

            builtInRuleVerification.Violation.AddRange(violations);

            CDPMessageBus.Current.SendObjectChangeEvent(builtInRuleVerification, EventKind.Updated);

            foreach (var ruleViolation in violations)
            {
                CDPMessageBus.Current.SendObjectChangeEvent(ruleViolation, EventKind.Added);
            }
        }
        /// <summary>
        /// Execute the <see cref="Rule"/> verification.
        /// </summary>
        /// <param name="session">
        /// The <see cref="ISession"/> instance used to update the contained <see cref="RuleVerification"/> instances on the data-source.
        /// </param>
        /// <param name="userRuleVerification">
        /// The <see cref="UserRuleVerification"/> that references <see cref="Rule"/> that needs to be verified.
        /// </param>
        /// <param name="container">
        /// The container <see cref="RuleVerificationList"/> of the <paramref name="userRuleVerification"/>
        /// </param>
        /// <returns>An awaitable <see cref="Task"/></returns>
        private async Task Execute(ISession session, UserRuleVerification userRuleVerification, RuleVerificationList container)
        {
            var iteration = (Iteration)container.Container;

            if (iteration == null)
            {
                throw new ContainmentException(string.Format("The container Iteration of the RuleVerificationList {0} has not been set", container.Iid));
            }

            foreach (var violation in userRuleVerification.Violation)
            {
                CDPMessageBus.Current.SendObjectChangeEvent(violation, EventKind.Removed);
            }

            userRuleVerification.Violation.Clear();
            userRuleVerification.Status = RuleVerificationStatusKind.PASSED;

            CDPMessageBus.Current.SendObjectChangeEvent(userRuleVerification, EventKind.Updated);

            IEnumerable <RuleViolation> violations = null;

            switch (userRuleVerification.Rule.ClassKind)
            {
            case ClassKind.BinaryRelationshipRule:
                var binaryRelationshipRule = (BinaryRelationshipRule)userRuleVerification.Rule;
                violations = binaryRelationshipRule.Verify(iteration);
                break;

            case ClassKind.DecompositionRule:
                var decompositionRule = (DecompositionRule)userRuleVerification.Rule;
                violations = decompositionRule.Verify(iteration);
                break;

            case ClassKind.MultiRelationshipRule:
                var multiRelationshipRule = (MultiRelationshipRule)userRuleVerification.Rule;
                violations = multiRelationshipRule.Verify(iteration);
                break;

            case ClassKind.ParameterizedCategoryRule:
                var parameterizedCategoryRule = (ParameterizedCategoryRule)userRuleVerification.Rule;
                violations = parameterizedCategoryRule.Verify(iteration);
                break;

            case ClassKind.ReferencerRule:
                var referencerRule = (ReferencerRule)userRuleVerification.Rule;
                violations = referencerRule.Verify(iteration);
                break;
            }

            if (violations is not null)
            {
                userRuleVerification.Status = RuleVerificationStatusKind.FAILED;

                IDisposable subscription = null;

                //Listen for changes to the verification rule that will happen after UpdateExecutedOn in order to get the updated version.
                //The violations must be added lastly as they are not persistent
                subscription = CDPMessageBus.Current.Listen <ObjectChangedEvent>(userRuleVerification)
                               .Where(objectChange => objectChange.EventKind == EventKind.Updated)
                               .ObserveOn(RxApp.MainThreadScheduler)
                               .Subscribe(updated =>
                {
                    //Only interested in a single update
                    subscription.Dispose();

                    var verification = updated.ChangedThing as UserRuleVerification;
                    verification.Violation.AddRange(violations);

                    CDPMessageBus.Current.SendObjectChangeEvent(verification, EventKind.Updated);

                    foreach (var ruleViolation in violations)
                    {
                        CDPMessageBus.Current.SendObjectChangeEvent(ruleViolation, EventKind.Added);
                    }
                });
            }

            await this.UpdateExecutedOn(session, userRuleVerification);
        }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuleVerificationListDialogViewModel"/> class
 /// </summary>
 /// <param name="ruleVerificationList">
 /// The <see cref="RuleVerificationList"/> 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="DialogViewModelBase{T}"/> is the root of all <see cref="DialogViewModelBase{T}"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="DialogViewModelBase{T}"/> 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>
 public RuleVerificationListDialogViewModel(RuleVerificationList ruleVerificationList, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container, IEnumerable <Thing> chainOfContainers)
     : base(ruleVerificationList, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
 }