Esempio n. 1
0
        public void SetUp()
        {
            this.uri       = new Uri("http://www.rheagroup.com");
            this.cache     = new List <Thing>();
            this.testInput = new List <CDP4Common.DTO.Thing>();

            this.person = new CDP4Common.DTO.Person(Guid.NewGuid(), 0)
            {
                Surname = "test", Password = "******", IsActive = true
            };
            this.person2 = new CDP4Common.DTO.Person(Guid.NewGuid(), 0)
            {
                Surname = "test2", Password = "******", IsActive = true
            };
            var phone1 = new CDP4Common.DTO.TelephoneNumber(Guid.NewGuid(), 0)
            {
                Value = "123"
            };

            phone1.VcardType.Add(VcardTelephoneNumberKind.HOME);
            var phone2 = new CDP4Common.DTO.TelephoneNumber(Guid.NewGuid(), 0)
            {
                Value = "456"
            };

            phone2.VcardType.Add(VcardTelephoneNumberKind.WORK);
            var phone3 = new CDP4Common.DTO.TelephoneNumber(Guid.NewGuid(), 0)
            {
                Value = "789"
            };

            phone3.VcardType.Add(VcardTelephoneNumberKind.FAX);

            this.linearConversionUnitType = new CDP4Common.DTO.LinearConversionUnit(Guid.NewGuid(), 0);
            this.prefixedUnitType         = new CDP4Common.DTO.PrefixedUnit(Guid.NewGuid(), 0);
            this.derivedUnitType          = new CDP4Common.DTO.DerivedUnit(Guid.NewGuid(), 0);
            this.simpleUnitUnitType       = new CDP4Common.DTO.SimpleUnit(Guid.NewGuid(), 0);

            this.person.TelephoneNumber.Add(phone1.Iid);
            this.person.TelephoneNumber.Add(phone2.Iid);
            this.person.TelephoneNumber.Add(phone3.Iid);

            this.testInput.Add(new SiteDirectory(Guid.NewGuid(), 1));
            this.testInput.Add(this.person);
            this.testInput.Add(this.person2);
            this.testInput.Add(phone1);
            this.testInput.Add(phone2);
            this.testInput.Add(phone3);

            this.testInput.Add(this.linearConversionUnitType);
            this.testInput.Add(this.prefixedUnitType);
            this.testInput.Add(this.derivedUnitType);
            this.testInput.Add(this.simpleUnitUnitType);
        }
        /// <summary>
        /// Instantiate and deserialize the properties of a <paramref name="DerivedUnit"/>
        /// </summary>
        /// <param name="jObject">The <see cref="JObject"/> containing the data</param>
        /// <returns>The <see cref="DerivedUnit"/> to instantiate</returns>
        public static CDP4Common.DTO.DerivedUnit FromJsonObject(JObject jObject)
        {
            var iid            = jObject["iid"].ToObject <Guid>();
            var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject <int>();
            var derivedUnit    = new CDP4Common.DTO.DerivedUnit(iid, revisionNumber);

            if (!jObject["alias"].IsNullOrEmpty())
            {
                derivedUnit.Alias.AddRange(jObject["alias"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["definition"].IsNullOrEmpty())
            {
                derivedUnit.Definition.AddRange(jObject["definition"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["excludedDomain"].IsNullOrEmpty())
            {
                derivedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["excludedPerson"].IsNullOrEmpty())
            {
                derivedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["hyperLink"].IsNullOrEmpty())
            {
                derivedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["isDeprecated"].IsNullOrEmpty())
            {
                derivedUnit.IsDeprecated = jObject["isDeprecated"].ToObject <bool>();
            }

            if (!jObject["modifiedOn"].IsNullOrEmpty())
            {
                derivedUnit.ModifiedOn = jObject["modifiedOn"].ToObject <DateTime>();
            }

            if (!jObject["name"].IsNullOrEmpty())
            {
                derivedUnit.Name = jObject["name"].ToObject <string>();
            }

            if (!jObject["shortName"].IsNullOrEmpty())
            {
                derivedUnit.ShortName = jObject["shortName"].ToObject <string>();
            }

            if (!jObject["thingPreference"].IsNullOrEmpty())
            {
                derivedUnit.ThingPreference = jObject["thingPreference"].ToObject <string>();
            }

            if (!jObject["unitFactor"].IsNullOrEmpty())
            {
                derivedUnit.UnitFactor.AddRange(jObject["unitFactor"].ToOrderedItemCollection());
            }

            return(derivedUnit);
        }