示例#1
0
        /// <summary>
        /// Creates and returns a <see cref="ThingTransaction"/> that contains required operations to insert <paramref name="reqToInsert"/> before <paramref name="requirement"/>
        /// </summary>
        /// <param name="reqToInsert">The <see cref="Requirement"/> to insert</param>
        /// <param name="requirement">The <see cref="Requirement"/> that comes right after <paramref name="reqToInsert"/></param>
        /// <param name="insertKind">The <see cref="InsertKind"/></param>
        /// <returns>The <see cref="ThingTransaction"/></returns>
        public ThingTransaction Insert(Requirement reqToInsert, Requirement requirement, InsertKind insertKind)
        {
            var transaction   = new ThingTransaction(TransactionContextResolver.ResolveContext(reqToInsert));
            var specification = (RequirementsSpecification)requirement.Container;

            var allReqInContext = specification.Requirement.Where(x => x.Group == requirement.Group && x.Iid != reqToInsert.Iid).ToList();

            allReqInContext.Add(reqToInsert);

            // contains all new or clone of SimpleParameterValue
            var paramValuesClone = new Dictionary <Guid, SimpleParameterValue>();
            var unorderedReq     = new List <Requirement>();

            // put all ParameterValueSet in transaction as update if existing, as created otherwise
            foreach (var req in allReqInContext)
            {
                // Create SimpleParameterValue if missing
                SimpleParameterValue orderValue;
                if (!this.TryQueryOrderParameterOrCreate(req, out orderValue))
                {
                    var cloneReq = req.Clone(false);
                    cloneReq.ParameterValue.Add(orderValue);
                    transaction.CreateOrUpdate(cloneReq);
                    transaction.CreateOrUpdate(orderValue);
                    paramValuesClone.Add(req.Iid, orderValue);

                    // keep tab on unordered req to put order on their shortname
                    unorderedReq.Add(req);
                }
                else
                {
                    var cloneValue = orderValue.Clone(false);
                    if (req.Iid == reqToInsert.Iid)
                    {
                        // reset current value to max
                        cloneValue.Value = new ValueArray <string>(new [] { int.MaxValue.ToString() });
                    }

                    transaction.CreateOrUpdate(cloneValue);
                    paramValuesClone.Add(req.Iid, cloneValue);
                }
            }

            var reqToInsertClone = (Requirement)transaction.UpdatedThing.SingleOrDefault(x => x.Key.Iid == reqToInsert.Iid).Value;

            if (reqToInsertClone == null)
            {
                reqToInsertClone = reqToInsert.Clone(false);
                transaction.CreateOrUpdate(reqToInsertClone);
            }

            reqToInsertClone.Group = requirement.Group;
            if (reqToInsert.Container != requirement.Container)
            {
                var specClone = (RequirementsSpecification)requirement.Container.Clone(false);

                specClone.Requirement.Add(reqToInsertClone);
                transaction.CreateOrUpdate(specClone);
            }

            // keys
            unorderedReq = unorderedReq.OrderBy(x => x.ShortName).ToList();
            var unorderedReqId = unorderedReq.Select(x => x.Iid).ToList();

            var orderedParamClone = paramValuesClone.Where(x => !unorderedReqId.Contains(x.Key)).OrderBy(x => this.getOrderKey(x.Value)).ToList();

            orderedParamClone.AddRange(paramValuesClone.Where(x => unorderedReqId.Contains(x.Key)).OrderBy(x => unorderedReqId.IndexOf(x.Key)));

            paramValuesClone = orderedParamClone.ToDictionary(x => x.Key, x => x.Value);
            var reqOrderedUuid = paramValuesClone.Where(x => x.Key != reqToInsert.Iid).OrderBy(x => this.getOrderKey(x.Value)).Select(x => x.Key).ToList();

            var indexOfRefInsertReq = reqOrderedUuid.IndexOf(requirement.Iid);
            var endReqIdInterval    = insertKind == InsertKind.InsertBefore
                ? indexOfRefInsertReq > 0 ? (Guid?)reqOrderedUuid[indexOfRefInsertReq - 1] : null
                : indexOfRefInsertReq < reqOrderedUuid.Count - 1
                    ? (Guid?)reqOrderedUuid[indexOfRefInsertReq + 1]
                    : null;

            var upperPair = insertKind == InsertKind.InsertBefore ? paramValuesClone.First(x => x.Key == requirement.Iid) : endReqIdInterval.HasValue ? paramValuesClone.First(x => x.Key == endReqIdInterval) : default(KeyValuePair <Guid, SimpleParameterValue>);
            var lowerPair = insertKind == InsertKind.InsertBefore ? endReqIdInterval.HasValue ? paramValuesClone.First(x => x.Key == endReqIdInterval) : default(KeyValuePair <Guid, SimpleParameterValue>) : paramValuesClone.First(x => x.Key == requirement.Iid);

            var upperKey = upperPair.Value != null?this.getOrderKey(upperPair.Value) : int.MaxValue;

            var lowerKey = lowerPair.Value != null?this.getOrderKey(lowerPair.Value) : int.MinValue;

            // either just update key of the dropped requirement or recompute all keys
            var insertKey = this.ComputeOrderKey(lowerKey, upperKey, paramValuesClone.Values.Select(this.getOrderKey).ToList(), false);

            if (insertKey.HasValue)
            {
                paramValuesClone[reqToInsert.Iid].Value = new ValueArray <string>(new [] { insertKey.ToString() });
            }
            else
            {
                if (unorderedReq.Any(x => !this.session.PermissionService.CanWrite(ClassKind.SimpleParameterValue, x)))
                {
                    // if no permission to update everything, just update value with min or max depending on the kind of insert
                    insertKey = this.ComputeOrderKey(lowerKey, upperKey, paramValuesClone.Values.Select(this.getOrderKey).ToList(), true);
                    paramValuesClone[reqToInsert.Iid].Value = new ValueArray <string>(new[] { insertKey.ToString() });
                }
                else
                {
                    var lower = 0;
                    // recompute all keys in ascending order
                    foreach (var simpleParameterValue in paramValuesClone)
                    {
                        if (simpleParameterValue.Key == reqToInsert.Iid)
                        {
                            continue;
                        }

                        var key = this.ComputeOrderKey(lower, Int32.MaxValue, new List <int>(), true);
                        if (simpleParameterValue.Key == requirement.Iid && insertKind == InsertKind.InsertBefore)
                        {
                            var reqValueToInsert = paramValuesClone.First(x => x.Key == reqToInsert.Iid);
                            reqValueToInsert.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                            key   = this.ComputeOrderKey(lower, Int32.MaxValue, new List <int>(), true);
                            simpleParameterValue.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                        }
                        else if (simpleParameterValue.Key == requirement.Iid && insertKind == InsertKind.InsertAfter)
                        {
                            simpleParameterValue.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;

                            key = this.ComputeOrderKey(lower, Int32.MaxValue, new List <int>(), true);
                            var reqValueToInsert = paramValuesClone.First(x => x.Key == reqToInsert.Iid);
                            reqValueToInsert.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                        }
                        else
                        {
                            simpleParameterValue.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                        }
                    }
                }
            }

            return(transaction);
        }
        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());
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.uri           = new Uri("http://www.rheagroup.com");
            this.dialogService = new Mock <IThingDialogNavigationService>();

            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            var person = new Person(Guid.NewGuid(), null, this.uri)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, this.uri);
            this.siteDir.Person.Add(person);
            this.genericSiteReferenceDataLibrary = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri)
            {
                Name = "Generic RDL", ShortName = "GENRDL"
            };

            this.cat = new Category(Guid.NewGuid(), null, this.uri)
            {
                Name = "category", ShortName = "cat"
            };
            this.cat1 = new Category(Guid.NewGuid(), null, this.uri)
            {
                Name = "category1", ShortName = "cat1"
            };
            this.genericSiteReferenceDataLibrary.DefinedCategory.Add(this.cat);
            this.genericSiteReferenceDataLibrary.DefinedCategory.Add(this.cat1);
            this.siteDir.SiteReferenceDataLibrary.Add(this.genericSiteReferenceDataLibrary);

            this.siteRdl             = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri);
            this.siteRdl.RequiredRdl = this.genericSiteReferenceDataLibrary;
            this.cat2 = new Category(Guid.NewGuid(), null, this.uri)
            {
                Name = "category2", ShortName = "cat2"
            };
            this.cat3 = new Category(Guid.NewGuid(), null, this.uri)
            {
                Name = "category3", ShortName = "cat3"
            };
            this.siteRdl.DefinedCategory.Add(this.cat2);
            this.siteRdl.DefinedCategory.Add(this.cat3);
            this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, null);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary));

            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());
        }
