Beispiel #1
0
        public void VerifyThatRdlShortnameIsUpdated()
        {
            var vm = new MeasurementUnitsBrowserViewModel(this.session.Object, this.siteDir, null, null, null, null);

            var sRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);

            sRdl.Container = this.siteDir;

            var cat = new LinearConversionUnit(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name = "cat1", ShortName = "1", Container = sRdl
            };
            var cat2 = new LinearConversionUnit(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.MeasurementUnits.Count(x => x.ContainerRdl == "test") == 2);
        }
Beispiel #2
0
        public void SetUp()
        {
            this.conversionBasedUnitRuleChecker = new ConversionBasedUnitRuleChecker();

            this.siteReferenceDataLibrary = new SiteReferenceDataLibrary();
            this.linearConversionUnit     = new LinearConversionUnit();

            this.siteReferenceDataLibrary.Unit.Add(this.linearConversionUnit);
        }
        /// <summary>
        /// Serialize the <see cref="LinearConversionUnit"/>
        /// </summary>
        /// <param name="linearConversionUnit">The <see cref="LinearConversionUnit"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(LinearConversionUnit linearConversionUnit)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](linearConversionUnit.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), linearConversionUnit.ClassKind)));
            jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](linearConversionUnit.ConversionFactor));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](linearConversionUnit.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](linearConversionUnit.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](linearConversionUnit.Iid));
            jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](linearConversionUnit.IsDeprecated));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](linearConversionUnit.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](linearConversionUnit.Name));
            jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](linearConversionUnit.ReferenceUnit));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](linearConversionUnit.RevisionNumber));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](linearConversionUnit.ShortName));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](linearConversionUnit.ThingPreference));
            return(jsonObject);
        }
Beispiel #4
0
        public void VerifyThatPropertiesAreSet()
        {
            var shortname        = "new shortname";
            var name             = "new name";
            var conversionFactor = "254/10000";
            var isdeprecated     = true;

            var container = this.genericSiteReferenceDataLibrary;
            var gram      = this.genericSiteReferenceDataLibrary.Unit.Single(u => u.ShortName == "g");
            var metre     = this.genericSiteReferenceDataLibrary.Unit.Single(u => u.ShortName == "m");

            var linearConversionUnit = new LinearConversionUnit(Guid.NewGuid(), null, this.uri)
            {
                ShortName        = shortname,
                Name             = name,
                IsDeprecated     = isdeprecated,
                Container        = container,
                ReferenceUnit    = gram,
                ConversionFactor = conversionFactor
            };

            var vm = new LinearConversionUnitDialogViewModel(linearConversionUnit, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.dialogService.Object, null);

            Assert.AreEqual(this.genericSiteReferenceDataLibrary.Iid, vm.Container.Iid);

            CollectionAssert.Contains(vm.PossibleReferenceUnit, gram);
            CollectionAssert.Contains(vm.PossibleReferenceUnit, metre);

            Assert.AreEqual(shortname, vm.ShortName);
            Assert.AreEqual(name, vm.Name);
            Assert.AreEqual(conversionFactor, vm.ConversionFactor);
            Assert.AreEqual(isdeprecated, vm.IsDeprecated);
            Assert.AreEqual(gram, vm.SelectedReferenceUnit);

            Assert.IsTrue(vm.OkCommand.CanExecute(null));
        }
        /// <summary>
        /// Persist the <see cref="LinearConversionUnit"/> 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="linearConversionUnit">
        /// The <see cref="LinearConversionUnit"/> instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool UpsertContainment(NpgsqlTransaction transaction, string partition, LinearConversionUnit linearConversionUnit)
        {
            var results = new List <bool>();

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

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

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

            return(results.All(x => x));
        }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LinearConversionUnitDialogViewModel"/> class.
 /// </summary>
 /// <param name="linearConversionUnit">
 /// The <see cref="LinearConversionUnit"/> 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="LinearConversionUnitDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="LinearConversionUnitDialogViewModel"/> 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 LinearConversionUnitDialogViewModel(LinearConversionUnit linearConversionUnit, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(linearConversionUnit, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
     this.WhenAnyValue(vm => vm.Container).Subscribe(_ => this.PopulatePossibleReferenceUnit());
     this.WhenAnyValue(vm => vm.Container).Subscribe(_ => this.UpdateOkCanExecute());
 }
Beispiel #7
0
        public void Setup()
        {
            this.npgsqlTransaction = null;
            this.securityContext   = new Mock <ISecurityContext>();

            // There is a chain a -> b -> c
            this.linearConversionUnitC = new LinearConversionUnit {
                Iid = Guid.NewGuid()
            };
            this.linearConversionUnitB =
                new LinearConversionUnit {
                Iid = Guid.NewGuid(), ReferenceUnit = this.linearConversionUnitC.Iid
            };
            this.linearConversionUnitA =
                new LinearConversionUnit {
                Iid = Guid.NewGuid(), ReferenceUnit = this.linearConversionUnitB.Iid
            };
            this.linearConversionUnitD = new LinearConversionUnit {
                Iid = Guid.NewGuid()
            };

            // Outside the rdl chain
            this.linearConversionUnitE = new LinearConversionUnit {
                Iid = Guid.NewGuid()
            };

            // There is a chain librayA -> LibraryB
            this.referenceDataLibraryB =
                new SiteReferenceDataLibrary {
                Iid = Guid.NewGuid(), Unit = { this.linearConversionUnitD.Iid }
            };
            this.referenceDataLibraryA = new ModelReferenceDataLibrary
            {
                Iid  = Guid.NewGuid(),
                Unit =
                {
                    this.linearConversionUnitA.Iid,
                    this.linearConversionUnitB.Iid,
                    this.linearConversionUnitC.Iid
                },
                RequiredRdl = this.referenceDataLibraryB.Iid
            };

            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.referenceDataLibraryB
            });

            this.conversionBasedUnitService = new Mock <IConversionBasedUnitService>();
            this.conversionBasedUnitService
            .Setup(
                x => x.Get(
                    this.npgsqlTransaction,
                    It.IsAny <string>(),
                    new List <Guid>
            {
                this.linearConversionUnitD.Iid,
                this.linearConversionUnitA.Iid,
                this.linearConversionUnitB.Iid,
                this.linearConversionUnitC.Iid
            },
                    It.IsAny <ISecurityContext>())).Returns(
                new List <ConversionBasedUnit>
            {
                this.linearConversionUnitD,
                this.linearConversionUnitA,
                this.linearConversionUnitB,
                this.linearConversionUnitC
            });
        }
Beispiel #8
0
        public void VerififyThatInvalidContainerThrowsException()
        {
            var linearConversionUnit = new LinearConversionUnit(Guid.NewGuid(), null, this.uri);

            Assert.Throws <ArgumentException>(() => new LinearConversionUnitDialogViewModel(linearConversionUnit, this.transaction, this.session.Object, true, ThingDialogKind.Inspect, this.dialogService.Object, this.sitedirclone));
        }