Example #1
0
        public void VerifyInspectMappingToReferenceScale()
        {
            var vm = this.viewmodel;
            Assert.IsNull(vm.SelectedMappingToReferenceScale);

            var mtrs = new MappingToReferenceScale(Guid.NewGuid(), null, null);
            var mtrsr = new CDP4CommonView.MappingToReferenceScaleRowViewModel(mtrs, this.session.Object, null);
            vm.MappingToReferenceScale.Add(mtrsr);
            vm.SelectedMappingToReferenceScale = vm.MappingToReferenceScale.First();
            Assert.IsTrue(vm.InspectMappingToReferenceScaleCommand.CanExecute(null));
            vm.InspectMappingToReferenceScaleCommand.Execute(null);
            this.navigation.Verify(x => x.Navigate(It.IsAny<MappingToReferenceScale>(), It.IsAny<ThingTransaction>(), this.session.Object, false, ThingDialogKind.Inspect, this.navigation.Object, It.IsAny<Thing>(), null));
        }
        /// <summary>
        /// Serialize the <see cref="MappingToReferenceScale"/>
        /// </summary>
        /// <param name="mappingToReferenceScale">The <see cref="MappingToReferenceScale"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(MappingToReferenceScale mappingToReferenceScale)
        {
            var jsonObject = new JObject();

            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), mappingToReferenceScale.ClassKind)));
            jsonObject.Add("dependentScaleValue", this.PropertySerializerMap["dependentScaleValue"](mappingToReferenceScale.DependentScaleValue));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](mappingToReferenceScale.Iid));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](mappingToReferenceScale.ModifiedOn));
            jsonObject.Add("referenceScaleValue", this.PropertySerializerMap["referenceScaleValue"](mappingToReferenceScale.ReferenceScaleValue));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](mappingToReferenceScale.RevisionNumber));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](mappingToReferenceScale.ThingPreference));
            return(jsonObject);
        }