示例#4
0
        public void Setup()
        {
            this.session                      = new Mock <ISession>();
            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            var dal = new Mock <IDal>();

            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            this.thingDialogNavigationService.Setup(
                x =>
                x.Navigate(
                    It.IsAny <Thing>(),
                    It.IsAny <IThingTransaction>(),
                    this.session.Object,
                    false,
                    ThingDialogKind.Create,
                    this.thingDialogNavigationService.Object,
                    It.IsAny <Thing>(),
                    It.IsAny <IEnumerable <Thing> >())).Returns(true);

            this.siteDir        = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.modelsetup     = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.siteDir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationsetup);
            this.siteDir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);

            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup =
                    this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri)
            {
                IterationSetup = this.iterationsetup
            };
            this.requirement           = new Requirement(Guid.NewGuid(), this.cache, this.uri);
            this.relationalExpression  = new RelationalExpression(Guid.NewGuid(), this.cache, this.uri);
            this.andExpression         = new AndExpression(Guid.NewGuid(), this.cache, this.uri);
            this.orExpression          = new OrExpression(Guid.NewGuid(), this.cache, this.uri);
            this.exclusiveOrExpression = new ExclusiveOrExpression(Guid.NewGuid(), this.cache, this.uri);
            this.notExpression         = new NotExpression(Guid.NewGuid(), this.cache, this.uri);
            this.parametricConstraint  = new ParametricConstraint(Guid.NewGuid(), this.cache, this.uri);
            this.requirement.ParametricConstraint.Add(this.parametricConstraint);
            this.parametricConstraint.Expression.Add(this.relationalExpression);
            this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Requirement.Add(this.requirement);
            this.grp = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Group.Add(this.grp);
            this.cache.TryAdd(new CacheKey(this.reqSpec.Iid, null), new Lazy <Thing>(() => this.reqSpec));

            this.model.Iteration.Add(this.iteration);
            this.iteration.RequirementsSpecification.Add(this.reqSpec);

            this.clone = this.requirement.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.clone);
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.navigation           = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            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.session = new Mock <ISession>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            var person = new Person(Guid.NewGuid(), this.cache, null)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, null);
            this.siteDir.Person.Add(person);
            var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, null)
            {
                Name = "testRDL", ShortName = "test"
            };

            this.mappingToReferenceScale = new MappingToReferenceScale(Guid.NewGuid(), null, null);
            this.siteDir.SiteReferenceDataLibrary.Add(rdl);
            this.testRatioScale = new RatioScale(Guid.NewGuid(), this.cache, null)
            {
                Name = "ratioScale", ShortName = "dqk"
            };
            var testRatioScale1 = new RatioScale(Guid.NewGuid(), this.cache, null)
            {
                Name = "ratioScale1", ShortName = "dqk1"
            };
            var svd1 = new ScaleValueDefinition(Guid.NewGuid(), this.cache, null)
            {
                Name = "ReferenceSVD", ShortName = "RSVD"
            };
            var svd2 = new ScaleValueDefinition(Guid.NewGuid(), this.cache, null)
            {
                Name = "DependentSVD", ShortName = "DSVD"
            };

            this.testRatioScale.ValueDefinition.Add(svd1);
            testRatioScale1.ValueDefinition.Add(svd2);
            rdl.Scale.Add(this.testRatioScale);
            rdl.Scale.Add(testRatioScale1);

            this.cache.TryAdd(new CacheKey(this.testRatioScale.Iid, null), new Lazy <Thing>(() => this.testRatioScale));
            this.clone = this.testRatioScale.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);

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

            this.viewmodel = new MappingToReferenceScaleDialogViewModel(this.mappingToReferenceScale, this.transaction, this.session.Object, false, ThingDialogKind.Create, this.navigation.Object, this.clone);
        }
        /// <summary>
        /// Submits the changes the user has made to inputs and outputs on the Parameter sheet to the data-source.
        /// </summary>
        /// <param name="session">
        /// The current <see cref="ISession"/> that is submitting the outputs.
        /// </param>
        /// <param name="iteration">
        /// The <see cref="Iteration"/> that that contains the value sets that value-sets that if changed need to be submitted.
        /// </param>
        public async Task SubmitAll(ISession session, Iteration iteration)
        {
            this.application.StatusBar = string.Empty;

            var workbookSession = await this.CreateWorkbookSession(session.Dal, session.Credentials);

            try
            {
                IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets;
                var parameterSheetProcessor = new ParameterSheetProcessor(workbookSession, iteration);
                parameterSheetProcessor.ValidateValuesAndCheckForChanges(this.application, this.workbook, out processedValueSets);

                if (!processedValueSets.Any())
                {
                    this.application.StatusBar = "Submit cancelled: no values changed";
                    return;
                }

                var submitConfirmationViewModel = new SubmitConfirmationViewModel(processedValueSets, ValueSetKind.All);
                var dialogResult = this.DialogNavigationService.NavigateModal(submitConfirmationViewModel);

                if (dialogResult.Result.HasValue && dialogResult.Result.Value)
                {
                    var submitConfirmationDialogResult = (SubmitConfirmationDialogResult)dialogResult;

                    var context     = TransactionContextResolver.ResolveContext(iteration);
                    var transaction = new ThingTransaction(context);

                    foreach (var clone in submitConfirmationDialogResult.Clones)
                    {
                        transaction.CreateOrUpdate(clone);
                    }

                    // TODO: enable when OperationContainer.ResolveRoute supports this
                    //var clonedEngineeringModel = (EngineeringModel)iteration.Container.Clone();
                    //var logEntry = new ModelLogEntry(iid: Guid.NewGuid())
                    //                   {
                    //                       Content = submitConfirmationDialogResult.SubmitMessage,
                    //                       Author = session.ActivePerson,
                    //                       LanguageCode = "en-GB",
                    //                       Level = LogLevelKind.USER,
                    //                       AffectedItemIid = submitConfirmationDialogResult.Clones.Select(clone => clone.Iid).ToList()
                    //                   };
                    //clonedEngineeringModel.LogEntry.Add(logEntry);
                    //transaction.Create(logEntry);

                    var operationContainer = transaction.FinalizeTransaction();

                    this.application.StatusBar = string.Format("CDP4: Submitting data to {0}", session.DataSourceUri);
                    this.application.Cursor    = XlMousePointer.xlWait;

                    var sw = new Stopwatch();
                    sw.Start();
                    await session.Write(operationContainer);

                    sw.Stop();
                    this.application.StatusBar = string.Format("CDP4: SitedirectoryData submitted in {0} [ms]", sw.ElapsedMilliseconds);

                    this.application.StatusBar = "CDP4: Writing session data to workbook";
                    sw.Start();
                    this.WriteWorkbookDataToWorkbook(iteration);
                    sw.Stop();
                    this.application.StatusBar = string.Format("CDP4: Session data written in {0} [ms]", sw.ElapsedMilliseconds);
                }
                else
                {
                    this.application.StatusBar = "CDP4: Submit parameters and subscription has been cancelled by the user.";

                    var parameterSheetRowHighligter = new ParameterSheetRowHighligter();
                    parameterSheetRowHighligter.HighlightRows(this.application, this.workbook, processedValueSets);
                }
            }
            catch (Exception ex)
            {
                this.application.StatusBar = "CDP4: submission failed.";
                Logger.Error(ex);
            }
            finally
            {
                this.application.Cursor = XlMousePointer.xlDefault;
            }
        }
