public void VerifyExecuteCreateSubscriptionCommand() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); var revisionNumber = typeof(Iteration).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.iteration, 50); var elementdef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Container = this.iteration }; var anotherDomain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "Not owned" }; var boolParamType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri); var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = anotherDomain, Container = elementdef, ParameterType = boolParamType }; var published = new ValueArray <string>(new List <string> { "published" }); var paramValueSet = new ParameterValueSet(Guid.NewGuid(), this.assembler.Cache, this.uri) { Published = published, Manual = published, Computed = published, ValueSwitch = ParameterSwitchKind.COMPUTED }; parameter.ValueSet.Add(paramValueSet); elementdef.Parameter.Add(parameter); this.iteration.TopElement = elementdef; CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated); Assert.AreSame(elementdef, vm.TopElement.Single().Thing); Assert.AreEqual(1, vm.TopElement.Single().ContainedRows.Count); var paramRow = vm.TopElement.Single().ContainedRows.First() as ParameterOrOverrideBaseRowViewModel; Assert.NotNull(paramRow); vm.SelectedThing = paramRow; Assert.IsTrue(vm.CreateSubscriptionCommand.CanExecute(null)); Assert.AreEqual(0, paramRow.Thing.ParameterSubscription.Count); vm.SelectedThing = null; vm.CreateSubscriptionCommand.Execute(null); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()), Times.Never); vm.SelectedThing = vm.TopElement.Single(); vm.CreateSubscriptionCommand.Execute(null); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()), Times.Never); vm.SelectedThing = paramRow; vm.CreateSubscriptionCommand.Execute(null); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()), Times.Exactly(1)); }
public void TestViewLoaded() { var data = new HierarchyNode <ProductTree>() { Entity = new ProductTree { ParentId = 0, Id = 1, PartDescription = "Bin", Notes = "Notes" } }; Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>(); mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().GetProductTree()).Returns(data); ProductTreeViewModel viewModel = new ProductTreeViewModel(mockServiceFactory.Object); Assert.IsTrue(viewModel.ProductTree == null); object loaded = viewModel.ViewLoaded; // fires off the OnViewLoaded protected method Assert.IsTrue(viewModel.ProductTree != null); }
public void VerifyThatActiveDomainIsDisplayed() { this.session.Setup(x => x.OpenIterations).Returns( new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > { { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, null) } }); var vm = new ProductTreeViewModel(this.option, this.session.Object, null, null, null, null); Assert.AreEqual("domain [domainshortname]", vm.DomainOfExpertise); this.session.Setup(x => x.OpenIterations).Returns( new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > { { this.iteration, new Tuple <DomainOfExpertise, Participant>(null, null) } }); vm = new ProductTreeViewModel(this.option, this.session.Object, null, null, null, null); Assert.AreEqual("None", vm.DomainOfExpertise); this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >()); vm = new ProductTreeViewModel(this.option, this.session.Object, null, null, null, null); Assert.AreEqual("None", vm.DomainOfExpertise); }
public void VerifyCreateParameterOverride() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null); var revisionNumber = typeof(Iteration).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.iteration, 50); var elementdef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Container = this.iteration }; var boolParamType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri); var elementUsage = new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri) { Container = elementdef, ElementDefinition = elementdef }; var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = this.domain, Container = elementUsage, ParameterType = boolParamType }; elementdef.Parameter.Add(parameter); var published = new ValueArray <string>(new List <string> { "published" }); var paramValueSet = new ParameterValueSet(Guid.NewGuid(), this.assembler.Cache, this.uri) { Published = published, Manual = published, Computed = published, ValueSwitch = ParameterSwitchKind.COMPUTED }; parameter.ValueSet.Add(paramValueSet); var usageRow = new ElementUsageRowViewModel(elementUsage, this.option, this.session.Object, null); var parameterRow = new ParameterRowViewModel(parameter, this.option, this.session.Object, usageRow); this.iteration.TopElement = elementdef; vm.SelectedThing = parameterRow; Assert.IsTrue(vm.CreateOverrideCommand.CanExecute(null)); vm.SelectedThing = null; vm.CreateOverrideCommand.Execute(null); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()), Times.Never); vm.SelectedThing = vm.TopElement.Single(); vm.CreateOverrideCommand.Execute(null); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>()), Times.Never); vm.SelectedThing = parameterRow; vm.CreateOverrideCommand.Execute(parameter); this.session.Verify(x => x.Write(It.IsAny <OperationContainer>())); vm.PopulateContextMenu(); Assert.AreEqual(6, vm.ContextMenu.Count); }
public void VerifyThatDragWorks() { var vm = new ProductTreeViewModel(this.option, this.session.Object, null, this.panelNavigationService.Object, null, null); var draginfo = new Mock <IDragInfo>(); var dragSource = new Mock <IDragSource>(); draginfo.Setup(x => x.Payload).Returns(dragSource.Object); vm.StartDrag(draginfo.Object); dragSource.Verify(x => x.StartDrag(draginfo.Object)); }
public void VerifyThatActiveDomainIsDisplayed() { var vm = new ProductTreeViewModel(this.option, this.session.Object, null, null, null, null); Assert.AreEqual("domain [domainshortname]", vm.DomainOfExpertise); this.domain = null; this.session.Setup(x => x.QuerySelectedDomainOfExpertise(this.iteration)).Returns(this.domain); vm = new ProductTreeViewModel(this.option, this.session.Object, null, null, null, null); Assert.AreEqual("None", vm.DomainOfExpertise); }
public void VerifyThatTopElementIsRemovedUponIterationUpdateWithNoTop() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); var revisionNumber = typeof(Iteration).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.iteration, 50); this.iteration.TopElement = null; CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated); Assert.AreEqual(0, vm.TopElement.Count); }
protected override void OnWireViewModelEvents(ViewModelBase viewModel) { ProductTreeViewModel vm = viewModel as ProductTreeViewModel; if (vm != null) { //vm.ConfirmDelete += OnConfirmDelete; vm.ErrorOccured += OnErrorOccured; vm.OpenEditStockWindow += OnOpenEditStockWindow; vm.OpenEditPartWindow += OnOpenEditPartWindow; } }
public void VerifyThatUpdatePersonEventIsHandled() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); var revisionNumber = typeof(Person).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.person, 50); this.person.GivenName = "Jane"; CDPMessageBus.Current.SendObjectChangeEvent(this.person, EventKind.Updated); Assert.AreEqual("Jane Doe", vm.Person); }
public void VerifyToggleNamesAndShortNames() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null); Assert.IsFalse(vm.IsDisplayShortNamesOn); Assert.IsTrue(vm.ToggleUsageNamesCommand.CanExecute(null)); vm.ToggleUsageNamesCommand.Execute(null); Assert.IsTrue(vm.IsDisplayShortNamesOn); vm.ToggleUsageNamesCommand.Execute(null); Assert.IsFalse(vm.IsDisplayShortNamesOn); Assert.DoesNotThrow(vm.Dispose); }
public void VerifyThatDropsWorkDomain() { var vm = new ProductTreeViewModel(this.option, this.session.Object, null, null, null, null); var dropinfo = new Mock <IDropInfo>(); var droptarget = new Mock <IDropTarget>(); dropinfo.Setup(x => x.TargetItem).Returns(droptarget.Object); droptarget.Setup(x => x.Drop(It.IsAny <IDropInfo>())).Throws(new Exception("ex")); vm.Drop(dropinfo.Object); droptarget.Verify(x => x.Drop(dropinfo.Object)); Assert.AreEqual("ex", vm.Feedback); }
public void VerifyCopyPathToClipboardCommand() { var elementdef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Container = this.iteration, ShortName = "ELEMENT" }; var anotherDomain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "Not owned" }; var boolParamType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri) { ShortName = "PARAM" }; var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = anotherDomain, Container = elementdef, ParameterType = boolParamType }; var published = new ValueArray <string>(new List <string> { "published" }); var paramValueSet = new ParameterValueSet(Guid.NewGuid(), this.assembler.Cache, this.uri) { Published = published, Manual = published, Computed = published, ValueSwitch = ParameterSwitchKind.COMPUTED }; parameter.ValueSet.Add(paramValueSet); elementdef.Parameter.Add(parameter); this.iteration.TopElement = elementdef; var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null); var paramRow = vm.TopElement.Single().ContainedRows.First() as ParameterOrOverrideBaseRowViewModel; Assert.NotNull(paramRow); vm.SelectedThing = paramRow; vm.PopulateContextMenu(); Assert.AreEqual(7, vm.ContextMenu.Count); Clipboard.SetText("Reset"); vm.CopyPathToClipboardCommand.Execute(null); Assert.IsTrue(Clipboard.GetDataObject().GetData(typeof(string)).ToString().Contains($"{this.nestedParameterPath}")); }
public void VerifyThatUpdateOptionEventWorks() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); Assert.AreEqual("option name", vm.CurrentOption); var revisionNumber = typeof(Option).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.option, 50); this.option.Name = "blablabla"; CDPMessageBus.Current.SendObjectChangeEvent(this.option, EventKind.Updated); Assert.AreEqual("blablabla", vm.CurrentOption); }
public void VerifyThatUpdateDomainEventIsHandled() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); var revisionNumber = typeof(DomainOfExpertise).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.domain, 50); this.domain.Name = "System"; this.domain.ShortName = "SYS"; CDPMessageBus.Current.SendObjectChangeEvent(this.domain, EventKind.Updated); Assert.AreEqual("System [SYS]", vm.DomainOfExpertise); }
public void VerifyContextMenuPopulation() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null); Assert.AreEqual(0, vm.ContextMenu.Count); Assert.IsNull(vm.SelectedThing); vm.PopulateContextMenu(); Assert.AreEqual(0, vm.ContextMenu.Count); var elemDef = vm.TopElement.Single(); vm.SelectedThing = elemDef; vm.PopulateContextMenu(); Assert.AreEqual(5, vm.ContextMenu.Count); }
public void VerifyThatTopElementIsModifiedUponNewTopElement() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); var revisionNumber = typeof(Iteration).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.iteration, 50); var elementdef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri); this.iteration.TopElement = elementdef; CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated); Assert.AreSame(elementdef, vm.TopElement.Single().Thing); }
public void VerifyThatPropertiesAreSet() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); Assert.That(vm.Caption, Is.Not.Null.Or.Empty); Assert.That(vm.ToolTip, Is.Not.Null.Or.Empty); Assert.AreEqual("model name", vm.CurrentModel); Assert.AreEqual("option name", vm.CurrentOption); Assert.AreEqual("domain [domainshortname]", vm.DomainOfExpertise); Assert.AreEqual("John Doe", vm.Person); Assert.AreEqual(0, vm.CurrentIteration); Assert.IsNotNull(vm.ActiveParticipant); Assert.AreEqual(1, vm.TopElement.Count); }
public void VerifyThatUpdateIterationSetupEventIsHandled() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); Assert.AreEqual(0, vm.CurrentIteration); var revisionNumber = typeof(IterationSetup).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.iterationSetup, 50); var iterationNumber = typeof(IterationSetup).GetProperty("IterationNumber"); iterationNumber.SetValue(this.iterationSetup, 1); CDPMessageBus.Current.SendObjectChangeEvent(this.iterationSetup, EventKind.Updated); Assert.AreEqual(1, vm.CurrentIteration); }
public void VerifyCreateParameterOverrideIsDisabledForTopElement() { var vm = new ProductTreeViewModel(this.option, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null); var revisionNumber = typeof(Iteration).GetProperty("RevisionNumber"); revisionNumber.SetValue(this.iteration, 50); var elementdef = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri) { Container = this.iteration }; this.iteration.TopElement = elementdef; var boolParamType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri); var parameter = new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri) { Owner = this.domain, Container = elementdef, ParameterType = boolParamType }; elementdef.Parameter.Add(parameter); Assert.IsFalse(vm.CreateOverrideCommand.CanExecute(parameter)); }
/// <summary> /// Show or close the <see cref="ProductTreeViewModel"/> /// </summary> /// <param name="optionId"> /// the unique id of the <see cref="Option"/> that is being represented by the <see cref="ProductTreeViewModel"/> /// </param> private void ShowOrCloseProductTree(string optionId) { // format of tag iterationId_OptionId var iids = optionId.Split('_'); var iterationUniqueId = Guid.Parse(iids[0]); var optionGuid = Guid.Parse(iids[1]); var iteration = this.Iterations.SingleOrDefault(x => x.Iid == iterationUniqueId); if (iteration == null) { return; } var option = iteration.Option.SingleOrDefault(x => x.Iid == optionGuid); if (option == null) { return; } // close the brower if it exists var browser = this.openProductTree.SingleOrDefault(x => x.Thing == option); if (browser != null) { this.PanelNavigationService.Close(browser, false); this.openProductTree.Remove(browser); return; } browser = new ProductTreeViewModel(option, this.Session, this.ThingDialogNavigationService, this.PanelNavigationService, this.DialogNavigationService, this.PluginSettingsService); this.openProductTree.Add(browser); this.PanelNavigationService.Open(browser, false); }