public void VerifyUpdateSelectedScale() { this.viewModel.SelectedThing = null; Assert.DoesNotThrow(() => this.viewModel.UpdateSelectedScale()); this.viewModel.SelectedThing = this.viewModel.Variables.First(); Assert.DoesNotThrow(() => this.viewModel.UpdateSelectedScale()); var ratioScale = new CyclicRatioScale() { Name = "scale2", NumberSet = NumberSetKind.REAL_NUMBER_SET }; this.quantityKindParameterType.DefaultScale = ratioScale; this.quantityKindParameterType.PossibleScale.Add(this.scale); this.quantityKindParameterType.PossibleScale.Add(ratioScale); this.viewModel.SelectedThing.SelectedParameterType = this.quantityKindParameterType; Assert.DoesNotThrow(() => this.viewModel.UpdateSelectedScale()); Assert.AreEqual(ratioScale, this.viewModel.SelectedThing.SelectedScale); this.viewModel.SelectedThing.SelectedParameter = new Parameter() { ParameterType = this.quantityKindParameterType, Scale = this.scale }; Assert.DoesNotThrow(() => this.viewModel.UpdateSelectedScale()); Assert.AreEqual(this.scale, this.viewModel.SelectedThing.SelectedScale); }
public void VerifyThatRdlShortnameIsUpdated() { var vm = new MeasurementScalesBrowserViewModel(this.session.Object, this.siteDirectory, null, null, null, null); var sRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri); sRdl.Container = this.siteDirectory; var cat = new CyclicRatioScale(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "cat1", ShortName = "1", Container = sRdl }; var cat2 = new CyclicRatioScale(Guid.NewGuid(), this.assembler.Cache, this.uri) { Name = "cat2", ShortName = "2", Container = sRdl }; CDPMessageBus.Current.SendObjectChangeEvent(cat, EventKind.Added); CDPMessageBus.Current.SendObjectChangeEvent(cat2, EventKind.Added); var rev = typeof(Thing).GetProperty("RevisionNumber"); rev.SetValue(sRdl, 3); sRdl.ShortName = "test"; CDPMessageBus.Current.SendObjectChangeEvent(sRdl, EventKind.Updated); Assert.IsTrue(vm.MeasurementScales.Count(x => x.ContainerRdl == "test") == 2); }
/// <summary> /// Serialize the <see cref="CyclicRatioScale"/> /// </summary> /// <param name="cyclicRatioScale">The <see cref="CyclicRatioScale"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(CyclicRatioScale cyclicRatioScale) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](cyclicRatioScale.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), cyclicRatioScale.ClassKind))); jsonObject.Add("definition", this.PropertySerializerMap["definition"](cyclicRatioScale.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](cyclicRatioScale.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](cyclicRatioScale.Iid)); jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](cyclicRatioScale.IsDeprecated)); jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](cyclicRatioScale.IsMaximumInclusive)); jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](cyclicRatioScale.IsMinimumInclusive)); jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](cyclicRatioScale.MaximumPermissibleValue)); jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](cyclicRatioScale.MinimumPermissibleValue)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](cyclicRatioScale.ModifiedOn)); jsonObject.Add("modulus", this.PropertySerializerMap["modulus"](cyclicRatioScale.Modulus)); jsonObject.Add("name", this.PropertySerializerMap["name"](cyclicRatioScale.Name)); jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](cyclicRatioScale.NegativeValueConnotation)); jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), cyclicRatioScale.NumberSet))); jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](cyclicRatioScale.PositiveValueConnotation)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](cyclicRatioScale.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](cyclicRatioScale.ShortName)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](cyclicRatioScale.ThingPreference)); jsonObject.Add("unit", this.PropertySerializerMap["unit"](cyclicRatioScale.Unit)); jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); return(jsonObject); }
public void VerifyThatParameterTypeEventsAreCaught() { var textParamType = new TextParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri); CDPMessageBus.Current.SendObjectChangeEvent(textParamType, EventKind.Added); Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count); CDPMessageBus.Current.SendObjectChangeEvent(textParamType, EventKind.Removed); Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any()); var booleanParamType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri); CDPMessageBus.Current.SendObjectChangeEvent(booleanParamType, EventKind.Added); Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count); CDPMessageBus.Current.SendObjectChangeEvent(booleanParamType, EventKind.Removed); Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any()); var defaultScale = new CyclicRatioScale(Guid.NewGuid(), this.assembler.Cache, this.uri); var simpleQuantityKind = new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.uri) { DefaultScale = defaultScale }; CDPMessageBus.Current.SendObjectChangeEvent(simpleQuantityKind, EventKind.Added); Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count); CDPMessageBus.Current.SendObjectChangeEvent(simpleQuantityKind, EventKind.Removed); Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any()); var specializedQuantityKind = new SpecializedQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.uri) { DefaultScale = defaultScale }; CDPMessageBus.Current.SendObjectChangeEvent(specializedQuantityKind, EventKind.Added); Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count); CDPMessageBus.Current.SendObjectChangeEvent(specializedQuantityKind, EventKind.Removed); Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any()); var derivedQuantityKind = new DerivedQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.uri) { DefaultScale = defaultScale }; CDPMessageBus.Current.SendObjectChangeEvent(derivedQuantityKind, EventKind.Added); Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count); CDPMessageBus.Current.SendObjectChangeEvent(derivedQuantityKind, EventKind.Removed); Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any()); }
/// <summary> /// Initializes a new instance of the <see cref="CyclicRatioScaleDialogViewModel"/> class /// </summary> /// <param name="cyclicRatioScale"> /// The <see cref="CyclicRatioScale"/> that is the subject of the current view-model. This is the object /// that will be either created, or edited. /// </param> /// <param name="transaction"> /// The <see cref="ThingTransaction"/> that contains the log of recorded changes. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated /// </param> /// <param name="isRoot"> /// Assert if this <see cref="DialogViewModelBase{T}"/> is the root of all <see cref="DialogViewModelBase{T}"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="DialogViewModelBase{T}"/> performs /// </param> /// <param name="thingDialogNavigationService"> /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>. /// </param> /// <param name="container"> /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog /// </param> /// <param name="chainOfContainers"> /// The optional chain of containers that contains the <paramref name="container"/> argument /// </param> public CyclicRatioScaleDialogViewModel(CyclicRatioScale cyclicRatioScale, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container, IEnumerable <Thing> chainOfContainers) : base(cyclicRatioScale, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { if (container != null) { var containerThing = container as ReferenceDataLibrary; if (containerThing == null) { var errorMessage = string.Format( "The container parameter is of type {0}, it shall be of type ReferenceDataLibrary", container.GetType()); throw new ArgumentException(errorMessage); } } }
/// <summary> /// Persist the DTO composition to the ORM layer. /// </summary> /// <param name="transaction"> /// The transaction object. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="cyclicRatioScale"> /// The cyclicRatioScale instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool CreateContainment(NpgsqlTransaction transaction, string partition, CyclicRatioScale cyclicRatioScale) { var results = new List <bool>(); foreach (var alias in this.ResolveFromRequestCache(cyclicRatioScale.Alias)) { results.Add(this.AliasService.CreateConcept(transaction, partition, alias, cyclicRatioScale)); } foreach (var definition in this.ResolveFromRequestCache(cyclicRatioScale.Definition)) { results.Add(this.DefinitionService.CreateConcept(transaction, partition, definition, cyclicRatioScale)); } foreach (var hyperLink in this.ResolveFromRequestCache(cyclicRatioScale.HyperLink)) { results.Add(this.HyperLinkService.CreateConcept(transaction, partition, hyperLink, cyclicRatioScale)); } foreach (var valueDefinition in this.ResolveFromRequestCache(cyclicRatioScale.ValueDefinition)) { results.Add(this.ScaleValueDefinitionService.CreateConcept(transaction, partition, valueDefinition, cyclicRatioScale)); } foreach (var mappingToReferenceScale in this.ResolveFromRequestCache(cyclicRatioScale.MappingToReferenceScale)) { results.Add(this.MappingToReferenceScaleService.CreateConcept(transaction, partition, mappingToReferenceScale, cyclicRatioScale)); } return(results.All(x => x)); }
/// <summary> /// Initializes a new instance of the <see cref="CyclicRatioScaleDialogViewModel"/> class. /// </summary> /// <param name="cyclicRatioScale"> /// The <see cref="CyclicRatioScale"/>. /// </param> /// <param name="transaction"> /// The <see cref="ThingTransaction"/> that contains the log of recorded changes. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated /// </param> /// <param name="isRoot"> /// Assert if this <see cref="RatioScaleDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/> /// </param> /// <param name="dialogKind"> /// The kind of operation this <see cref="RatioScaleDialogViewModel"/> performs /// </param> /// <param name="thingDialogNavigationService"> /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>. /// </param> /// <param name="container"> /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog /// </param> /// <param name="chainOfContainers"> /// The optional chain of containers that contains the <paramref name="container"/> argument /// </param> /// <exception cref="ArgumentException"> /// The container must be of type <see cref="ReferenceDataLibrary"/>. /// </exception> public CyclicRatioScaleDialogViewModel(CyclicRatioScale cyclicRatioScale, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(cyclicRatioScale, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers) { this.WhenAnyValue(vm => vm.Container).Subscribe(_ => this.PopulatePossibleUnit()); this.WhenAnyValue(vm => vm.SelectedUnit).Subscribe(_ => this.UpdateOkCanExecute()); }
public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.navigation = new Mock <IThingDialogNavigationService>(); 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.cyclicRatioScale = new CyclicRatioScale(Guid.NewGuid(), null, null) { Name = "ratioScale", ShortName = "dqk", Modulus = "modulus" }; this.cyclicRatioScale.ValueDefinition.Add(svd1); this.cyclicRatioScale.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); 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 BasicRdl.ViewModels.CyclicRatioScaleDialogViewModel(this.cyclicRatioScale, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object); }
/// <summary> /// Initializes a new instance of the <see cref="CyclicRatioScaleRowViewModel"/> class /// </summary> /// <param name="cyclicRatioScale">The <see cref="CyclicRatioScale"/> associated with this row</param> /// <param name="session">The session</param> /// <param name="containerViewModel">The <see cref="IViewModelBase"/> that is the container of this <see cref="IRowViewModelBase"/></param> public CyclicRatioScaleRowViewModel(CyclicRatioScale cyclicRatioScale, ISession session, IViewModelBase <Thing> containerViewModel) : base(cyclicRatioScale, session, containerViewModel) { this.UpdateColumnValues(); }