Пример #1
0
        public void VerifyHighlightElementUsagesEventIsSent()
        {
            var eu1 = new CDP4Common.EngineeringModelData.ElementDefinition();
            var eu2 = new CDP4Common.EngineeringModelData.ElementDefinition();

            CDPMessageBus.Current.Listen <ElementUsageHighlightEvent>().Subscribe(x => this.OnElementUsageHighlightEvent(x.ElementDefinition));

            CDPMessageBus.Current.SendMessage(new ElementUsageHighlightEvent(eu1));
            Assert.AreEqual(1, this.cache.Count);

            CDPMessageBus.Current.SendMessage(new ElementUsageHighlightEvent(eu2));
            Assert.AreEqual(2, this.cache.Count);
        }
        public void VerifyThatNoOperationAdded()
        {
            var domain1 = new CDP4Common.SiteDirectoryData.DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache,
                                                                             this.uri);
            var domain2 = new CDP4Common.SiteDirectoryData.DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache,
                                                                             this.uri);
            var model      = new CDP4Common.EngineeringModelData.EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var iteration  = new CDP4Common.EngineeringModelData.Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var elementDef = new CDP4Common.EngineeringModelData.ElementDefinition(Guid.NewGuid(), this.assembler.Cache,
                                                                                   this.uri)
            {
                Owner = domain1
            };
            var defForUsage = new CDP4Common.EngineeringModelData.ElementDefinition(Guid.NewGuid(), this.assembler.Cache,
                                                                                    this.uri)
            {
                Owner = domain1
            };
            var usage = new CDP4Common.EngineeringModelData.ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ElementDefinition = defForUsage
            };

            var parameter = new CDP4Common.EngineeringModelData.Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Owner = domain1
            };
            var parameterSubscription = new CDP4Common.EngineeringModelData.ParameterSubscription(Guid.NewGuid(),
                                                                                                  this.assembler.Cache, this.uri)
            {
                Owner = domain2
            };

            parameter.ParameterSubscription.Add(parameterSubscription);

            var parameterOverride = new CDP4Common.EngineeringModelData.ParameterOverride(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Owner     = domain1,
                Parameter = parameter
            };

            usage.ParameterOverride.Add(parameterOverride);

            model.Iteration.Add(iteration);
            iteration.Element.Add(elementDef);
            iteration.Element.Add(defForUsage);
            elementDef.ContainedElement.Add(usage);
            defForUsage.Parameter.Add(parameter);

            var transactionContext = TransactionContextResolver.ResolveContext(iteration);
            var context            = transactionContext.ContextRoute();

            var operationContainer = new OperationContainer(context, model.RevisionNumber);

            operationContainer.AddOperation(new Operation(null, parameterOverride.ToDto(), OperationKind.Create));

            var modifier = new OperationModifier(this.session.Object);

            modifier.ModifyOperationContainer(operationContainer);

            Assert.AreEqual(1, operationContainer.Operations.Count());
        }
