Exemplo n.º 1
0
        public void Get_Paged_Parent_Child_Entities_With_Same_Entity_Relation()
        {
            // Create a media item and create a relationship between itself (parent -> child)
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            MediaTypeService.Save(imageType);
            Media media = MediaBuilder.CreateMediaImage(imageType, -1);

            MediaService.Save(media);
            IRelationType relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);

            RelationService.Relate(media.Id, media.Id, relType);

            using (IScope scope = ScopeProvider.CreateScope())
            {
                RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository relationTypeRepository);

                // Get parent entities for child id
                var parents = repository.GetPagedParentEntitiesByChildId(media.Id, 0, 10, out long totalRecords).ToList();
                Assert.AreEqual(1, totalRecords);
                Assert.AreEqual(1, parents.Count);

                // Get child entities for parent id
                var children = repository.GetPagedChildEntitiesByParentId(media.Id, 0, 10, out totalRecords).ToList();
                Assert.AreEqual(1, totalRecords);
                Assert.AreEqual(1, children.Count);
            }
        }
Exemplo n.º 2
0
        public void Get_Paged_Parent_Entities_By_Child_Id()
        {
            CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia);

            using (IScope scope = ScopeProvider.CreateScope())
            {
                RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository relationTypeRepository);

                // Get parent entities for child id
                var parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 11, out long totalRecords).ToList();
                Assert.AreEqual(6, totalRecords);
                Assert.AreEqual(6, parents.Count);

                // add the next page
                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 1, 11, out totalRecords));
                Assert.AreEqual(6, totalRecords);
                Assert.AreEqual(6, parents.Count);

                var contentEntities = parents.OfType <IDocumentEntitySlim>().ToList();
                var mediaEntities   = parents.OfType <IMediaEntitySlim>().ToList();
                var memberEntities  = parents.OfType <IMemberEntitySlim>().ToList();

                Assert.AreEqual(3, contentEntities.Count);
                Assert.AreEqual(0, mediaEntities.Count);
                Assert.AreEqual(3, memberEntities.Count);

                // only of a certain type
                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Document.GetGuid()));
                Assert.AreEqual(3, totalRecords);

                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Member.GetGuid()));
                Assert.AreEqual(3, totalRecords);

                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Media.GetGuid()));
                Assert.AreEqual(0, totalRecords);
            }
        }
Exemplo n.º 3
0
        public void Get_Paged_Parent_Entities_By_Child_Id()
        {
            CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia);

            using (IScope scope = ScopeProvider.CreateScope())
            {
                RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository relationTypeRepository);

                // Get parent entities for child id
                var parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 11, out long totalRecords).ToList();
                Assert.AreEqual(9, totalRecords);
                Assert.AreEqual(9, parents.Count);

                // Add the next page
                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 1, 11, out totalRecords));
                Assert.AreEqual(9, totalRecords);
                Assert.AreEqual(9, parents.Count);

                var contentEntities = parents.OfType <IDocumentEntitySlim>().ToList();
                var mediaEntities   = parents.OfType <IMediaEntitySlim>().ToList();
                var memberEntities  = parents.OfType <IMemberEntitySlim>().ToList();

                Assert.AreEqual(3, contentEntities.Count);
                Assert.AreEqual(3, mediaEntities.Count);
                Assert.AreEqual(3, memberEntities.Count);

                // Only of a certain type
                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Document.GetGuid()));
                Assert.AreEqual(3, totalRecords);

                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Member.GetGuid()));
                Assert.AreEqual(3, totalRecords);

                parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Media.GetGuid()));
                Assert.AreEqual(3, totalRecords);

                // Test relations on content
                var contentParents = repository.GetPagedParentEntitiesByChildId(createdContent[0].Id, 0, int.MaxValue, out totalRecords).ToList();
                Assert.AreEqual(6, totalRecords);
                Assert.AreEqual(6, contentParents.Count);

                // Test getting relations of specified relation types
                var relatedMediaRelType   = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
                var relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);

                parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 11, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
                Assert.AreEqual(6, totalRecords);
                Assert.AreEqual(6, parents.Count);

                parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 1, 11, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
                Assert.AreEqual(6, totalRecords);
                Assert.AreEqual(0, parents.Count);

                parents = repository.GetPagedParentEntitiesByChildId(createdContent[0].Id, 0, 6, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
                Assert.AreEqual(3, totalRecords);
                Assert.AreEqual(3, parents.Count);

                parents = repository.GetPagedParentEntitiesByChildId(createdContent[0].Id, 1, 6, out totalRecords, new int[] { relatedContentRelType.Id, relatedMediaRelType.Id }).ToList();
                Assert.AreEqual(3, totalRecords);
                Assert.AreEqual(0, parents.Count);
            }
        }