示例#7
0
        public void Setup()
        {
            this.session                      = new Mock <ISession>();
            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.siteDir        = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.modelsetup     = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };

            this.siteDir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationsetup);
            this.siteDir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);
            this.pt = new BooleanParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.srdl.ParameterType.Add(this.pt);

            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri)
            {
                IterationSetup = this.iterationsetup
            };
            this.requirement    = new Requirement(Guid.NewGuid(), this.cache, this.uri);
            this.parameterValue = new SimpleParameterValue(Guid.NewGuid(), this.cache, this.uri)
            {
                ParameterType = this.pt
            };
            this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Requirement.Add(this.requirement);
            this.requirement.ParameterValue.Add(this.parameterValue);
            this.grp = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Group.Add(this.grp);
            this.cache.TryAdd(new CacheKey(this.reqSpec.Iid, null), new Lazy <Thing>(() => this.reqSpec));

            this.model.Iteration.Add(this.iteration);
            this.iteration.RequirementsSpecification.Add(this.reqSpec);

            this.cat1 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.cat1.PermissibleClass.Add(ClassKind.Requirement);
            this.srdl.DefinedCategory.Add(this.cat1);

            this.cat2 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.srdl.DefinedCategory.Add(this.cat2);

            this.requirementClone = this.requirement.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.requirementClone);

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

            this.cache.TryAdd(new CacheKey(this.parameterValue.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.parameterValue));
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.session = new Mock <ISession>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.fileDialogService            = new Mock <IOpenSaveFileDialogService>();
            this.downloadFileService          = new Mock <IDownloadFileService>();
            this.thingSelectorDialogService   = new Mock <IThingSelectorDialogService>();
            this.serviceLocator = new Mock <IServiceLocator>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IOpenSaveFileDialogService>()).Returns(this.fileDialogService.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingSelectorDialogService>()).Returns(this.thingSelectorDialogService.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IDownloadFileService>()).Returns(this.downloadFileService.Object);

            this.assembler = new Assembler(this.uri);
            this.session.Setup(x => x.Assembler).Returns(this.assembler);
            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

            var dal = new Mock <IDal>();

            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);

            this.sitedir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name = "model"
            };

            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "person",
                GivenName = "person",
            };

            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.session.Setup(x => x.QueryDomainOfExpertise(It.IsAny <Iteration>())).Returns(new List <DomainOfExpertise>()
            {
                this.domain
            });

            this.fileType1 = new FileType(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Extension = "jpg"
            };
            this.fileType2 = new FileType(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Extension = "zip"
            };

            this.thingSelectorDialogService.Setup(x => x.SelectThing(It.IsAny <IEnumerable <FileType> >(), It.IsAny <IEnumerable <string> >())).Returns(this.fileType1);

            this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl,
                FileType    = { this.fileType1, this.fileType2 }
            };

            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new ReferenceDataLibrary[] { this.srdl, this.mrdl });

            this.sitedir.Model.Add(this.engineeringModelSetup);
            this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Person.Add(this.person);
            this.sitedir.Domain.Add(this.domain);
            this.engineeringModelSetup.RequiredRdl.Add(this.mrdl);
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.engineeringModelSetup.Participant.Add(this.participant);
            this.participant.Domain.Add(this.domain);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.engineeringModelSetup
            };

            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup,
                Container      = this.engineeringModelSetup
            };

            this.model.Iteration.Add(this.iteration);

            this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);

            this.session.Setup(x => x.OpenIterations)
            .Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) }
            });

            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

            this.session.Setup(x => x.ActivePerson).Returns(this.person);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);

            this.store = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.iteration
            };

            this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.store,
                Owner     = this.domain
            };

            this.fileRevision = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.file.FileRevision.Add(this.fileRevision);

            this.storeClone = this.store.Clone(false);
            this.fileClone  = this.file.Clone(false);

            this.assembler.Cache.TryAdd(new CacheKey(this.store.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.storeClone));
            this.assembler.Cache.TryAdd(new CacheKey(this.file.Iid, null), new Lazy <Thing>(() => this.fileClone));

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.file);
        }
示例#9
0
        /// <summary>
        /// Creates a <see cref="BinaryRelationship"/>
        /// </summary>
        /// <param name="connector">The drawn <see cref="DiagramConnector"/> that is used as a template.</param>
        private async void CreateBinaryRelationship(DiagramConnector connector)
        {
            var beginItemContent = ((DiagramContentItem)connector?.BeginItem)?.Content as NamedThingDiagramContentItem;
            var endItemContent   = ((DiagramContentItem)connector?.EndItem)?.Content as NamedThingDiagramContentItem;

            if (beginItemContent == null || endItemContent == null)
            {
                // connector was drawn with either the source or target missing
                // remove the dummy connector
                this.Behavior.RemoveItem(connector);
                this.Behavior.ResetTool();
                return;
            }

            // send off the relationship
            Tuple <DomainOfExpertise, Participant> tuple;

            this.Session.OpenIterations.TryGetValue(this.Thing, out tuple);

            var binaryRelationship = new BinaryRelationship(Guid.NewGuid(), null, null)
            {
                Owner = tuple.Item1
            };

            if (this.PendingBinaryRelationshipRule != null)
            {
                binaryRelationship.Category.Add(this.PendingBinaryRelationshipRule.RelationshipCategory);
            }

            var iteration = this.Thing.Clone(false);

            iteration.Relationship.Add(binaryRelationship);

            binaryRelationship.Container = iteration;

            binaryRelationship.Source = beginItemContent.Thing;
            binaryRelationship.Target = endItemContent.Thing;

            var transactionContext   = TransactionContextResolver.ResolveContext(this.Thing);
            var containerTransaction = new ThingTransaction(transactionContext, iteration);

            containerTransaction.CreateOrUpdate(binaryRelationship);

            try
            {
                var operationContainer = containerTransaction.FinalizeTransaction();
                await this.Session.Write(operationContainer);

                // at this point relationship has gone through.

                if (this.Thing.Relationship.FirstOrDefault(r => r.Iid == binaryRelationship.Iid) is BinaryRelationship returedRelationship)
                {
                    this.CreateBinaryRelationshipDiagramConnector(returedRelationship, connector);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Creation of Binary Relationship failed: {ex.Message}",
                                "Creating Binary Relationship Failed",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                // remove the dummy connector
                this.Behavior.RemoveItem(connector);
                this.Behavior.ResetTool();
                this.PendingBinaryRelationshipRule = null;
            }
        }
        public void Setup()
        {
            this.uri = new Uri("http://www.rheagroup.com");
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            var testDomain    = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri);
            var subscription  = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri);
            var anotherDomain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "Other Domain"
            };

            subscription.Owner = anotherDomain;
            var paramValueSet = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri);

            paramValueSet.Computed    = new ValueArray <string>(new[] { "c" });
            paramValueSet.Manual      = new ValueArray <string>(new[] { "m" });
            paramValueSet.Reference   = new ValueArray <string>(new[] { "r" });
            paramValueSet.ValueSwitch = ParameterSwitchKind.COMPUTED;

            var testParamType = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri);

            this.parameter = new Parameter(Guid.NewGuid(), this.cache, this.uri)
            {
                Owner = testDomain, ParameterType = testParamType
            };
            this.parameter.ParameterSubscription.Add(subscription);
            this.parameter.ValueSet.Add(paramValueSet);
            var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);

            elementDefinition.Parameter.Add(this.parameter);
            this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            this.option1   = new Option(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "opt1", ShortName = "o1"
            };
            this.option2 = new Option(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "opt2", ShortName = "o2"
            };
            this.iteration.Option.Add(this.option1);
            this.iteration.Option.Add(this.option2);
            this.iteration.Element.Add(elementDefinition);

            this.psl = new PossibleFiniteStateList(Guid.NewGuid(), this.cache, this.uri);
            this.ps1 = new PossibleFiniteState(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "1", ShortName = "1"
            };
            this.ps2 = new PossibleFiniteState(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "2", ShortName = "2"
            };
            this.psl.PossibleState.Add(this.ps1);
            this.psl.PossibleState.Add(this.ps2);

            this.asl = new ActualFiniteStateList(Guid.NewGuid(), this.cache, this.uri);
            this.as1 = new ActualFiniteState(Guid.NewGuid(), this.cache, this.uri);
            this.as1.PossibleState.Add(this.ps1);
            this.as2 = new ActualFiniteState(Guid.NewGuid(), this.cache, this.uri);
            this.as2.PossibleState.Add(this.ps2);

            this.asl.PossibleFiniteStateList.Add(this.psl);

            this.asl.ActualState.Add(this.as1);
            this.asl.ActualState.Add(this.as2);
            this.iteration.ActualFiniteStateList.Add(this.asl);
            this.iteration.PossibleFiniteStateList.Add(this.psl);

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

            modelSetup.ActiveDomain.Add(testDomain);
            modelSetup.ActiveDomain.Add(anotherDomain);
            var testPerson      = new Person(Guid.NewGuid(), null, null);
            var testParticipant = new Participant(Guid.NewGuid(), null, null)
            {
                Person = testPerson, SelectedDomain = testDomain
            };

            modelSetup.Participant.Add(testParticipant);
            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup = modelSetup
            };
            this.sitedir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.srdl    = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            var ratioScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri);

            this.srdl.Scale.Add(ratioScale);
            testParamType.PossibleScale.Add(ratioScale);
            this.srdl.ParameterType.Add(testParamType);
            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };

            this.model.EngineeringModelSetup.RequiredRdl.Add(mrdl);
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);

            this.model.Iteration.Add(this.iteration);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);
            this.session.Setup(x => x.ActivePerson).Returns(testPerson);

            this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));

            this.elementDefinitionClone = elementDefinition.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.elementDefinitionClone);

            this.integerScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri)
            {
                NumberSet = NumberSetKind.INTEGER_NUMBER_SET,
                MaximumPermissibleValue = "5",
                MinimumPermissibleValue = "0"
            };

            this.realScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri)
            {
                MaximumPermissibleValue = "50",
                MinimumPermissibleValue = "0",
                NumberSet = NumberSetKind.REAL_NUMBER_SET
            };

            this.simpleQt = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri);
            this.simpleQt.PossibleScale.Add(this.integerScale);
            this.simpleQt.PossibleScale.Add(this.realScale);

            this.cptPt = new CompoundParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.c1    = new ParameterTypeComponent(Guid.NewGuid(), this.cache, this.uri)
            {
                ParameterType = this.simpleQt, Scale = this.integerScale
            };
            this.cptPt.Component.Add(this.c1);

            this.srdl.Scale.Add(this.integerScale);
            this.srdl.Scale.Add(this.realScale);

            this.srdl.ParameterType.Add(this.cptPt);
            this.srdl.ParameterType.Add(this.simpleQt);

            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());
        }
