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()); }
public void Setup() { this.cache = new List <Thing>(); RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.session = new Mock <ISession>(); this.uri = new Uri("http://test.com"); this.assembler = new Assembler(this.uri); this.panelNavigationService = new Mock <IPanelNavigationService>(); this.sitedir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri); this.pt = new TextParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri); this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri); this.sitedir.Person.Add(person); this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "TestDoE" }; this.sitedir.Domain.Add(this.domain); this.session.Setup(x => x.ActivePerson).Returns(this.person); this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri); this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri); this.elementDef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "1" }; this.elementDef.Owner = this.domain; this.elementDef.Container = this.iteration; this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri) { Person = this.person }; this.participant.Domain.Add(this.domain); var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri) { Container = this.elementDef, ParameterType = this.pt, Owner = this.elementDef.Owner }; var parameterOverride = new ParameterOverride(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = this.domain, Parameter = parameter, Container = this.elementDef }; var elementUsage = new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri) { ElementDefinition = this.elementDef }; elementUsage.ParameterOverride.Add(parameterOverride); elementUsage.Container = this.iteration; this.elementDef.ContainedElement.Add(elementUsage); this.model.Iteration.Add(this.iteration); var iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.iteration.IterationSetup = iterationSetup; this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "ModelSetup" }; this.engineeringModelSetup.IterationSetup.Add(iterationSetup); this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri); this.sitedir.SiteReferenceDataLibrary.Add(this.srdl); this.srdl.ParameterType.Add(this.pt); this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri); this.mrdl.RequiredRdl = this.srdl; this.engineeringModelSetup.RequiredRdl.Add(this.mrdl); this.model.EngineeringModelSetup = this.engineeringModelSetup; this.model.EngineeringModelSetup.Participant.Add(this.participant); this.permissionService = new Mock <IPermissionService>(); this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > { { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) } }); this.assembler.Cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration)); this.assembler.Cache.TryAdd(new CacheKey(this.model.Iid, null), new Lazy <Thing>(() => this.model)); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.dialogNavigationService = new Mock <IDialogNavigationService>(); this.dialogNavigationService.Setup(x => x.NavigateModal(It.IsAny <IterationTrackParameterDetailViewModel>())).Returns(new BaseDialogResult(true)); }
public void SetUp() { this.assembler = new Assembler(this.credentials.Uri); this.session = new Mock <ISession>(); this.session.Setup(x => x.Credentials).Returns(this.credentials); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Container = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { EngineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) }, IterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { IterationNumber = 1 } }; var domain = new DomainOfExpertise(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri) { Name = "Domain" }; var elementDefinition = new ElementDefinition { Iid = Guid.NewGuid(), Name = "ElementDefinition_1", ShortName = "ED_1", Container = this.iteration, Owner = domain }; var parameterType = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "P_SimpleQuantityKind" }; var parameterTypeRedundancy = new CompoundParameterType(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Name = "redundancy", ShortName = "redundancy", Component = { new ParameterTypeComponent(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "scheme", ParameterType = new TextParameterType(Guid.NewGuid(),this.assembler.Cache, this.credentials.Uri) { ShortName = "scheme_pt" } }, new ParameterTypeComponent(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "type", ParameterType = new TextParameterType(Guid.NewGuid(),this.assembler.Cache, this.credentials.Uri) { ShortName = "type_pt" } }, new ParameterTypeComponent(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "k", ParameterType = new TextParameterType(Guid.NewGuid(),this.assembler.Cache, this.credentials.Uri) { ShortName = "k_pt" } }, new ParameterTypeComponent(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "n", ParameterType = new TextParameterType(Guid.NewGuid(),this.assembler.Cache, this.credentials.Uri) { ShortName = "n_pt" } } } }; var parameterTypePowerOn = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "P_on" }; var parameterTypePowerStandby = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "P_stby" }; var parameterTypePowerPeak = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "P_peak" }; var parameterTypePowerDutyCycle = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ShortName = "P_duty_cyc" }; var parameterTypePowerMean = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Name = "P_mean", ShortName = "P_mean" }; var parameter = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterType, Scale = parameterType.DefaultScale, Owner = domain }; this.parameterRedundancy = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterTypeRedundancy, Scale = parameterTypePowerOn.DefaultScale, Owner = domain }; this.parameterPowerOn = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterTypePowerOn, Scale = parameterTypePowerOn.DefaultScale, Owner = domain }; this.parameterPowerStandBy = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterTypePowerStandby, Scale = parameterTypePowerOn.DefaultScale, Owner = domain }; this.parameterPowerPeak = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterTypePowerPeak, Scale = parameterTypePowerOn.DefaultScale, Owner = domain }; this.parameterPowerPowerDutyCycle = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterTypePowerDutyCycle, Scale = parameterTypePowerOn.DefaultScale, Owner = domain }; this.parameterPowerMean = new Parameter { Iid = Guid.NewGuid(), ParameterType = parameterTypePowerMean, Scale = parameterTypePowerOn.DefaultScale, Owner = domain }; this.iteration.Element.Add(elementDefinition); this.iteration.Element.FirstOrDefault()?.Parameter.Add(parameter); 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.excelFilePath = tempfile.FullName; }
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>())); }); }
private void InstantiateThings() { this.serviceLocator = new Mock <IServiceLocator>(); ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object); this.serviceLocator.Setup(x => x.GetInstance <IMetaDataProvider>()).Returns(new MetaDataProvider()); this.assembler = new Assembler(this.credentials.Uri); this.session = new Mock <ISession>(); this.session.Setup(x => x.Credentials).Returns(this.credentials); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.session.Setup(x => x.ActivePerson).Returns(this.person); this.siteDir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri); this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Container = this.siteDir }; this.siteDir.Person.Add(this.person); this.genericRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Name = "Generic RDL", ShortName = "GenRDL" }; this.siteRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { RequiredRdl = this.genericRdl }; this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl); this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Container = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { EngineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) }, IterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { IterationNumber = 1 } }; var domain = new DomainOfExpertise(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri) { Name = "Domain" }; this.elementDefinition = new ElementDefinition(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri) { Name = "ElementDefinition", ShortName = "ED", Container = this.iteration, Owner = domain }; this.parameterType = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { Name = "SimpleQuantityKind", ShortName = "SQK", }; this.siteRdl.ParameterType.Add(this.parameterType); var parameter = new CDP4Common.EngineeringModelData.Parameter(Guid.NewGuid(), this.assembler.Cache, this.credentials.Uri) { ParameterType = this.parameterType, Scale = this.parameterType.DefaultScale, Owner = domain }; this.iteration.Element.Add(this.elementDefinition); this.iteration.Element.FirstOrDefault()?.Parameter.Add(parameter); }