Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DerivedQuantityKindDialogViewModel"/> class.
 /// </summary>
 /// <param name="derivedQuantityKind">
 /// The Derived 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="DerivedQuantityKindDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="DerivedQuantityKindDialogViewModel"/> 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 DerivedQuantityKindDialogViewModel(DerivedQuantityKind derivedQuantityKind, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(derivedQuantityKind, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
     this.WhenAnyValue(vm => vm.Container).Subscribe(_ => this.PopulatePossiblePossibleScales());
     this.WhenAnyValue(vm => vm.SelectedDefaultScale).Subscribe(_ => this.UpdateOkCanExecute());
     this.QuantityKindFactor.CountChanged.Subscribe(_ => this.UpdateOkCanExecute());
 }
Пример #2
0
        public void VerifyThatErrorListContainsErrorWhenNoPossibleScalesAreSet()
        {
            this.derivedQuantityKind = new DerivedQuantityKind();
            this.derivedQuantityKind.ValidatePoco();

            CollectionAssert.Contains(this.derivedQuantityKind.ValidationErrors, "The PossibleScale property is empty.");
        }
Пример #3
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);
        }
Пример #4
0
        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.quantityKindFactor = new QuantityKindFactor();
            var testDerivedQuantityKind = new DerivedQuantityKind(Guid.NewGuid(), this.cache, null)
            {
                Name = "Test Derived QK", ShortName = "tdqk"
            };
            var simpleQuantityKind = new SimpleQuantityKind();

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


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

            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 QuantityKindFactorDialogViewModel(this.quantityKindFactor, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone, chainOfContainers);
        }
        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());
        }
        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.session         = new Mock <ISession>();
            this.referenceSource = new ReferenceSource(Guid.NewGuid(), null, null)
            {
                Name = "Referencesource", ShortName = "RSO", IsDeprecated = true,
            };
            this.citation = new Citation(Guid.NewGuid(), null, null)
            {
                ShortName = "CIT", Location = "location", IsAdaptation = true, Remark = "remark"
            };
            this.citation.Source = this.referenceSource;
            this.siteDirectory   = new SiteDirectory(Guid.NewGuid(), null, null);

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

            this.transaction = 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());

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, null)
            {
                Name = "testRDL", ShortName = "test"
            };
            var simpleQuantityKind      = new SimpleQuantityKind();
            var testDerivedQuantityKind = new DerivedQuantityKind(Guid.NewGuid(), this.cache, null)
            {
                Name = "Test Derived QK", ShortName = "tdqk"
            };

            rdl.ParameterType.Add(simpleQuantityKind);
            rdl.ParameterType.Add(testDerivedQuantityKind);
            this.chainOfContainers = new[] { rdl };
        }
Пример #7
0
        public void Setup()
        {
            // QuantityKind tree: rootQk -> specializedQk -> derivedQk -> simpleQk
            this.simpleQk = new SimpleQuantityKind(Guid.NewGuid(), 0);

            this.derivedQkFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.simpleQk.Iid
            };

            this.derivedQk = new DerivedQuantityKind(Guid.NewGuid(), 0)
            {
                QuantityKindFactor =
                {
                    new OrderedItem {
                        K = 1, V = this.derivedQkFactor.Iid.ToString()
                    }
                }
            };

            this.specializedQk = new SpecializedQuantityKind(Guid.NewGuid(), 0)
            {
                General = this.derivedQk.Iid
            };

            this.rootQkFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.specializedQk.Iid
            };

            this.rootQk = new DerivedQuantityKind(Guid.NewGuid(), 0)
            {
                QuantityKindFactor =
                {
                    new OrderedItem {
                        K = 1, V = this.rootQkFactor.Iid.ToString()
                    }
                }
            };

            // cyclic factor
            this.derivedQkCyclicFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.rootQk.Iid
            };

            // outside RDL factor
            this.outsideRdlQk = new SimpleQuantityKind(Guid.NewGuid(), 0);

            this.derivedQkOutsideRdlFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.outsideRdlQk.Iid
            };

            // RDL chain: mrdl -> srdl
            this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), 0)
            {
                ParameterType =
                {
                    this.simpleQk.Iid
                }
            };

            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), 0)
            {
                ParameterType =
                {
                    this.derivedQk.Iid,
                    this.specializedQk.Iid,
                    this.rootQk.Iid
                },
                RequiredRdl = this.srdl.Iid
            };

            // setup services
            this.npgsqlTransaction = null;
            this.securityContext   = new Mock <ISecurityContext>();

            this.siteReferenceDataLibraryService = new Mock <ISiteReferenceDataLibraryService>();
            this.siteReferenceDataLibraryService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       null,
                       It.IsAny <ISecurityContext>()))
            .Returns(new List <ReferenceDataLibrary>
            {
                this.srdl
            });

            this.quantityKindFactorService = new Mock <IQuantityKindFactorService>();
            this.quantityKindFactorService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       It.IsAny <IEnumerable <Guid> >(),
                       It.IsAny <ISecurityContext>()))
            .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>(
                (transaction, partition, iids, context) =>
            {
                iids = iids.ToList();

                return(new List <Thing>
                {
                    this.derivedQkFactor,
                    this.rootQkFactor,
                    this.derivedQkCyclicFactor,
                    this.derivedQkOutsideRdlFactor
                }.Where(qkf => iids.Contains(qkf.Iid)));
            });

            this.quantityKindService = new Mock <IQuantityKindService>();
            this.quantityKindService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       It.IsAny <IEnumerable <Guid> >(),
                       It.IsAny <ISecurityContext>()))
            .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>(
                (transaction, partition, iids, context) =>
            {
                iids = iids.ToList();

                return(new List <Thing>
                {
                    this.simpleQk,
                    this.derivedQk,
                    this.specializedQk,
                    this.rootQk,
                    this.outsideRdlQk
                }.Where(qk => iids.Contains(qk.Iid)));
            });

            this.sideEffect = new DerivedQuantityKindSideEffect
            {
                SiteReferenceDataLibraryService = this.siteReferenceDataLibraryService.Object,
                QuantityKindFactorService       = this.quantityKindFactorService.Object,
                QuantityKindService             = this.quantityKindService.Object
            };
        }
        /// <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="derivedQuantityKind">
        /// The derivedQuantityKind instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool CreateContainment(NpgsqlTransaction transaction, string partition, DerivedQuantityKind derivedQuantityKind)
        {
            var results = new List <bool>();

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

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

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

            foreach (var quantityKindFactor in this.ResolveFromRequestCache(derivedQuantityKind.QuantityKindFactor))
            {
                results.Add(this.QuantityKindFactorService.CreateConcept(transaction, partition, (QuantityKindFactor)quantityKindFactor.V, derivedQuantityKind, quantityKindFactor.K));
            }

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