public void Setup()
        {
            this.model     = new EngineeringModel(Guid.NewGuid(), 0);
            this.iteration = new Iteration(Guid.NewGuid(), 0);
            this.statelist = new PossibleFiniteStateList(Guid.NewGuid(), 0)
            {
                IterationContainerId = this.iteration.Iid
            };
            this.state = new PossibleFiniteState(Guid.NewGuid(), 0)
            {
                IterationContainerId = this.iteration.Iid
            };
            this.model.Iteration.Add(this.iteration.Iid);
            this.iteration.PossibleFiniteStateList.Add(this.statelist.Iid);
            this.statelist.PossibleState.Add(new OrderedItem {
                K = 1, V = this.state.Iid
            });

            this.assembler = new Assembler(this.uri);
            this.session   = new Mock <ISession>();
            this.session.Setup(x => x.Assembler).Returns(this.assembler);

            this.pocoModel     = new Poco.EngineeringModel(this.model.Iid, this.assembler.Cache, this.uri);
            this.pocoIt        = new Poco.Iteration(this.iteration.Iid, this.assembler.Cache, this.uri);
            this.pocoStateList = new Poco.PossibleFiniteStateList(this.statelist.Iid, this.assembler.Cache, this.uri);
            this.pocoState     = new Poco.PossibleFiniteState(this.state.Iid, this.assembler.Cache, this.uri);

            this.pocoModel.Iteration.Add(pocoIt);
            this.pocoIt.PossibleFiniteStateList.Add(pocoStateList);
            this.pocoStateList.PossibleState.Add(pocoState);
        }
        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());
        }
Esempio n. 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>()));
            });
        }