Пример #1
0
        /// <summary>
        /// Populates the <see cref="ElementUsageRowViewModel"/>
        /// </summary>
        private void PopulateElemenUsages()
        {
            var currentUsages = this.ContainedRows.OfType <ElementUsageRowViewModel>().Select(x => x.Thing).ToList();

            var deletedUsages = currentUsages.Except(this.Thing.ContainedElement).ToList();

            foreach (var deletedUsage in deletedUsages)
            {
                var row = this.ContainedRows.OfType <ElementUsageRowViewModel>().SingleOrDefault(x => x.Thing == deletedUsage);
                if (row == null)
                {
                    continue;
                }

                row.Dispose();
                this.ContainedRows.Remove(row);
            }

            var addedUsages = this.Thing.ContainedElement.Except(currentUsages).ToList();

            foreach (var elementUsage in addedUsages)
            {
                var row = new ElementUsageRowViewModel(elementUsage, this.currentDomain, this.Session, this);
                this.ContainedRows.SortedInsert(row, ChildRowComparer);
            }
        }
        public void VerifyCreateParameterOverride()
        {
            var browser      = new ElementDefinitionsBrowserViewModel(this.iteration, this.session.Object, null, this.panelNavigationService.Object, null, null, null, null);
            var elementUsage = new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Owner = this.elementDef.Owner, ElementDefinition = this.elementDef, Container = this.elementDef
            };
            var usageRow  = new ElementUsageRowViewModel(elementUsage, this.elementDef.Owner, this.session.Object, null, this.obfuscationService.Object);
            var qk        = new SimpleQuantityKind();
            var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container     = this.elementDef,
                ParameterType = qk,
                Owner         = this.elementDef.Owner
            };

            var parameterRow = new ParameterRowViewModel(parameter, this.session.Object, usageRow, false);

            Assert.IsFalse(browser.CreateOverrideCommand.CanExecute(null));
            browser.SelectedThing = parameterRow;
            Assert.IsTrue(browser.CreateOverrideCommand.CanExecute(null));
            browser.CreateOverrideCommand.Execute(parameter);

            this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()));

            browser.SelectedThing = null;
            browser.ComputePermission();
            browser.CreateOverrideCommand.Execute(null);
            this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()), Times.Once);

            var paramtType = new CompoundParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri);

            paramtType.Component.Add(new ParameterTypeComponent(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ParameterType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri), Scale = null
            });
            parameter.ParameterType = paramtType;

            var elementDefRow         = new ElementDefinitionRowViewModel(this.elementDef, this.elementDef.Owner, this.session.Object, null, this.obfuscationService.Object);
            var parameterValueBaseRow = new ParameterComponentValueRowViewModel(parameter, 0, this.session.Object, null, null, elementDefRow, false);

            browser.SelectedThing = parameterValueBaseRow;
            browser.ComputePermission();
            browser.CreateOverrideCommand.Execute(null);

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

            parameterValueBaseRow = new ParameterComponentValueRowViewModel(parameterOverride, 0, this.session.Object, null, null, usageRow, false);
            browser.SelectedThing = parameterValueBaseRow;
            browser.CreateOverrideCommand.Execute(null);
        }