示例#11
0
        /// <summary>
        /// Convert a parameter value and scale.
        /// </summary>
        /// <param name="elementDefinitionShortName"> The element definition user friendly short name </param>
        /// <param name="parameterClone"> The parameter clone </param>
        /// <param name="oldScale"> The old scale. </param>
        /// <param name="newScale"> The new scale. </param>
        /// <param name="conversionFactor">the conversion factor in <see cref="double" /></param>
        private void ConvertParameterValueAndScale(string elementDefinitionShortName, Parameter parameterClone, string oldScale, MeasurementScale newScale, double conversionFactor)
        {
            var ownerShortName = parameterClone.Owner.ShortName;
            var errorCount     = 0;

            foreach (var thingClone in parameterClone.ValueSet.Select(p => p.Clone(true)))
            {
                this.sessionService.Transactions.Add(new ThingTransaction(TransactionContextResolver.ResolveContext(thingClone), thingClone));

                if (thingClone.Computed.Count == 1 && errorCount == 0)
                {
                    var oldValue = thingClone.Computed[0];
                    thingClone.Computed[0] = this.ConvertNumericValue(oldValue, conversionFactor, ref errorCount);
                    this.OutputReport(elementDefinitionShortName, parameterClone.UserFriendlyShortName, oldScale, newScale, ownerShortName, oldValue, thingClone.Computed[0], errorCount == 0);
                }

                if (thingClone.Manual.Count == 1 && errorCount == 0)
                {
                    var oldValue = thingClone.Manual[0];
                    thingClone.Manual[0] = this.ConvertNumericValue(oldValue, conversionFactor, ref errorCount);
                    this.OutputReport(elementDefinitionShortName, parameterClone.UserFriendlyShortName, oldScale, newScale, ownerShortName, oldValue, thingClone.Manual[0], errorCount == 0);
                }

                if (thingClone.Reference.Count == 1 && errorCount == 0)
                {
                    var oldValue = thingClone.Reference[0];
                    thingClone.Reference[0] = this.ConvertNumericValue(oldValue, conversionFactor, ref errorCount);
                    this.OutputReport(elementDefinitionShortName, parameterClone.UserFriendlyShortName, oldScale, newScale, ownerShortName, oldValue, thingClone.Reference[0], errorCount == 0);
                }

                this.sessionService.Transactions.Last().CreateOrUpdate(thingClone);
            }

            foreach (var thingClone in parameterClone.ParameterSubscription.SelectMany(p => p.ValueSet.Select(v => v.Clone(true))))
            {
                var subscriber = (thingClone.Container as ParameterSubscription)?.Owner.ShortName;
                this.sessionService.Transactions.Add(new ThingTransaction(TransactionContextResolver.ResolveContext(thingClone), thingClone));

                if (thingClone.Computed.Count == 1 && errorCount == 0)
                {
                    var oldValue = thingClone.Computed[0];
                    thingClone.Computed[0] = this.ConvertNumericValue(oldValue, conversionFactor, ref errorCount);
                    this.OutputReport(elementDefinitionShortName, parameterClone.UserFriendlyShortName, oldScale, newScale, subscriber, oldValue, thingClone.Computed[0], errorCount == 0, true);
                }

                if (thingClone.Manual.Count == 1 && errorCount == 0)
                {
                    var oldValue = thingClone.Manual[0];
                    thingClone.Manual[0] = this.ConvertNumericValue(oldValue, conversionFactor, ref errorCount);
                    this.OutputReport(elementDefinitionShortName, parameterClone.UserFriendlyShortName, oldScale, newScale, subscriber, oldValue, thingClone.Manual[0], errorCount == 0, true);
                }

                if (thingClone.Reference.Count == 1 && errorCount == 0)
                {
                    var oldValue = thingClone.Reference[0];
                    thingClone.Reference[0] = this.ConvertNumericValue(oldValue, conversionFactor, ref errorCount);
                    this.OutputReport(elementDefinitionShortName, parameterClone.UserFriendlyShortName, oldScale, newScale, subscriber, oldValue, thingClone.Reference[0], errorCount == 0, true);
                }

                this.sessionService.Transactions.Last().CreateOrUpdate(thingClone);
            }

            if (errorCount == 0)
            {
                var transaction = new ThingTransaction(TransactionContextResolver.ResolveContext(parameterClone), parameterClone);
                parameterClone.Scale = newScale;
                transaction.CreateOrUpdate(parameterClone);
                this.sessionService.Transactions.Add(transaction);
            }
        }
        public void Setup()
        {
            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();

            this.uri     = new Uri("http://test.com");
            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, this.uri);
            this.domain  = new DomainOfExpertise(Guid.NewGuid(), null, this.uri);
            this.siteDir.Domain.Add(this.domain);
            this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), null, this.uri);
            this.modelsetup.ActiveDomain.Add(this.domain);
            this.mrdl1 = new ModelReferenceDataLibrary(Guid.NewGuid(), null, this.uri);
            this.modelsetup.RequiredRdl.Add(this.mrdl1);

            this.reqSpec  = new RequirementsSpecification(Guid.NewGuid(), null, this.uri);
            this.reqGroup = new RequirementsGroup(Guid.NewGuid(), null, this.uri);

            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), null, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), null, this.uri);
            this.requirementsSpecification = new RequirementsSpecification(Guid.NewGuid(), null, this.uri);
            this.engineeringModelSetup     = new EngineeringModelSetup(Guid.NewGuid(), null, this.uri);

            this.mrdl2 = new ModelReferenceDataLibrary(Guid.NewGuid(), null, this.uri);
            this.engineeringModelSetup.RequiredRdl.Add(this.mrdl2);

            this.iterationSetup           = new IterationSetup(Guid.NewGuid(), null, this.uri);
            this.iteration.IterationSetup = this.iterationSetup;

            var person = new Person(Guid.NewGuid(), null, this.uri);

            this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), null, this.uri)
            {
                Name = "test"
            };
            person.DefaultDomain = this.domainOfExpertise;

            this.engineeringModelSetup.ActiveDomain.Add(this.domainOfExpertise);
            this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.ActivePerson).Returns(person);
            this.siteDir.Domain.Add(this.domainOfExpertise);

            this.engineeringModel.Iteration.Add(this.iteration);
            this.iteration.RequirementsSpecification.Add(this.requirementsSpecification);
            this.iteration.RequirementsSpecification.Add(this.reqSpec);
            this.requirementsSpecification.Group.Add(this.reqGroup);

            this.engineeringModel.EngineeringModelSetup = this.engineeringModelSetup;

            var transactionContext = TransactionContextResolver.ResolveContext(this.engineeringModel);

            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());
        }
