public void CreateTestData() { _relateContent = new RelationType( "Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972")); _relateContentType = new RelationType( "Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB")); using (IScope scope = ScopeProvider.CreateScope()) { var accessor = (IScopeAccessor)ScopeProvider; var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Mock.Of <ILogger <RelationTypeRepository> >()); var entityRepository = new EntityRepository(accessor, AppCaches.Disabled); var relationRepository = new RelationRepository(accessor, Mock.Of <ILogger <RelationRepository> >(), relationTypeRepository, entityRepository); relationTypeRepository.Save(_relateContent); relationTypeRepository.Save(_relateContentType); Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) _contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); ContentTypeService.Save(_contentType); // Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1) _textpage = ContentBuilder.CreateSimpleContent(_contentType); ContentService.Save(_textpage, 0); // Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2) _subpage = ContentBuilder.CreateSimpleContent(_contentType, "Text Page 1", _textpage.Id); ContentService.Save(_subpage, 0); // Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3) _subpage2 = ContentBuilder.CreateSimpleContent(_contentType, "Text Page 2", _textpage.Id); ContentService.Save(_subpage2, 0); _relation = new Relation(_textpage.Id, _subpage.Id, _relateContent) { Comment = string.Empty }; _relation2 = new Relation(_textpage.Id, _subpage2.Id, _relateContent) { Comment = string.Empty }; relationRepository.Save(_relation); relationRepository.Save(_relation2); scope.Complete(); } }
public void CreateTestData() { var relateContent = new RelationType( "Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972")); var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB")); var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var accessor = (IScopeAccessor)provider; var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Mock.Of <ILogger>()); var entityRepository = new EntityRepository(accessor); var relationRepository = new RelationRepository(accessor, Mock.Of <ILogger>(), relationTypeRepository, entityRepository); relationTypeRepository.Save(relateContent); relationTypeRepository.Save(relateContentType); //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! ServiceContext.ContentTypeService.Save(contentType); //Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1) Content textpage = MockedContent.CreateSimpleContent(contentType); ServiceContext.ContentService.Save(textpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2) Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id); ServiceContext.ContentService.Save(subpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3) Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id); ServiceContext.ContentService.Save(subpage2, 0); var relation = new Relation(textpage.Id, subpage.Id, relateContent) { Comment = string.Empty }; var relation2 = new Relation(textpage.Id, subpage2.Id, relateContent) { Comment = string.Empty }; relationRepository.Save(relation); relationRepository.Save(relation2); scope.Complete(); } }
protected void RelateInternal(IClassifiable relatable, IClassifiable related, RelationDirection direction, TaxonomyNode type) { var currentRelation = GetRelation(relatable, related, type); if (direction == RelationDirection.Undefined) { if (currentRelation != null) { relationRepo.Delete(currentRelation); } //do nothing if direction is undefined } else { if (currentRelation == null) { currentRelation = RelationEntity.Create(relatable, related, type == null?null:type.entity, direction); relationRepo.Save(currentRelation); } else { currentRelation.Direction = direction; relationRepo.Update(currentRelation); } } }
public void Can_Perform_Add_On_RelationRepository() { // Arrange using (IScope scope = ScopeProvider.CreateScope()) { RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository repositoryType); // Act IRelationType relationType = repositoryType.Get(1); var relation = new Relation(_textpage.Id, _subpage.Id, relationType); repository.Save(relation); // Assert Assert.That(relation, Is.Not.Null); Assert.That(relation.HasIdentity, Is.True); } }
public void Can_Perform_Update_On_RelationRepository() { // Arrange using (IScope scope = ScopeProvider.CreateScope()) { RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository repositoryType); // Act IRelation relation = repository.Get(1); relation.Comment = "This relation has been updated"; repository.Save(relation); IRelation relationUpdated = repository.Get(1); // Assert Assert.That(relationUpdated, Is.Not.Null); Assert.That(relationUpdated.Comment, Is.EqualTo("This relation has been updated")); Assert.AreNotEqual(relationUpdated.UpdateDate, relation.UpdateDate); } }