Example #3
0
        public void VerifMappingToReferenceScaleCommands()
        {
            Assert.IsTrue(this.viewmodel.CreateMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsFalse(this.viewmodel.InspectMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsFalse(this.viewmodel.EditMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsFalse(this.viewmodel.DeleteMappingToReferenceScaleCommand.CanExecute(null));

            var mtrs = new MappingToReferenceScale(Guid.NewGuid(), null, null);
            var mtrsr = new CDP4CommonView.MappingToReferenceScaleRowViewModel(mtrs, this.session.Object, null);
            this.viewmodel.MappingToReferenceScale.Add(mtrsr);
            this.viewmodel.SelectedMappingToReferenceScale = this.viewmodel.MappingToReferenceScale.First();

            Assert.IsTrue(this.viewmodel.InspectMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsTrue(this.viewmodel.EditMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsTrue(this.viewmodel.DeleteMappingToReferenceScaleCommand.CanExecute(null));

            this.viewmodel.ValueDefinition.Clear();
            Assert.IsFalse(this.viewmodel.CreateMappingToReferenceScaleCommand.CanExecute(null));
        }
Example #4
0
        public void VerifyReactiveCommandsCanExecuteOnInspectMode()
        {
            var vm = new RatioScaleDialogViewModel(this.ratioScale, this.transaction, this.session.Object, true, ThingDialogKind.Inspect, this.navigation.Object, this.rdl);
            Assert.IsFalse(vm.CreateAliasCommand.CanExecute(null));
            Assert.IsFalse(vm.CreateDefinitionCommand.CanExecute(null));
            Assert.IsFalse(vm.CreateHyperLinkCommand.CanExecute(null));
            Assert.IsFalse(vm.CreateMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsFalse(vm.CreateValueDefinitionCommand.CanExecute(null));

            vm.SelectedValueDefinition = this.viewmodel.ValueDefinition.First();
            var mtrs = new MappingToReferenceScale(Guid.NewGuid(), null, null);
            var mtrsr = new CDP4CommonView.MappingToReferenceScaleRowViewModel(mtrs, this.session.Object, null);
            vm.SelectedMappingToReferenceScale = mtrsr;

            Assert.IsTrue(vm.InspectValueDefinitionCommand.CanExecute(null));
            Assert.IsFalse(vm.EditValueDefinitionCommand.CanExecute(null));
            Assert.IsFalse(vm.DeleteValueDefinitionCommand.CanExecute(null));
            Assert.IsTrue(vm.InspectMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsFalse(vm.EditMappingToReferenceScaleCommand.CanExecute(null));
            Assert.IsFalse(vm.DeleteMappingToReferenceScaleCommand.CanExecute(null));
        }
Example #5
0
 public void VerifyThatParameterlessContructorExists()
 {
     var dialogViewModel = new MappingToReferenceScale();
     Assert.IsNotNull(dialogViewModel.Iid);
 }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.navigation           = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            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 rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, null)
            {
                Name = "testRDL", ShortName = "test"
            };

            this.mappingToReferenceScale = new MappingToReferenceScale(Guid.NewGuid(), null, null);
            this.siteDir.SiteReferenceDataLibrary.Add(rdl);
            this.testRatioScale = new RatioScale(Guid.NewGuid(), this.cache, null)
            {
                Name = "ratioScale", ShortName = "dqk"
            };
            var testRatioScale1 = new RatioScale(Guid.NewGuid(), this.cache, null)
            {
                Name = "ratioScale1", ShortName = "dqk1"
            };
            var svd1 = new ScaleValueDefinition(Guid.NewGuid(), this.cache, null)
            {
                Name = "ReferenceSVD", ShortName = "RSVD"
            };
            var svd2 = new ScaleValueDefinition(Guid.NewGuid(), this.cache, null)
            {
                Name = "DependentSVD", ShortName = "DSVD"
            };

            this.testRatioScale.ValueDefinition.Add(svd1);
            testRatioScale1.ValueDefinition.Add(svd2);
            rdl.Scale.Add(this.testRatioScale);
            rdl.Scale.Add(testRatioScale1);

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

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

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);

            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 MappingToReferenceScaleDialogViewModel(this.mappingToReferenceScale, this.transaction, this.session.Object, false, ThingDialogKind.Create, this.navigation.Object, this.clone);
        }
Example #7
0
 /// <summary>
 /// Add an Mapping To Reference Scale row view model to the list of <see cref="MappingToReferenceScale"/>
 /// </summary>
 /// <param name="mappingToReferenceScale">
 /// The <see cref="MappingToReferenceScale"/> that is to be added
 /// </param>
 private MappingToReferenceScaleRowViewModel AddMappingToReferenceScaleRowViewModel(MappingToReferenceScale mappingToReferenceScale)
 {
     return(new MappingToReferenceScaleRowViewModel(mappingToReferenceScale, this.Session, this));
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MappingToReferenceScaleDialogViewModel"/> class.
 /// </summary>
 /// <param name="mappingToReferenceScale">
 /// The <see cref="MappingToReferenceScale"/> 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="MappingToReferenceScaleDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="MappingToReferenceScaleDialogViewModel"/> 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 MappingToReferenceScaleDialogViewModel(MappingToReferenceScale mappingToReferenceScale, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(mappingToReferenceScale, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
     this.WhenAnyValue(vm => vm.SelectedReferenceScaleValue).Subscribe(_ => this.UpdateOkCanExecute());
     this.WhenAnyValue(vm => vm.SelectedDependentScaleValue).Subscribe(_ => this.UpdateOkCanExecute());
 }
Example #9
0
        public void Setup()
        {
            this.scaleValueDefinition = new ScaleValueDefinition(Guid.NewGuid(), 0);

            this.containerMeasurementScale = new OrdinalScale(Guid.NewGuid(), 0)
            {
                ValueDefinition =
                {
                    this.scaleValueDefinition.Iid
                }
            };

            this.rootMappingToReferenceScale = new MappingToReferenceScale(Guid.NewGuid(), 0)
            {
                ReferenceScaleValue = this.scaleValueDefinition.Iid,
                DependentScaleValue = this.scaleValueDefinition.Iid
            };

            this.rootMeasurementScale = new OrdinalScale(Guid.NewGuid(), 0)
            {
                MappingToReferenceScale =
                {
                    this.rootMappingToReferenceScale.Iid
                }
            };

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

            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), 0)
            {
                Scale =
                {
                    this.rootMeasurementScale.Iid,
                    this.containerMeasurementScale.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.mappingToReferenceScaleService = new Mock <IMappingToReferenceScaleService>();
            this.mappingToReferenceScaleService
            .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.rootMappingToReferenceScale
                }.Where(qk => iids.Contains(qk.Iid)));
            });

            this.scaleValueDefinitionService = new Mock <IScaleValueDefinitionService>();
            this.scaleValueDefinitionService
            .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.scaleValueDefinition
                }.Where(qk => iids.Contains(qk.Iid)));
            });

            this.measurementScaleService = new Mock <IMeasurementScaleService>();
            this.measurementScaleService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       null,
                       It.IsAny <ISecurityContext>()))
            .Returns(new List <MeasurementScale>
            {
                this.rootMeasurementScale,
                this.containerMeasurementScale
            });

            this.sideEffect = new MeasurementScaleSideEffect
            {
                SiteReferenceDataLibraryService = this.siteReferenceDataLibraryService.Object,
                MappingToReferenceScaleService  = this.mappingToReferenceScaleService.Object,
                ScaleValueDefinitionService     = this.scaleValueDefinitionService.Object,
                MeasurementScaleService         = this.measurementScaleService.Object
            };
        }