示例#13
0
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

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

            this.systemDomainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "system", ShortName = "SYS"
            };
            this.aocsDomainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "aocs", ShortName = "AOCS"
            };

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

            engineeringModelSetup.ActiveDomain.Add(this.systemDomainOfExpertise);
            engineeringModelSetup.ActiveDomain.Add(this.aocsDomainOfExpertise);

            var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "testRDL", ShortName = "test"
            };
            var category = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "test Category", ShortName = "testCategory"
            };

            category.PermissibleClass.Add(ClassKind.ElementDefinition);
            srdl.DefinedCategory.Add(category);
            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = srdl
            };

            engineeringModelSetup.RequiredRdl.Add(mrdl);
            srdl.DefinedCategory.Add(new Category(Guid.NewGuid(), this.cache, this.uri));
            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.engineeringModel.EngineeringModelSetup = engineeringModelSetup;
            var iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);

            this.engineeringModel.Iteration.Add(iteration);
            this.ruleVerificationList = new RuleVerificationList(Guid.NewGuid(), this.cache, this.uri);
            iteration.RuleVerificationList.Add(this.ruleVerificationList);

            this.cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration));
            this.iterationClone = iteration.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.iterationClone);

            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());
        }
示例#14
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.dialogService = new Mock <IThingDialogNavigationService>();

            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            var person = new Person(Guid.NewGuid(), null, null)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null);
            this.siteDir.Person.Add(person);
            this.genericSiteReferenceDataLibrary = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null)
            {
                Name = "Generic RDL", ShortName = "GENRDL"
            };
            this.siteDir.SiteReferenceDataLibrary.Add(this.genericSiteReferenceDataLibrary);

            var kiloPrefix = new UnitPrefix(Guid.NewGuid(), null, null)
            {
                ShortName = "k", Name = "kilo"
            };

            this.genericSiteReferenceDataLibrary.UnitPrefix.Add(kiloPrefix);
            var miliPrefix = new UnitPrefix(Guid.NewGuid(), null, null)
            {
                ShortName = "m", Name = "milli"
            };

            this.genericSiteReferenceDataLibrary.UnitPrefix.Add(miliPrefix);

            var simpleUnit = new SimpleUnit(Guid.NewGuid(), null, null)
            {
                Name = "gram", ShortName = "g"
            };

            this.genericSiteReferenceDataLibrary.Unit.Add(simpleUnit);
            var siteRdl1    = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null);
            var centiPrefix = new UnitPrefix(Guid.NewGuid(), null, null)
            {
                ShortName = "c", Name = "centi"
            };

            siteRdl1.UnitPrefix.Add(centiPrefix);
            this.siteDir.SiteReferenceDataLibrary.Add(siteRdl1);
            this.genericSiteReferenceDataLibrary.RequiredRdl = siteRdl1;

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, null);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary));

            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());
        }
示例#15
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache             = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            this.permissionService = new Mock <IPermissionService>();
            this.session           = new Mock <ISession>();
            this.model             = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.modelSetup        = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "model"
            };
            this.iteration      = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.resSpec        = new RequirementsSpecification();
            this.group1         = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri);
            this.req1           = new Requirement(Guid.NewGuid(), this.cache, this.uri);

            this.dialogNavigation = new Mock <IThingDialogNavigationService>();
            this.serviceLocator   = new Mock <IServiceLocator>();

            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>())
            .Returns(this.dialogNavigation.Object);

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "test"
            };
            this.req1.Owner    = this.domain;
            this.group1.Owner  = this.domain;
            this.resSpec.Owner = this.domain;

            this.resSpec.Group.Add(this.group1);
            this.resSpec.Requirement.Add(this.req1);

            this.iteration.IterationSetup    = this.iterationSetup;
            this.model.EngineeringModelSetup = this.modelSetup;
            this.model.Iteration.Add(this.iteration);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, null);
            this.siteDir.Domain.Add(this.domain);
            var person = new Person(Guid.NewGuid(), this.cache, null)
            {
                DefaultDomain = this.domain
            };

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.ActivePerson).Returns(person);

            this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));
            var clone = this.iteration.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.transaction = new ThingTransaction(transactionContext, clone);

            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());
            this.modelSetup.ActiveDomain.Add(this.domain);
            this.viewmodel = new RequirementsSpecificationDialogViewModel(this.resSpec, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);
        }
示例#16
0
        public void Setup()
        {
            this.uri = new Uri("http://www.rheagroup.com");
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.cache             = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            var testDomain   = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri);
            var subscription = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri);

            subscription.Owner = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "Other Domain"
            };
            var paramValueSet = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri);

            paramValueSet.Computed    = new ValueArray <string>(new[] { "c" });
            paramValueSet.Manual      = new ValueArray <string>(new[] { "m" });
            paramValueSet.Reference   = new ValueArray <string>(new[] { "r" });
            paramValueSet.ValueSwitch = ParameterSwitchKind.COMPUTED;

            var paramSubscriptionValueSet = new ParameterSubscriptionValueSet(Guid.NewGuid(), this.cache, this.uri);

            paramSubscriptionValueSet.Manual             = new ValueArray <string>(new[] { "m1" });
            paramSubscriptionValueSet.ValueSwitch        = ParameterSwitchKind.REFERENCE;
            paramSubscriptionValueSet.SubscribedValueSet = paramValueSet;

            var testParamType = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri);

            this.parameter = new Parameter {
                Owner = testDomain, ParameterType = testParamType
            };
            this.parameter.ValueSet.Add(paramValueSet);
            var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);

            elementDefinition.Parameter.Add(this.parameter);
            this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            var option1 = new Option(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "opt1"
            };
            var option2 = new Option(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "opt2"
            };

            this.iteration.Option.Add(option1);
            this.iteration.Option.Add(option2);
            this.iteration.Element.Add(elementDefinition);
            var actualFiniteStateList = new ActualFiniteStateList(Guid.NewGuid(), this.cache, this.uri);

            actualFiniteStateList.ActualState.Add(new ActualFiniteState(Guid.NewGuid(), this.cache, this.uri));
            actualFiniteStateList.ActualState.Add(new ActualFiniteState(Guid.NewGuid(), this.cache, this.uri));
            this.iteration.ActualFiniteStateList.Add(actualFiniteStateList);
            var modelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);

            modelSetup.ActiveDomain.Add(testDomain);
            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup = modelSetup
            };
            this.sitedir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.srdl    = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.srdl.Scale.Add(new RatioScale(Guid.NewGuid(), this.cache, this.uri));
            this.srdl.ParameterType.Add(testParamType);
            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };

            this.model.EngineeringModelSetup.RequiredRdl.Add(mrdl);
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            var testPerson      = new Person(Guid.NewGuid(), null, null);
            var testParticipant = new Participant(Guid.NewGuid(), null, null)
            {
                Person = testPerson, SelectedDomain = testDomain
            };

            modelSetup.Participant.Add(testParticipant);
            this.parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri)
            {
                Container = this.parameter
            };
            this.parameterSubscription.ValueSet.Add(paramSubscriptionValueSet);
            var elementUsage = new ElementUsage(Guid.NewGuid(), this.cache, this.uri);

            elementDefinition.ContainedElement.Add(elementUsage);
            elementUsage.ElementDefinition = elementDefinition;
            this.model.Iteration.Add(this.iteration);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);
            this.session.Setup(x => x.ActivePerson).Returns(testPerson);
            this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));
            this.parameterSubscription.Owner = subscription.Owner;

            var pt = new TextParameterType();

            this.parameter.ParameterType = pt;
            this.parameter.ParameterSubscription.Add(this.parameterSubscription);

            this.parameterClone = this.parameter.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.parameterClone);

            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());
        }
示例#17
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.serviceLocator       = new Mock <IServiceLocator>();
            this.navigation           = new Mock <IThingDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>()).Returns(this.navigation.Object);
            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.session = new Mock <ISession>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            var person = new Person(Guid.NewGuid(), null, null)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);

            var simpleUnit = new SimpleUnit(Guid.NewGuid(), null, null);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null);
            this.siteDir.Person.Add(person);
            var testScale = new LogarithmicScale();

            this.rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null)
            {
                Name = "testRDL", ShortName = "test"
            };
            this.rdl.Unit.Add(simpleUnit);
            this.rdl.Scale.Add(testScale);
            var svd1 = new ScaleValueDefinition(Guid.NewGuid(), null, null)
            {
                Name = "ReferenceSVD", ShortName = "RSVD"
            };
            var svd2 = new ScaleValueDefinition(Guid.NewGuid(), null, null)
            {
                Name = "DependentSVD", ShortName = "DSVD"
            };

            this.ordinalScale = new OrdinalScale(Guid.NewGuid(), null, null)
            {
                Name = "ordinalScale", ShortName = "dqk"
            };
            this.ordinalScale.ValueDefinition.Add(svd1);
            this.ordinalScale.ValueDefinition.Add(svd2);
            this.rdl.ParameterType.Add(new SimpleQuantityKind {
                Name = "testSQK", ShortName = "tSQK"
            });
            this.siteDir.SiteReferenceDataLibrary.Add(this.rdl);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, null);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary));

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

            this.viewmodel = new OrdinalScaleDialogViewModel(this.ordinalScale, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object);
        }
 /// <summary>
 /// Create the transaction and update the owner
 /// </summary>
 /// <param name="thingClone">the <see cref="Thing" /> cloned to make the change of owner on</param>
 /// <param name="newOwner">the <see cref="DomainOfExpertise" /> to set as new owner of the <see cref="Thing" /> cloned</param>
 private void MakeTheChangeOfOwnerOnThing(Thing thingClone, DomainOfExpertise newOwner)
 {
     this.sessionService.Transactions.Add(new ThingTransaction(TransactionContextResolver.ResolveContext(thingClone), thingClone));
     ((IOwnedThing)thingClone).Owner = newOwner;
     this.sessionService.Transactions.Last().CreateOrUpdate(thingClone);
 }
