public void Setup() { this.session = new Mock <ISession>(); this.permissionService = new Mock <IPermissionService>(); this.assembler = new Assembler(this.uri); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.sitedir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri); this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri) { Surname = "surname", GivenName = "given", ShortName = "short" }; this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri); this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri) { IterationNumber = 1 }; this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri) { Person = this.person }; this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri); this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri) { EngineeringModelSetup = this.modelsetup }; this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri) { IterationSetup = this.iterationsetup }; this.ed = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri); this.rid = new ReviewItemDiscrepancy(Guid.NewGuid(), this.assembler.Cache, this.uri); this.reference = new ModellingThingReference(Guid.NewGuid(), this.assembler.Cache, this.uri); this.reference.ReferencedThing = this.ed; this.rid.PrimaryAnnotatedThing = this.reference; this.sitedir.Person.Add(this.person); this.sitedir.Domain.Add(this.domain); this.sitedir.Model.Add(this.modelsetup); this.modelsetup.Participant.Add(this.participant); this.model.Iteration.Add(this.iteration); this.iteration.Element.Add(this.ed); this.model.ModellingAnnotation.Add(this.rid); this.rid.RelatedThing.Add(this.reference); this.session.Setup(x => x.ActivePerson).Returns(this.person); this.session.Setup(x => x.OpenIterations). Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > { { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) } }); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.session.Setup(x => x.Write(It.IsAny <OperationContainer>())).Returns(() => null); this.assembler.Cache.TryAdd(new CacheKey(this.model.Iid, null), new Lazy <Thing>(() => this.model)); this.assembler.Cache.TryAdd(new CacheKey(this.rid.Iid, null), new Lazy <Thing>(() => this.rid)); }
/// <summary> /// Serialize the <see cref="ReviewItemDiscrepancy"/> /// </summary> /// <param name="reviewItemDiscrepancy">The <see cref="ReviewItemDiscrepancy"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(ReviewItemDiscrepancy reviewItemDiscrepancy) { var jsonObject = new JObject(); jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.guidComparer))); jsonObject.Add("author", this.PropertySerializerMap["author"](reviewItemDiscrepancy.Author)); jsonObject.Add("category", this.PropertySerializerMap["category"](reviewItemDiscrepancy.Category.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), reviewItemDiscrepancy.Classification))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), reviewItemDiscrepancy.ClassKind))); jsonObject.Add("content", this.PropertySerializerMap["content"](reviewItemDiscrepancy.Content)); jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](reviewItemDiscrepancy.CreatedOn)); jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](reviewItemDiscrepancy.Iid)); jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](reviewItemDiscrepancy.LanguageCode)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](reviewItemDiscrepancy.ModifiedOn)); jsonObject.Add("owner", this.PropertySerializerMap["owner"](reviewItemDiscrepancy.Owner)); jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](reviewItemDiscrepancy.PrimaryAnnotatedThing)); jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.guidComparer))); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](reviewItemDiscrepancy.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](reviewItemDiscrepancy.ShortName)); jsonObject.Add("solution", this.PropertySerializerMap["solution"](reviewItemDiscrepancy.Solution)); jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.guidComparer))); jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), reviewItemDiscrepancy.Status))); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](reviewItemDiscrepancy.ThingPreference)); jsonObject.Add("title", this.PropertySerializerMap["title"](reviewItemDiscrepancy.Title)); return(jsonObject); }
/// <summary> /// Persist the <see cref="ReviewItemDiscrepancy"/> 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="reviewItemDiscrepancy"> /// The <see cref="ReviewItemDiscrepancy"/> instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool UpsertContainment(NpgsqlTransaction transaction, string partition, ReviewItemDiscrepancy reviewItemDiscrepancy) { var results = new List <bool>(); foreach (var approvedBy in this.ResolveFromRequestCache(reviewItemDiscrepancy.ApprovedBy)) { results.Add(this.ApprovedByService.UpsertConcept(transaction, partition, approvedBy, reviewItemDiscrepancy)); } foreach (var discussion in this.ResolveFromRequestCache(reviewItemDiscrepancy.Discussion)) { results.Add(this.DiscussionService.UpsertConcept(transaction, partition, discussion, reviewItemDiscrepancy)); } foreach (var relatedThing in this.ResolveFromRequestCache(reviewItemDiscrepancy.RelatedThing)) { results.Add(this.RelatedThingService.UpsertConcept(transaction, partition, relatedThing, reviewItemDiscrepancy)); } foreach (var solution in this.ResolveFromRequestCache(reviewItemDiscrepancy.Solution)) { results.Add(this.SolutionService.UpsertConcept(transaction, partition, solution, reviewItemDiscrepancy)); } return(results.All(x => x)); }
/// <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="reviewItemDiscrepancy"> /// The reviewItemDiscrepancy instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool CreateContainment(NpgsqlTransaction transaction, string partition, ReviewItemDiscrepancy reviewItemDiscrepancy) { var results = new List <bool>(); foreach (var relatedThing in this.ResolveFromRequestCache(reviewItemDiscrepancy.RelatedThing)) { results.Add(this.ModellingThingReferenceService.CreateConcept(transaction, partition, relatedThing, reviewItemDiscrepancy)); } foreach (var discussion in this.ResolveFromRequestCache(reviewItemDiscrepancy.Discussion)) { results.Add(this.EngineeringModelDataDiscussionItemService.CreateConcept(transaction, partition, discussion, reviewItemDiscrepancy)); } foreach (var approvedBy in this.ResolveFromRequestCache(reviewItemDiscrepancy.ApprovedBy)) { results.Add(this.ApprovalService.CreateConcept(transaction, partition, approvedBy, reviewItemDiscrepancy)); } foreach (var solution in this.ResolveFromRequestCache(reviewItemDiscrepancy.Solution)) { results.Add(this.SolutionService.CreateConcept(transaction, partition, solution, reviewItemDiscrepancy)); } return(results.All(x => x)); }