public void SetUp() { this.serviceLocator = new Mock <IServiceLocator>(); ServiceLocator.SetLocatorProvider(new ServiceLocatorProvider(() => this.serviceLocator.Object)); this.serviceLocator.Setup(x => x.GetInstance <IMetaDataProvider>()).Returns(new MetaDataProvider()); var sourcePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\test.xlsx"); var fileinfo = new FileInfo(sourcePath); var targetPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\temporarytestfile.xlsx"); var tempfile = fileinfo.CopyTo(targetPath, true); this.testfilepath = tempfile.FullName; var siteDirectory = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), null, null); var engineeringModelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), null, null) { Name = "test model", ShortName = "testmodel" }; siteDirectory.Model.Add(engineeringModelSetup); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), null, null) { IterationIid = Guid.NewGuid() }; engineeringModelSetup.IterationSetup.Add(iterationSetup); var person = new CDP4Common.SiteDirectoryData.Person(Guid.NewGuid(), null, null) { GivenName = "test", Surname = "user" }; siteDirectory.Person.Add(person); var domainOfExpertise = new CDP4Common.SiteDirectoryData.DomainOfExpertise(Guid.NewGuid(), null, null); siteDirectory.Domain.Add(domainOfExpertise); this.workbookSession = new WorkbookSession(person, engineeringModelSetup, iterationSetup, domainOfExpertise); this.workbookSession.RebuildDateTime = DateTime.Now; }
/// <summary> /// Initializes a new instance of the <see cref="WorkbookSession"/> class. /// </summary> /// <param name="person"> /// The person. /// </param> /// <param name="engineeringModelSetup"> /// The engineering model setup. /// </param> /// <param name="iterationSetup"> /// The iteration setup. /// </param> /// <param name="domainOfExpertise"> /// The domain Of Expertise. /// </param> public WorkbookSession(CDP4Common.SiteDirectoryData.Person person, CDP4Common.SiteDirectoryData.EngineeringModelSetup engineeringModelSetup, CDP4Common.SiteDirectoryData.IterationSetup iterationSetup, CDP4Common.SiteDirectoryData.DomainOfExpertise domainOfExpertise) { this.RebuildDateTime = DateTime.UtcNow; this.Person = (Person)person.ToDto(); this.EngineeringModelSetup = (EngineeringModelSetup)engineeringModelSetup.ToDto(); this.IterationSetup = (IterationSetup)iterationSetup.ToDto(); this.DomainOfExpertise = (DomainOfExpertise)domainOfExpertise.ToDto(); }
public void VerifyThatCreatingOverrideCreateSubscriptions() { 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 EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri); var iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri); var elementDef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = domain1 }; var defForUsage = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = domain1 }; var usage = new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri) { ElementDefinition = defForUsage }; var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = domain1 }; var parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = domain2 }; parameter.ParameterSubscription.Add(parameterSubscription); this.assembler.Cache.TryAdd(new CacheKey(parameter.Iid, iteration.Iid), new Lazy <Thing>(() => parameter)); this.assembler.Cache.TryAdd(new CacheKey(parameterSubscription.Iid, iteration.Iid), new Lazy <Thing>(() => parameterSubscription)); this.assembler.Cache.TryAdd(new CacheKey(usage.Iid, iteration.Iid), new Lazy <Thing>(() => usage)); var parameterOverride = new 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)); operationContainer.AddOperation(new Operation(usage.ToDto(), usage.ToDto(), OperationKind.Update)); var modifier = new OperationModifier(this.session.Object); modifier.ModifyOperationContainer(operationContainer); Assert.AreEqual(3, operationContainer.Operations.Count()); }
private void InstantiateThings() { var siteDirectory = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), null, null); var domain1 = new CDP4Common.SiteDirectoryData.DomainOfExpertise(Guid.NewGuid(), null, null); siteDirectory.Domain.Add(domain1); var domain2 = new CDP4Common.SiteDirectoryData.DomainOfExpertise(Guid.NewGuid(), null, null); siteDirectory.Domain.Add(domain2); var alias = new CDP4Common.CommonData.Alias(Guid.NewGuid(), null, null); domain1.Alias.Add(alias); var engineeringModelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), null, null); siteDirectory.Model.Add(engineeringModelSetup); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), null, null); engineeringModelSetup.IterationSetup.Add(iterationSetup); var participantRole1 = new CDP4Common.SiteDirectoryData.ParticipantRole(Guid.NewGuid(), null, null); siteDirectory.ParticipantRole.Add(participantRole1); var participantRole2 = new CDP4Common.SiteDirectoryData.ParticipantRole(Guid.NewGuid(), null, null); siteDirectory.ParticipantRole.Add(participantRole2); var person1 = new CDP4Common.SiteDirectoryData.Person(Guid.NewGuid(), null, null); siteDirectory.Person.Add(person1); var personRole1 = new CDP4Common.SiteDirectoryData.PersonRole(Guid.NewGuid(), null, null); siteDirectory.PersonRole.Add(personRole1); var siteReferenceDataLibrary1 = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary(Guid.NewGuid(), null, null); siteDirectory.SiteReferenceDataLibrary.Add(siteReferenceDataLibrary1); var engineeringModel = new CDP4Common.EngineeringModelData.EngineeringModel(Guid.NewGuid(), null, null); engineeringModel.EngineeringModelSetup = engineeringModelSetup; engineeringModelSetup.EngineeringModelIid = engineeringModel.Iid; this.iteration = new CDP4Common.EngineeringModelData.Iteration(Guid.NewGuid(), null, null); this.iteration.IterationSetup = iterationSetup; iterationSetup.IterationIid = this.iteration.Iid; engineeringModel.Iteration.Add(this.iteration); var modelReferenceDataLibrary = new CDP4Common.SiteDirectoryData.ModelReferenceDataLibrary(Guid.NewGuid(), null, null); modelReferenceDataLibrary.RequiredRdl = siteReferenceDataLibrary1; engineeringModelSetup.RequiredRdl.Add(modelReferenceDataLibrary); var participant = new CDP4Common.SiteDirectoryData.Participant(Guid.NewGuid(), null, null); participant.Person = person1; participant.Domain.Add(domain1); participant.Role = participantRole1; engineeringModelSetup.Participant.Add(participant); var elementDefinition1 = new CDP4Common.EngineeringModelData.ElementDefinition(Guid.NewGuid(), null, null); this.iteration.Element.Add(elementDefinition1); var elementDefinition2 = new CDP4Common.EngineeringModelData.ElementDefinition(Guid.NewGuid(), null, null); this.iteration.Element.Add(elementDefinition2); var elementUsage = new CDP4Common.EngineeringModelData.ElementUsage(Guid.NewGuid(), null, null); elementDefinition1.ContainedElement.Add(elementUsage); elementUsage.ElementDefinition = elementDefinition2; }
/// <summary> /// Build operation containes structure that will be serialized /// </summary> /// <returns> /// List of <see cref="OperationContainer"/> /// </returns> private IEnumerable <OperationContainer> BuildOperationContainers() { var cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); // DomainOfExpertise var domain = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "SYS" }; this.siteDirectoryData.Domain.Add(domain); // PersonRole var role = new PersonRole(Guid.NewGuid(), null, null); this.siteDirectoryData.PersonRole.Add(role); this.siteDirectoryData.DefaultPersonRole = role; // ParticipantRole var participantRole = new ParticipantRole(Guid.Empty, null, null); this.siteDirectoryData.ParticipantRole.Add(participantRole); this.siteDirectoryData.DefaultParticipantRole = participantRole; // Organization var organization = new Organization(Guid.NewGuid(), null, null) { Container = this.siteDirectoryData }; // Iteration var iterationIid = new Guid("b58ea73d-350d-4520-b9d9-a52c75ac2b5d"); var iterationSetup = new IterationSetup(Guid.NewGuid(), 0); var iterationSetupPoco = new CDP4Common.SiteDirectoryData.IterationSetup(iterationSetup.Iid, cache, this.credentials.Uri); // EngineeringModel var model = new EngineeringModel(Guid.NewGuid(), cache, this.credentials.Uri); var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(); modelSetup.ActiveDomain.Add(domain); var requiredRdl = new ModelReferenceDataLibrary(); var person = new Person { ShortName = "admin", Organization = organization }; var participant = new Participant(Guid.NewGuid(), cache, this.credentials.Uri) { Person = person }; participant.Person.Role = role; participant.Role = participantRole; participant.Domain.Add(domain); modelSetup.Participant.Add(participant); var lazyPerson = new Lazy <Thing>(() => person); var iterationPoco = new CDP4Common.EngineeringModelData.Iteration(iterationIid, cache, this.credentials.Uri) { IterationSetup = iterationSetupPoco }; model.Iteration.Add(iterationPoco); var iteration = (Iteration)iterationPoco.ToDto(); model.EngineeringModelSetup = modelSetup; this.siteDirectoryData.Model.Add(modelSetup); modelSetup.RequiredRdl.Add(requiredRdl); modelSetup.IterationSetup.Add(iterationSetupPoco); cache.TryAdd(new CacheKey(person.Iid, this.siteDirectoryData.Iid), lazyPerson); this.siteDirectoryData.Cache = cache; iteration.IterationSetup = iterationSetup.Iid; var iterationClone = iteration.DeepClone <Iteration>(); var operation = new Operation(iteration, iterationClone, OperationKind.Update); var operationContainers = new[] { new OperationContainer("/EngineeringModel/" + model.Iid + "/iteration/" + iteration.Iid, 0) }; operationContainers.Single().AddOperation(operation); return(operationContainers); }
public async Task VerifyWriteEnumerableOperationContainer() { var cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); var files = new[] { "file1" }; Assert.Throws <ArgumentNullException>(() => this.dal.Write((IEnumerable <OperationContainer>)null, files)); Assert.Throws <ArgumentException>(() => this.dal.Write(new List <OperationContainer>(), files)); var operationContainers = new[] { new OperationContainer("/SiteDirectory/00000000-0000-0000-0000-000000000000", 0) }; Assert.Throws <ArgumentException>(() => this.dal.Write(operationContainers, files)); var domainSys = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "SYS" }; this.siteDirectoryData.Domain.Add(domainSys); var domainAer = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "AER" }; this.siteDirectoryData.Domain.Add(domainAer); var domainProp = new DomainOfExpertise(Guid.NewGuid(), cache, this.credentials.Uri) { ShortName = "PROP" }; this.siteDirectoryData.Domain.Add(domainProp); // PersonRole var role = new PersonRole(Guid.NewGuid(), null, null); this.siteDirectoryData.PersonRole.Add(role); this.siteDirectoryData.DefaultPersonRole = role; // ParticipantRole var participantRole = new ParticipantRole(Guid.Empty, null, null); this.siteDirectoryData.ParticipantRole.Add(participantRole); this.siteDirectoryData.DefaultParticipantRole = participantRole; // Organization var organization = new Organization(Guid.NewGuid(), null, null) { Container = this.siteDirectoryData }; var sitedirectoryDto = (CDP4Common.DTO.SiteDirectory) this.siteDirectoryData.ToDto(); var clone = sitedirectoryDto.DeepClone <CDP4Common.DTO.SiteDirectory>(); var operation = new Operation(sitedirectoryDto, clone, OperationKind.Update); Assert.AreEqual(0, operationContainers.Single().Operations.Count()); operationContainers.Single().AddOperation(operation); Assert.AreEqual(1, operationContainers.Single().Operations.Count()); Assert.Throws <ArgumentException>(() => this.dal.Write(operationContainers, files)); operationContainers.Single().RemoveOperation(operation); Assert.AreEqual(0, operationContainers.Single().Operations.Count()); var iterationIid = new Guid("b58ea73d-350d-4520-b9d9-a52c75ac2b5d"); var iterationSetup = new IterationSetup(Guid.NewGuid(), 0); var iterationSetupPoco = new CDP4Common.SiteDirectoryData.IterationSetup(iterationSetup.Iid, cache, this.credentials.Uri); var model = new EngineeringModel(Guid.NewGuid(), cache, this.credentials.Uri); var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(); modelSetup.ActiveDomain.Add(domainSys); var source = new ReferenceSource(Guid.NewGuid(), cache, this.credentials.Uri) { Publisher = new Organization(Guid.NewGuid(), cache, this.credentials.Uri) { Container = this.siteDirectoryData } }; var requiredRdl = new ModelReferenceDataLibrary { RequiredRdl = new SiteReferenceDataLibrary(), ReferenceSource = { source } }; var person = new Person { ShortName = "admin", Organization = organization, DefaultDomain = domainAer }; var participant = new Participant(Guid.NewGuid(), cache, this.credentials.Uri) { Person = person }; participant.Person.Role = role; participant.Role = participantRole; participant.Domain.Add(domainSys); participant.Domain.Add(domainProp); modelSetup.Participant.Add(participant); var lazyPerson = new Lazy <Thing>(() => person); var iterationPoco = new CDP4Common.EngineeringModelData.Iteration(iterationIid, cache, this.credentials.Uri) { IterationSetup = iterationSetupPoco }; model.Iteration.Add(iterationPoco); var iteration = (Iteration)iterationPoco.ToDto(); model.EngineeringModelSetup = modelSetup; this.siteDirectoryData.Model.Add(modelSetup); modelSetup.RequiredRdl.Add(requiredRdl); modelSetup.IterationSetup.Add(iterationSetupPoco); cache.TryAdd(new CacheKey(person.Iid, this.siteDirectoryData.Iid), lazyPerson); this.siteDirectoryData.Cache = cache; iteration.IterationSetup = iterationSetup.Iid; var clone1 = iteration.DeepClone <Iteration>(); operation = new Operation(iteration, clone1, OperationKind.Update); var operationContainer = new OperationContainer("/EngineeringModel/" + model.Iid + "/iteration/" + iteration.Iid, 0); operationContainer.AddOperation(operation); operationContainers = new[] { operationContainer, operationContainer }; Assert.IsEmpty(await this.dal.Write(operationContainers, files)); }
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>())); }); }