示例#19
0
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

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

            this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "system", ShortName = "SYS"
            };

            this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri);
            this.participant.Domain.Add(this.domainOfExpertise);

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

            engineeringModelSetup.ActiveDomain.Add(this.domainOfExpertise);
            var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "testRDL", ShortName = "test"
            };
            var category = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "test Category", ShortName = "testCategory"
            };

            category.PermissibleClass.Add(ClassKind.ElementDefinition);
            srdl.DefinedCategory.Add(category);
            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = srdl
            };

            engineeringModelSetup.RequiredRdl.Add(mrdl);
            srdl.DefinedCategory.Add(new Category(Guid.NewGuid(), this.cache, this.uri));
            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.engineeringModel.EngineeringModelSetup = engineeringModelSetup;
            var iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri)
            {
                IterationSetup = new IterationSetup()
            };

            this.engineeringModel.Iteration.Add(iteration);
            this.folder          = new Folder(Guid.NewGuid(), this.cache, this.uri);
            this.domainFileStore = new DomainFileStore(Guid.NewGuid(), this.cache, this.uri);
            this.domainFileStore.Folder.Add(this.folder);
            iteration.DomainFileStore.Add(this.domainFileStore);

            this.cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration));

            this.domainFileStoreClone = this.domainFileStore.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.domainFileStore);

            this.thingTransaction = new ThingTransaction(transactionContext, this.domainFileStoreClone);

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

            var openIterations = new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >();

            openIterations.Add(iteration, new Tuple <DomainOfExpertise, Participant>(this.domainOfExpertise, this.participant));

            this.session.Setup(x => x.OpenIterations).Returns(openIterations);
            this.session.Setup(x => x.QuerySelectedDomainOfExpertise(It.IsAny <Iteration>())).Returns(this.domainOfExpertise);

            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
        public void Setup()
        {
            this.session                      = new Mock <ISession>();
            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.domain  = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri);
            this.siteDir.Domain.Add(this.domain);

            this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            this.modelsetup.ActiveDomain.Add(this.domain);
            this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.siteDir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationsetup);
            this.siteDir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);

            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri)
            {
                IterationSetup = this.iterationsetup
            };
            this.requirement = new Requirement(Guid.NewGuid(), this.cache, this.uri);
            var paramValue = new SimpleParameterValue(Guid.NewGuid(), this.cache, this.uri)
            {
                Scale = new CyclicRatioScale {
                    Name = "s", ShortName = "s"
                },
                ParameterType = new BooleanParameterType {
                    Name = "a", ShortName = "a"
                }
            };

            paramValue.Value         = new ValueArray <string>();
            paramValue.ParameterType = new DateParameterType(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "testParameterType", ShortName = "tpt"
            };
            this.requirement.ParameterValue.Add(paramValue);
            var textParameterType    = new TextParameterType(Guid.NewGuid(), this.cache, this.uri);
            var parametricConstraint = new ParametricConstraint(Guid.NewGuid(), this.cache, this.uri);
            var relationalExpression = new RelationalExpression(Guid.NewGuid(), this.cache, this.uri)
            {
                ParameterType = textParameterType, RelationalOperator = RelationalOperatorKind.EQ, Value = new ValueArray <string>()
            };

            parametricConstraint.Expression.Add(relationalExpression);
            parametricConstraint.TopExpression = relationalExpression;
            this.requirement.ParametricConstraint.Add(parametricConstraint);
            this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Requirement.Add(this.requirement);
            this.grp = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Group.Add(this.grp);
            this.cache.TryAdd(new CacheKey(this.reqSpec.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.reqSpec));

            this.model.Iteration.Add(this.iteration);
            this.iteration.RequirementsSpecification.Add(this.reqSpec);

            this.cat1 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.cat1.PermissibleClass.Add(ClassKind.Requirement);
            this.srdl.DefinedCategory.Add(this.cat1);

            this.cat2 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.srdl.DefinedCategory.Add(this.cat2);

            var person = new Person(Guid.NewGuid(), null, this.uri);

            this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), null, this.uri)
            {
                Name = "test"
            };
            person.DefaultDomain = this.domainOfExpertise;

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.ActivePerson).Returns(person);
            this.siteDir.Domain.Add(this.domainOfExpertise);

            this.modelsetup.ActiveDomain.Add(this.domainOfExpertise);

            this.clone = this.reqSpec.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.clone);

            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

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

            var openIterations = new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >();
            var participant    = new Participant(Guid.NewGuid(), this.cache, this.uri)
            {
                Person = person,
                Domain = new List <DomainOfExpertise>()
                {
                    this.domain
                },
                SelectedDomain = this.domain
            };

            openIterations.Add(this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, participant));
            this.session.Setup(x => x.OpenIterations).Returns(openIterations);
        }
示例#21
0
        public void VerifyThatSuperCategoriesAreCorrectlyPopulated()
        {
            var sRdl10 = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            var cat10  = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "10"
            };
            var cat11 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "11"
            };

            sRdl10.DefinedCategory.Add(cat10);
            sRdl10.DefinedCategory.Add(cat11);

            var sRdl20 = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);

            sRdl20.RequiredRdl = sRdl10;
            var cat20 = new Category(Guid.NewGuid(), this.cache, null)
            {
                ShortName = "20"
            };
            var cat21 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "21"
            };

            sRdl20.DefinedCategory.Add(cat20);
            sRdl20.DefinedCategory.Add(cat21);

            var mRdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);

            mRdl.RequiredRdl = sRdl20;
            var cat30 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "30"
            };
            var cat32 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "32"
            };
            var cat31 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "31"
            };
            var cat311 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "311"
            };
            var cat3111 = new Category(Guid.NewGuid(), null, this.uri)
            {
                ShortName = "3111"
            };
            var cat312 = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "312"
            };

            mRdl.DefinedCategory.Add(cat30);
            mRdl.DefinedCategory.Add(cat31);
            mRdl.DefinedCategory.Add(cat32);
            mRdl.DefinedCategory.Add(cat311);
            mRdl.DefinedCategory.Add(cat3111);
            mRdl.DefinedCategory.Add(cat312);

            cat3111.SuperCategory.Add(cat311);
            cat3111.SuperCategory.Add(cat312);

            cat311.SuperCategory.Add(cat31);
            cat312.SuperCategory.Add(cat31);

            cat31.SuperCategory.Add(cat20);
            cat20.SuperCategory.Add(cat10);

            var sitedir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);

            sitedir.SiteReferenceDataLibrary.Add(sRdl10);
            sitedir.SiteReferenceDataLibrary.Add(sRdl20);
            var model = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);

            model.RequiredRdl.Add(mRdl);
            sitedir.Model.Add(model);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(sitedir);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(sitedir.SiteReferenceDataLibrary)
            {
                mRdl
            });
            var vm        = new CategoryDialogViewModel(cat3111, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, null, null);
            var container = vm.PossibleContainer.SingleOrDefault(x => x.Iid == mRdl.Iid);

            vm.Container = container;
            Assert.AreEqual(9, vm.PossibleSuperCategories.Count);

            this.cache.TryAdd(new CacheKey(mRdl.Iid, null), new Lazy <Thing>(() => mRdl));
            this.cache.TryAdd(new CacheKey(cat31.Iid, null), new Lazy <Thing>(() => cat31));
            var clonerdl = mRdl.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(sitedir);

            this.transaction = new ThingTransaction(transactionContext, clonerdl);

            vm = new CategoryDialogViewModel(cat31.Clone(false), this.transaction, this.session.Object, true, ThingDialogKind.Update, null, clonerdl);
            Assert.AreEqual(10, vm.PossibleSuperCategories.Count);
        }
        public async Task <bool> PackData(string migrationFile)
        {
            List <string> extensionFiles = null;
            var           zipCredentials = new Credentials(this.SourceSession.Credentials.UserName, this.TargetSession.Credentials.Password, new Uri(ArchiveFileName));
            var           zipSession     = new Session(this.Dal, zipCredentials);
            var           success        = true;

            if (!string.IsNullOrEmpty(migrationFile))
            {
                if (!System.IO.File.Exists(migrationFile))
                {
                    this.NotifyMessage("Unable to find selected migration file.", LogVerbosity.Warn);

                    return(false);
                }

                try
                {
                    extensionFiles = new List <string> {
                        MigrationFileName
                    };
                    if (System.IO.File.Exists(MigrationFileName))
                    {
                        System.IO.File.Delete(MigrationFileName);
                    }
                    System.IO.File.Copy(migrationFile, MigrationFileName);
                }
                catch (Exception ex)
                {
                    this.NotifyMessage("Could not add migration.json file.", LogVerbosity.Error, ex);

                    return(false);
                }
            }

            this.NotifyStep(MigrationStep.PackStart);

            var operationContainers = new List <OperationContainer>();
            var openIterations      = this.SourceSession.OpenIterations.Select(i => i.Key);

            foreach (var iteration in openIterations)
            {
                var transactionContext = TransactionContextResolver.ResolveContext(iteration);
                var operationContainer = new OperationContainer(transactionContext.ContextRoute());
                var dto       = iteration.ToDto();
                var operation = new Operation(null, dto, OperationKind.Create);
                operationContainer.AddOperation(operation);
                operationContainers.Add(operationContainer);
            }

            try
            {
                await this.Dal.Write(operationContainers, extensionFiles);
            }
            catch (Exception ex)
            {
                this.NotifyMessage("Could not pack data.", LogVerbosity.Error, ex);
                success = false;
            }
            finally
            {
                await this.SourceSession.Close();
            }

            this.NotifyStep(MigrationStep.PackEnd);

            return(success);
        }
