Ejemplo n.º 1
0
        /// <summary>
        /// Serialize the <see cref="LogarithmicScale"/>
        /// </summary>
        /// <param name="logarithmicScale">The <see cref="LogarithmicScale"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(LogarithmicScale logarithmicScale)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](logarithmicScale.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logarithmicScale.ClassKind)));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](logarithmicScale.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logarithmicScale.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logarithmicScale.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](logarithmicScale.Exponent));
            jsonObject.Add("factor", this.PropertySerializerMap["factor"](logarithmicScale.Factor));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](logarithmicScale.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](logarithmicScale.Iid));
            jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](logarithmicScale.IsDeprecated));
            jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](logarithmicScale.IsMaximumInclusive));
            jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](logarithmicScale.IsMinimumInclusive));
            jsonObject.Add("logarithmBase", this.PropertySerializerMap["logarithmBase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.LogarithmBaseKind), logarithmicScale.LogarithmBase)));
            jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](logarithmicScale.MaximumPermissibleValue));
            jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](logarithmicScale.MinimumPermissibleValue));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logarithmicScale.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](logarithmicScale.Name));
            jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](logarithmicScale.NegativeValueConnotation));
            jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), logarithmicScale.NumberSet)));
            jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](logarithmicScale.PositiveValueConnotation));
            jsonObject.Add("referenceQuantityKind", this.PropertySerializerMap["referenceQuantityKind"](logarithmicScale.ReferenceQuantityKind));
            jsonObject.Add("referenceQuantityValue", this.PropertySerializerMap["referenceQuantityValue"](logarithmicScale.ReferenceQuantityValue));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logarithmicScale.RevisionNumber));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](logarithmicScale.ShortName));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logarithmicScale.ThingPreference));
            jsonObject.Add("unit", this.PropertySerializerMap["unit"](logarithmicScale.Unit));
            jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](logarithmicScale.ValueDefinition.OrderBy(x => x, this.guidComparer)));
            return(jsonObject);
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache      = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            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(), 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 testScale = new LogarithmicScale();

            this.rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, null)
            {
                Name = "testRDL", ShortName = "test"
            };
            this.rdl.Scale.Add(testScale);
            var qkf = new QuantityKindFactor();

            this.derivedQuantityKind = new DerivedQuantityKind {
                Name = "derivedQuantityKind", ShortName = "dqk"
            };
            this.derivedQuantityKind.QuantityKindFactor.Add(qkf);
            this.rdl.ParameterType.Add(new SimpleQuantityKind {
                Name = "testSQK", ShortName = "tSQK"
            });
            this.siteDir.SiteReferenceDataLibrary.Add(this.rdl);

            this.cache.TryAdd(new CacheKey(this.rdl.Iid, null), new Lazy <Thing>(() => 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 DerivedQuantityKindDialogViewModel(this.derivedQuantityKind, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object, null);
        }
 public void VerifyInspectSelectedDefaultScale()
 {
     var scale1 = new LogarithmicScale(Guid.NewGuid(), null, null);
     var vm = new SimpleQuantityKindDialogViewModel(this.simpleQuantityKind, this.transaction, this.session.Object, true, ThingDialogKind.Inspect, this.navigation.Object, this.rdl);
     Assert.IsFalse(vm.InspectSelectedScaleCommand.CanExecute(null));
     vm.SelectedDefaultScale = scale1;
     Assert.IsTrue(vm.InspectSelectedScaleCommand.CanExecute(null));
     vm.InspectSelectedScaleCommand.Execute(null);
     this.navigation.Verify(x => x.Navigate(It.IsAny<MeasurementScale>(), It.IsAny<ThingTransaction>(), this.session.Object, false, ThingDialogKind.Inspect, this.navigation.Object, It.IsAny<Thing>(), null));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="LogarithmicScaleDialogViewModel"/> class.
        /// </summary>
        /// <param name="logarithmicScale">
        /// The Simple quantity Kind.
        /// </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="LogarithmicScaleDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
        /// </param>
        /// <param name="dialogKind">
        /// The kind of operation this <see cref="LogarithmicScaleDialogViewModel"/> 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 LogarithmicScaleDialogViewModel(LogarithmicScale logarithmicScale, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
            : base(logarithmicScale, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
        {
            this.WhenAnyValue(vm => vm.Container).Subscribe(_ =>
            {
                this.PopulatePossibleUnit();
                this.PopulatePossibleReferenceQuantityKind();
            });

            this.WhenAnyValue(vm => vm.SelectedUnit).Subscribe(_ => this.UpdateOkCanExecute());
        }
        public void VerifThatUpdatingContainerPopulatesPossiblePossibleScales()
        {
            Assert.IsEmpty(this.viewmodel.PossiblePossibleScale);
            this.viewmodel.Container = null;
            var rdl = this.siteDir.SiteReferenceDataLibrary.First();
            var testScale = new LogarithmicScale();
            rdl.Scale.Add(testScale);

            this.viewmodel.Container = rdl;
            Assert.IsNotEmpty(this.viewmodel.PossiblePossibleScale);
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.cache          = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            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.session = new Mock <ISession>();
            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.scaleReferenceQuantityValue = new ScaleReferenceQuantityValue();
            var testLogarithmicScale = new LogarithmicScale(Guid.NewGuid(), this.cache, null)
            {
                Name = "Test Derived QK", ShortName = "tdqk"
            };
            var simpleQuantityKind = new SimpleQuantityKind();

            rdl.ParameterType.Add(simpleQuantityKind);
            rdl.Scale.Add(testLogarithmicScale);
            this.siteDir.SiteReferenceDataLibrary.Add(rdl);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            var chainOfContainers = new[] { rdl };

            var clone = testLogarithmicScale.Clone(false);

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

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

            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.viewmodel = new ScaleReferenceQuantityValueDialogViewModel(this.scaleReferenceQuantityValue, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone, chainOfContainers);
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            this.scaleReferenceQuantityValueRuleChecker = new ScaleReferenceQuantityValueRuleChecker();

            this.siteReferenceDataLibrary = new SiteReferenceDataLibrary();
            this.logarithmicScale         = new LogarithmicScale {
                Iid = Guid.NewGuid()
            };
            this.scaleReferenceQuantityValue = new ScaleReferenceQuantityValue();

            this.siteReferenceDataLibrary.Scale.Add(this.logarithmicScale);
            this.logarithmicScale.ReferenceQuantityValue.Add(this.scaleReferenceQuantityValue);
        }
Ejemplo n.º 8
0
        public void TestGetAllPossibleScaleSpecialized()
        {
            var quantityKind = new SpecializedQuantityKind();

            var scale = new LogarithmicScale();

            quantityKind.PossibleScale.Add(scale);

            quantityKind.General = new SimpleQuantityKind();
            quantityKind.General.PossibleScale.Add(new RatioScale());
            quantityKind.General.PossibleScale.Add(new CyclicRatioScale());
            quantityKind.General.PossibleScale.Add(scale);

            Assert.AreEqual(3, quantityKind.AllPossibleScale.Count);
        }
Ejemplo n.º 9
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.ratioScale = new RatioScale(Guid.NewGuid(), null, null) { Name = "ratioScale", ShortName = "dqk" };
            this.ratioScale.ValueDefinition.Add(svd1);
            this.ratioScale.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 RatioScaleDialogViewModel(this.ratioScale, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object);
        }
Ejemplo n.º 10
0
        public void VerifThatUpdatingGeneralUpdatesPossiblePossibleScales()
        {
            Assert.IsNotEmpty(this.viewmodel.PossibleGeneral);
            Assert.IsNull(this.viewmodel.SelectedGeneral);

            var scale1 = new LogarithmicScale(Guid.NewGuid(), null, null);
            var scale2 = new RatioScale(Guid.NewGuid(), null, null);

            this.rdl.Scale.Add(scale1);
            this.rdl.Scale.Add(scale2);

            var generalQuantityKind = this.viewmodel.PossibleGeneral.First();

            Assert.AreEqual(0, generalQuantityKind.PossibleScale.Count);

            generalQuantityKind.PossibleScale.Add(scale1);
            generalQuantityKind.PossibleScale.Add(scale2);
            this.viewmodel.SelectedGeneral = generalQuantityKind;

            Assert.AreEqual(2, this.viewmodel.GeneralizationScale.Count);
            Assert.AreEqual(0, this.viewmodel.PossiblePossibleScale.Count);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Persist the <see cref="LogarithmicScale"/> containment tree to the ORM layer. Update if it already exists.
        /// This is typically used during the import of existing data to the Database.
        /// </summary>
        /// <param name="transaction">
        /// The current <see cref="NpgsqlTransaction"/> to the database.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="logarithmicScale">
        /// The <see cref="LogarithmicScale"/> instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool UpsertContainment(NpgsqlTransaction transaction, string partition, LogarithmicScale logarithmicScale)
        {
            var results = new List <bool>();

            foreach (var alias in this.ResolveFromRequestCache(logarithmicScale.Alias))
            {
                results.Add(this.AliasService.UpsertConcept(transaction, partition, alias, logarithmicScale));
            }

            foreach (var definition in this.ResolveFromRequestCache(logarithmicScale.Definition))
            {
                results.Add(this.DefinitionService.UpsertConcept(transaction, partition, definition, logarithmicScale));
            }

            foreach (var hyperLink in this.ResolveFromRequestCache(logarithmicScale.HyperLink))
            {
                results.Add(this.HyperLinkService.UpsertConcept(transaction, partition, hyperLink, logarithmicScale));
            }

            foreach (var mappingToReferenceScale in this.ResolveFromRequestCache(logarithmicScale.MappingToReferenceScale))
            {
                results.Add(this.MappingToReferenceScaleService.UpsertConcept(transaction, partition, mappingToReferenceScale, logarithmicScale));
            }

            foreach (var referenceQuantityValue in this.ResolveFromRequestCache(logarithmicScale.ReferenceQuantityValue))
            {
                results.Add(this.ReferenceQuantityValueService.UpsertConcept(transaction, partition, referenceQuantityValue, logarithmicScale));
            }

            foreach (var valueDefinition in this.ResolveFromRequestCache(logarithmicScale.ValueDefinition))
            {
                results.Add(this.ValueDefinitionService.UpsertConcept(transaction, partition, valueDefinition, logarithmicScale));
            }

            return(results.All(x => x));
        }