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

            if (!jObject["domain"].IsNullOrEmpty())
            {
                participant.Domain.AddRange(jObject["domain"].ToObject <IEnumerable <Guid> >());
            }

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

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

            if (!jObject["isActive"].IsNullOrEmpty())
            {
                participant.IsActive = jObject["isActive"].ToObject <bool>();
            }

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

            if (!jObject["person"].IsNullOrEmpty())
            {
                participant.Person = jObject["person"].ToObject <Guid>();
            }

            if (!jObject["role"].IsNullOrEmpty())
            {
                participant.Role = jObject["role"].ToObject <Guid>();
            }

            if (!jObject["selectedDomain"].IsNullOrEmpty())
            {
                participant.SelectedDomain = jObject["selectedDomain"].ToObject <Guid>();
            }

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

            return(participant);
        }
Beispiel #2
0
        public void VerifyThatExceptionIsThrownWhenInvalidOrNullSelectedDomain()
        {
            var participant = new CDP4Common.DTO.Participant();

            participant.Domain.Add(Guid.NewGuid());

            //null selected domain verification
            this.rawUpdateInfo = new ClasslessDTO()
            {
                { SelectedDomainKey, null }
            };

            Assert.Throws <InvalidOperationException>(
                () =>
                this.participantSideEffect.BeforeUpdate(
                    participant,
                    null,
                    this.npgsqlTransaction,
                    "partition",
                    this.securityContext.Object,
                    this.rawUpdateInfo));

            //invalid selected domain verification
            this.rawUpdateInfo = new ClasslessDTO()
            {
                { SelectedDomainKey, default }
            };

            Assert.Throws <InvalidOperationException>(
                () =>
                this.participantSideEffect.BeforeUpdate(
                    participant,
                    null,
                    this.npgsqlTransaction,
                    "partition",
                    this.securityContext.Object,
                    this.rawUpdateInfo));
        }