示例#23
0
        /// <summary>
        /// Subscribe parameters and parameter overrides with given short names for given subscriber.
        /// </summary>
        public void Subscribe()
        {
            var subscriber = this.sessionService.SiteDirectory.Domain.SingleOrDefault(d => d.ShortName == this.commandArguments.DomainOfExpertise);

            if (subscriber == null)
            {
                Console.WriteLine($"Unknown subscriber domain of expertise: \"{this.commandArguments.DomainOfExpertise}\". Subscribe parameters skipped.");
                return;
            }

            if (!this.commandArguments.SelectedParameters.Any())
            {
                Console.WriteLine("No --parameters given. Subscribe parameters skipped.");
                return;
            }

            foreach (var elementDefinition in this.sessionService.Iteration.Element
                     .Where(e => this.filterService.IsFilteredIn(e))
                     .OrderBy(x => x.ShortName))
            {
                // Visit all parameters in the element definitions and take a subscription if requested and not taken already
                foreach (var parameter in elementDefinition.Parameter.OrderBy(x => x.ParameterType.ShortName))
                {
                    // Take subscription on this parameter if no subscription taken already
                    if (!this.commandArguments.SelectedParameters.Contains(parameter.ParameterType.ShortName) ||
                        parameter.Owner.Iid == subscriber.Iid ||
                        parameter.ParameterSubscription.Any(p => p.Owner == this.sessionService.DomainOfExpertise))
                    {
                        continue;
                    }

                    var parameterClone = parameter.Clone(true);

                    this.sessionService.Transactions.Add(new ThingTransaction(TransactionContextResolver.ResolveContext(parameterClone), parameterClone));

                    var parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.sessionService.Cache, this.commandArguments.ServerUri)
                    {
                        Owner = subscriber
                    };

                    this.sessionService.Transactions.Last().Create(parameterSubscription, parameterClone);

                    Console.WriteLine($"Parameter Subscription taken on {parameterSubscription.UserFriendlyShortName}");
                }

                // Visit all parameter overrides in the element usages and take a subscription if requested and not taken already
                foreach (var elementUsage in elementDefinition.ContainedElement.OrderBy(x => x.ShortName))
                {
                    foreach (var parameterOverride in elementUsage.ParameterOverride.OrderBy(x => x.ParameterType.ShortName))
                    {
                        // Take subscription on this parameter override if no subscription is taken already
                        if (this.commandArguments.SelectedParameters.Contains(parameterOverride.ParameterType.ShortName) && parameterOverride.Owner.Iid != subscriber.Iid &&
                            parameterOverride.ParameterSubscription.All(parameterSubscription => parameterSubscription.Owner != subscriber))
                        {
                            var parameterOverrideClone = parameterOverride.Clone(true);
                            this.sessionService.Transactions.Add(new ThingTransaction(TransactionContextResolver.ResolveContext(parameterOverrideClone), parameterOverrideClone));

                            var parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.sessionService.Cache, this.commandArguments.ServerUri)
                            {
                                Owner = subscriber, Container = parameterOverrideClone
                            };

                            this.sessionService.Transactions.Last().Create(parameterSubscription, parameterOverrideClone);
                            Console.WriteLine($"Parameter Override Subscription taken on {parameterSubscription.UserFriendlyShortName}");
                        }
                    }
                }
            }
        }