Пример #3
0
        private void InitSessionThings()
        {
            // Site Directory
            this.siteDirectory = new SiteDirectory(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                                   this.session.Object.Credentials.Uri);

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                                this.session.Object.Credentials.Uri)
            {
                Name = "domain"
            };
            this.siteDirectory.Domain.Add(this.domain);

            this.person = new Person(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                     this.session.Object.Credentials.Uri)
            {
                ShortName     = this.credentials.UserName,
                GivenName     = this.credentials.UserName,
                Password      = this.credentials.Password,
                DefaultDomain = this.domain,
                IsActive      = true
            };
            this.siteDirectory.Person.Add(this.person);

            this.participant =
                new Participant(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                this.session.Object.Credentials.Uri)
            {
                Person = this.person
            };
            this.participant.Domain.Add(this.domain);

            // Site Rld
            this.siteReferenceDataLibrary =
                new SiteReferenceDataLibrary(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                             this.session.Object.Credentials.Uri)
            {
                ShortName = "Generic_RDL"
            };
            this.quantityKindParamType = new SimpleQuantityKind(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                                                this.session.Object.Credentials.Uri)
            {
                Name      = "m",
                ShortName = "m"
            };
            this.siteReferenceDataLibrary.ParameterType.Add(this.quantityKindParamType);

            // Model Rdl
            this.modelReferenceDataLibrary =
                new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                              this.session.Object.Credentials.Uri)
            {
                RequiredRdl = this.siteReferenceDataLibrary
            };
            this.siteDirectory.SiteReferenceDataLibrary.Add(this.siteReferenceDataLibrary);

            // Iteration
            this.iteration = new Iteration(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                           this.session.Object.Credentials.Uri);
            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                                     this.session.Object.Credentials.Uri)
            {
                IterationIid = this.iteration.Iid
            };

            // Engineering Model & Setup
            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                                         this.session.Object.Credentials.Uri)
            {
                EngineeringModelSetup = this.engineeringModelSetup
            };
            this.engineeringModel.Iteration.Add(this.iteration);

            var ed1    = new ElementDefinition(Guid.NewGuid(), null, null);
            var param1 = new Parameter(Guid.NewGuid(), null, null)
            {
                ParameterType = this.quantityKindParamType
            };

            ed1.Parameter.Add(param1);
            this.iteration.Element.Add(ed1);

            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.session.Object.Assembler.Cache,
                                                                   this.session.Object.Credentials.Uri)
            {
                EngineeringModelIid = this.engineeringModel.Iid
            };
            this.engineeringModelSetup.RequiredRdl.Add(this.modelReferenceDataLibrary);
            this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup);
            this.engineeringModelSetup.Participant.Add(this.participant);
            this.siteDirectory.Model.Add(this.engineeringModelSetup);

            this.sessionThings = new Dictionary <Guid, Thing>
            {
                { this.siteDirectory.Iid, this.siteDirectory.ToDto() },
                { this.domain.Iid, this.domain.ToDto() },
                { this.person.Iid, this.person.ToDto() },
                { this.participant.Iid, this.participant.ToDto() },
                { this.siteReferenceDataLibrary.Iid, this.siteReferenceDataLibrary.ToDto() },
                { this.quantityKindParamType.Iid, this.quantityKindParamType.ToDto() },
                { this.modelReferenceDataLibrary.Iid, this.modelReferenceDataLibrary.ToDto() },
                { this.engineeringModelSetup.Iid, this.engineeringModelSetup.ToDto() },
                { this.iteration.Iid, this.iteration.ToDto() },
                { this.iterationSetup.Iid, this.iterationSetup.ToDto() },
                { this.engineeringModel.Iid, this.engineeringModel.ToDto() }
            };

            this.session = new Mock <ISession>();
            this.session.Setup(s => s.Assembler).Returns(this.assembler);
            this.session.Setup(s => s.Credentials).Returns(this.credentials);
            this.session.Setup(s => s.ActivePerson).Returns(this.person);
            this.session.Setup(s => s.RetrieveSiteDirectory()).Returns(this.siteDirectory);

            this.session.Setup(x => x.Write(It.IsAny <OperationContainer>(), It.IsAny <IEnumerable <string> >()))
            .Returns <OperationContainer, IEnumerable <string> >((operationContainer, files) =>
            {
                foreach (var operation in operationContainer.Operations)
                {
                    var operationThing = operation.ModifiedThing;

                    switch (operation.OperationKind)
                    {
                    case OperationKind.Create:
                        if (!this.generatedThings.ContainsKey(operationThing.Iid))
                        {
                            this.generatedThings[operationThing.Iid] = operationThing;
                        }

                        break;

                    case OperationKind.Update:
                        if (!this.modifiedThings.ContainsKey(operationThing.Iid))
                        {
                            this.modifiedThings[operationThing.Iid] = operationThing;
                        }

                        break;
                    }
                }

                return(Task.FromResult((IEnumerable <Thing>) new List <Thing>()));
            });
        }