示例#24
0
        public void VerifyThatExceptionIsThrownWhenModelContainsNoIterations()
        {
            this.engineeringModel.Iteration.Clear();

            Assert.Throws <IncompleteModelException>(() => TransactionContextResolver.ResolveContext(this.book));
        }
        public void VerifyThatActualFiniteStateKindIsUpdatedOnNewDefault()
        {
            var model     = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri);

            var possibleList1 = new PossibleFiniteStateList(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var possibleList2 = new PossibleFiniteStateList(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var possibleList3 = new PossibleFiniteStateList(Guid.NewGuid(), this.assembler.Cache, this.uri);

            var ps11 = new PossibleFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var ps12 = new PossibleFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            var ps21 = new PossibleFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var ps22 = new PossibleFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            var ps31 = new PossibleFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var ps32 = new PossibleFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            possibleList1.PossibleState.Add(ps11);
            possibleList1.PossibleState.Add(ps12);
            possibleList2.PossibleState.Add(ps21);
            possibleList2.PossibleState.Add(ps22);
            possibleList3.PossibleState.Add(ps31);
            possibleList3.PossibleState.Add(ps32);

            var actualList1 = new ActualFiniteStateList(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var actualList2 = new ActualFiniteStateList(Guid.NewGuid(), this.assembler.Cache, this.uri);

            actualList1.PossibleFiniteStateList.Add(possibleList1);
            actualList1.PossibleFiniteStateList.Add(possibleList2);
            var as11 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as11.PossibleState.Add(ps11);
            as11.PossibleState.Add(ps21);
            var as12 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as12.PossibleState.Add(ps11);
            as12.PossibleState.Add(ps22);
            var as13 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as13.PossibleState.Add(ps12);
            as13.PossibleState.Add(ps21);
            var as14 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as14.PossibleState.Add(ps12);
            as14.PossibleState.Add(ps22);

            actualList1.ActualState.Add(as11);
            actualList1.ActualState.Add(as12);
            actualList1.ActualState.Add(as13);
            actualList1.ActualState.Add(as14);

            actualList2.PossibleFiniteStateList.Add(possibleList2);
            actualList2.PossibleFiniteStateList.Add(possibleList3);
            var as21 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as21.PossibleState.Add(ps21);
            as21.PossibleState.Add(ps31);
            var as22 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as22.PossibleState.Add(ps21);
            as22.PossibleState.Add(ps32);
            var as23 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as23.PossibleState.Add(ps22);
            as23.PossibleState.Add(ps31);
            var as24 = new ActualFiniteState(Guid.NewGuid(), this.assembler.Cache, this.uri);

            as24.PossibleState.Add(ps22);
            as24.PossibleState.Add(ps32);

            actualList2.ActualState.Add(as21);
            actualList2.ActualState.Add(as22);
            actualList2.ActualState.Add(as23);
            actualList2.ActualState.Add(as24);

            model.Iteration.Add(iteration);
            iteration.PossibleFiniteStateList.Add(possibleList1);
            iteration.PossibleFiniteStateList.Add(possibleList2);
            iteration.PossibleFiniteStateList.Add(possibleList3);
            iteration.ActualFiniteStateList.Add(actualList1);
            iteration.ActualFiniteStateList.Add(actualList2);

            this.assembler.Cache.TryAdd(new CacheKey(model.Iid, null), new Lazy <Thing>(() => model));
            this.assembler.Cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration));
            this.assembler.Cache.TryAdd(new CacheKey(possibleList1.Iid, iteration.Iid), new Lazy <Thing>(() => possibleList1));
            this.assembler.Cache.TryAdd(new CacheKey(possibleList2.Iid, iteration.Iid), new Lazy <Thing>(() => possibleList2));
            this.assembler.Cache.TryAdd(new CacheKey(possibleList3.Iid, iteration.Iid), new Lazy <Thing>(() => possibleList3));
            this.assembler.Cache.TryAdd(new CacheKey(ps11.Iid, iteration.Iid), new Lazy <Thing>(() => ps11));
            this.assembler.Cache.TryAdd(new CacheKey(ps12.Iid, iteration.Iid), new Lazy <Thing>(() => ps12));
            this.assembler.Cache.TryAdd(new CacheKey(ps21.Iid, iteration.Iid), new Lazy <Thing>(() => ps21));
            this.assembler.Cache.TryAdd(new CacheKey(ps22.Iid, iteration.Iid), new Lazy <Thing>(() => ps22));
            this.assembler.Cache.TryAdd(new CacheKey(ps31.Iid, iteration.Iid), new Lazy <Thing>(() => ps31));
            this.assembler.Cache.TryAdd(new CacheKey(ps32.Iid, iteration.Iid), new Lazy <Thing>(() => ps32));
            this.assembler.Cache.TryAdd(new CacheKey(actualList1.Iid, iteration.Iid), new Lazy <Thing>(() => actualList1));
            this.assembler.Cache.TryAdd(new CacheKey(actualList2.Iid, iteration.Iid), new Lazy <Thing>(() => actualList2));
            this.assembler.Cache.TryAdd(new CacheKey(as11.Iid, iteration.Iid), new Lazy <Thing>(() => as11));
            this.assembler.Cache.TryAdd(new CacheKey(as12.Iid, iteration.Iid), new Lazy <Thing>(() => as12));
            this.assembler.Cache.TryAdd(new CacheKey(as13.Iid, iteration.Iid), new Lazy <Thing>(() => as13));
            this.assembler.Cache.TryAdd(new CacheKey(as14.Iid, iteration.Iid), new Lazy <Thing>(() => as14));
            this.assembler.Cache.TryAdd(new CacheKey(as21.Iid, iteration.Iid), new Lazy <Thing>(() => as21));
            this.assembler.Cache.TryAdd(new CacheKey(as22.Iid, iteration.Iid), new Lazy <Thing>(() => as22));
            this.assembler.Cache.TryAdd(new CacheKey(as23.Iid, iteration.Iid), new Lazy <Thing>(() => as23));
            this.assembler.Cache.TryAdd(new CacheKey(as24.Iid, iteration.Iid), new Lazy <Thing>(() => as24));

            possibleList1.DefaultState = ps11;
            as11.Kind = ActualFiniteStateKind.FORBIDDEN;

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

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

            var original = possibleList2.ToDto();
            var modify   = (CDP4Common.DTO.PossibleFiniteStateList)possibleList2.ToDto();

            modify.DefaultState = ps21.Iid;

            operationContainer.AddOperation(new Operation(original, modify, OperationKind.Update));

            Assert.AreEqual(1, operationContainer.Operations.Count());

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

            modifier.ModifyOperationContainer(operationContainer);

            Assert.AreEqual(2, operationContainer.Operations.Count());
            var addedOperation      = operationContainer.Operations.Last();
            var originalActualState = (CDP4Common.DTO.ActualFiniteState)addedOperation.OriginalThing;
            var modifiedActualState = (CDP4Common.DTO.ActualFiniteState)addedOperation.ModifiedThing;

            Assert.AreEqual(as11.Iid, originalActualState.Iid);
            Assert.AreEqual(ActualFiniteStateKind.MANDATORY, modifiedActualState.Kind);
            Assert.AreEqual(ActualFiniteStateKind.FORBIDDEN, originalActualState.Kind);
        }
        public void VerifyThatParameterGroupsAreAcyclic()
        {
            var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "ElemDef", ShortName = "ED"
            };

            this.testIteration.Element.Add(elementDefinition);
            var pg1 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "1"
            };

            elementDefinition.ParameterGroup.Add(pg1);
            var pg2 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "2", ContainingGroup = pg1
            };

            elementDefinition.ParameterGroup.Add(pg2);
            var pg3 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "3", ContainingGroup = pg2
            };

            elementDefinition.ParameterGroup.Add(pg3);
            var pg4 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "4", ContainingGroup = pg3
            };

            elementDefinition.ParameterGroup.Add(pg4);
            var pg5 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "5"
            };

            elementDefinition.ParameterGroup.Add(pg5);
            var pg6 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "6", ContainingGroup = pg5
            };

            elementDefinition.ParameterGroup.Add(pg6);
            this.cache.TryAdd(new CacheKey(elementDefinition.Iid, this.testIteration.Iid), new Lazy <Thing>(() => elementDefinition));

            var clone = elementDefinition.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.testIteration);

            this.transaction = new ThingTransaction(transactionContext, clone);

            var vm1 = new ParameterGroupDialogViewModel(pg1, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);

            Assert.AreEqual(2, vm1.PossibleGroups.Count);

            var vm2 = new ParameterGroupDialogViewModel(pg2, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);

            Assert.AreEqual(3, vm2.PossibleGroups.Count);

            var vm3 = new ParameterGroupDialogViewModel(pg3, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);

            Assert.AreEqual(4, vm3.PossibleGroups.Count);
        }
        public void Setup()
        {
            this.session                      = new Mock <ISession>();
            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.siteDir    = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.domain1    = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri);
            this.srdl       = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            this.mrdl       = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.cat1 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.cat1.PermissibleClass.Add(ClassKind.ElementUsage);
            this.cat2 = new Category(Guid.NewGuid(), this.cache, this.uri);

            this.siteDir.SiteReferenceDataLibrary.Add(this.srdl);
            this.siteDir.Model.Add(this.modelsetup);
            this.siteDir.Domain.Add(this.domain1);
            this.modelsetup.RequiredRdl.Add(this.mrdl);
            this.mrdl.DefinedCategory.Add(this.cat2);
            this.srdl.DefinedCategory.Add(this.cat1);
            this.modelsetup.ActiveDomain.Add(this.domain1);

            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration   = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            this.option      = new Option(Guid.NewGuid(), this.cache, this.uri);
            this.definition1 = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);
            this.definition2 = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);

            this.usage = new ElementUsage(Guid.NewGuid(), this.cache, this.uri)
            {
                ElementDefinition = this.definition2
            };

            this.model.Iteration.Add(this.iteration);
            this.iteration.Option.Add(this.option);
            this.iteration.Element.Add(this.definition1);
            this.iteration.Element.Add(this.definition2);

            this.definition1.ContainedElement.Add(this.usage);

            this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));
            this.cache.TryAdd(new CacheKey(this.definition1.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.definition1));
            this.cache.TryAdd(new CacheKey(this.usage.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.usage));

            this.usageClone       = this.usage.Clone(false);
            this.definition1Clone = this.definition1.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.definition1Clone);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);

            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()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

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

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

            var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "testRDL", ShortName = "test"
            };

            this.binaryRelationshipRule = new BinaryRelationshipRule(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "binary", ShortName = "binary"
            };
            srdl.Rule.Add(this.binaryRelationshipRule);

            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = srdl
            };

            mrdl.RequiredRdl = srdl;
            engineeringModelSetup.RequiredRdl.Add(mrdl);
            this.decompositionRule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "decomposition", ShortName = "decomposition"
            };
            mrdl.Rule.Add(this.decompositionRule);

            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.iterationSetup           = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.iteration.IterationSetup = this.iterationSetup;

            this.engineeringModel.Iteration.Add(iteration);

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

            iteration.RuleVerificationList.Add(this.ruleVerificationList);
            this.userRuleVerification = new UserRuleVerification(Guid.NewGuid(), this.cache, this.uri)
            {
                Rule = this.binaryRelationshipRule
            };


            this.ruleVerificationList.RuleVerification.Add(this.userRuleVerification);

            this.cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration));

            var chainOfRdls = new List <ReferenceDataLibrary>();

            chainOfRdls.Add(mrdl);
            chainOfRdls.Add(srdl);

            this.session.Setup(x => x.GetEngineeringModelRdlChain(It.IsAny <EngineeringModel>())).Returns(chainOfRdls);

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