示例#1
0
        public void From_Inherited_TypedEntity_To_IndexOperation()
        {
            //Arrange

            var systemRoot = new SystemRoot();


            //Act

            var result1 = _mapper.Map <SystemRoot, NestedHiveIndexOperation>(systemRoot);
            var result2 = _mapper.Map <TypedEntity, NestedHiveIndexOperation>(systemRoot);

            //Assert

            Assert.AreEqual("TypedEntity", result1.ItemCategory);
            Assert.AreEqual(systemRoot.EntitySchema.SchemaType, result1.Fields[FixedIndexedFields.SchemaType].FieldValue);
            Assert.AreEqual(IndexOperationType.Add, result1.OperationType);
            Assert.AreEqual(systemRoot.Id.Value.ToString(), result1.Id.Value);
            Assert.AreEqual(systemRoot.Id.Value.ToString(), result1.Fields[FixedIndexedFields.EntityId].FieldValue);
            Assert.AreEqual(systemRoot.EntitySchema.Alias, result1.Fields[FixedIndexedFields.SchemaAlias].FieldValue);
            Assert.AreEqual(systemRoot.EntitySchema.Name, result1.Fields[FixedIndexedFields.SchemaName].FieldValue);
            Assert.AreEqual(systemRoot.EntitySchema.Id.Value.ToString(), result1.Fields[FixedIndexedFields.SchemaId].FieldValue);

            VerifyIEntityFields(result1, systemRoot);
        }
示例#2
0
        private void SetupContentTest()
        {
            AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry());

            // Ensure parent schema and content root exists for this test
            var contentVirtualRoot = FixedEntities.ContentVirtualRoot;
            var systemRoot         = new SystemRoot();
            var contentRootSchema  = new ContentRootSchema();

            Hive.AutoCommitTo <IContentStore>(
                x =>
            {
                x.Repositories.AddOrUpdate(systemRoot);
                x.Repositories.AddOrUpdate(contentVirtualRoot);
                x.Repositories.Schemas.AddOrUpdate(contentRootSchema);
            });
        }
示例#3
0
    public void EntityRemovedCallbackShouldBeCalledWithComponents2()
    {
        var entityManager = new EntityManager();

        var systemRoot = new SystemRoot <EntityManager>(entityManager);

        var group = entityManager.GetComponentGroup(typeof(Component1), typeof(Component2));

        var listenerMock = new ListenerMock();

        // group.SubscribeOnEntityAdded(listenerMock);
        // group.SubscribeOnEntityRemoved (listenerMock);
        group.SubscribeOnEntityRemoving(listenerMock);

        // group.component

        var e = entityManager.CreateEntity();

        entityManager.AddComponent(e, new Component1());
        entityManager.AddComponent(e, new Component2());

        // Assert.That (listenerMock.addedCalls, Is.EqualTo (1));

        // listenerMock.RemovedEvent += delegate (Entity e1) {
        //  Assert.True(entityManager.HasComponent<Component1>(e1));
        //  Assert.True(entityManager.HasComponent<Component2>(e1));
        // };

        listenerMock.RemovingEvent += delegate(Entity e1) {
            Assert.True(entityManager.HasComponent <Component1>(e1));
            Assert.True(entityManager.HasComponent <Component2>(e1));
        };


        entityManager.RemoveComponent <Component1>(e);
        // entityManager.RemoveComponentImmediate<Component1>(e);

        systemRoot.Update();

        Assert.That(listenerMock.removingCalls, Is.EqualTo(1));
    }
        public FakeUmbracoApplicationContext(IHiveManager hive, bool addSystemRooNode = true)
        {
            ApplicationId = Guid.NewGuid();

            //_repo = new NHibernateInMemoryRepository(cmsManager.CoreManager.FrameworkContext);

            Hive             = hive;
            FrameworkContext = Hive.FrameworkContext;
            //Security = MockRepository.GenerateMock<ISecurityService>();
            Security = Substitute.For <ISecurityService>();
            Security.GetEffectivePermission(Arg.Any <Guid>(), Arg.Any <HiveId>(), Arg.Any <HiveId>())
            .Returns(new PermissionResult(new BackOfficeAccessPermission(), HiveId.Empty, PermissionStatus.Allow));
            Security.GetEffectivePermissions(Arg.Any <HiveId>(), Arg.Any <HiveId>(), Arg.Any <Guid[]>())
            .Returns(new PermissionResults(new PermissionResult(new BackOfficeAccessPermission(), HiveId.Empty, PermissionStatus.Allow)));


            if (addSystemRooNode)
            {
                //we need to add the root node
                // Create root node
                var root = new SystemRoot();
                AddPersistenceData(root);
            }

            //get the bin folder
            var binFolder = Common.CurrentAssemblyDirectory;

            //get settings
            var settingsFile = new FileInfo(Path.Combine(binFolder, "web.config"));

            Settings = new UmbracoSettings(settingsFile);


            //FrameworkContext.Stub(x => x.CurrentLanguage).Return((LanguageInfo) Thread.CurrentThread.CurrentCulture);
            //FrameworkContext.Stub(x => x.TextManager).Return(MockRepository.GenerateMock<TextManager>());
        }
        public virtual void EntityRelations_CachePopulates()
        {
            TypedEntity entityParent = HiveModelCreationHelper.MockTypedEntity();
            TypedEntity entityChild = HiveModelCreationHelper.MockTypedEntity();
            TypedEntity entitySibling = HiveModelCreationHelper.MockTypedEntity();

            var root = new SystemRoot();
            root.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entityParent);
            entityParent.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entityChild);
            entityParent.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entitySibling);

            using (IReadWriteUnitOfWork writer = DirectReadWriteProvider.CreateReadWriteUnitOfWork())
            {
                writer.ReadWriteRepository.AddOrUpdate(root);
                writer.Commit();
            }

            PostWriteCallback.Invoke();

            using (IReadOnlyUnitOfWork reader = DirectReaderProvider.CreateReadOnlyUnitOfWork())
            {
                IEnumerable<TypedEntity> getEntities = reader.ReadRepository.GetEntities<TypedEntity>();
                Assert.AreEqual(4, getEntities.Count());
            }

            Assert.Inconclusive("Not finished");
        }
        public virtual void EntityRelations_GetByRoute()
        {
            TypedEntity entityParent = HiveModelCreationHelper.MockTypedEntity();
            TypedEntity entityChild = HiveModelCreationHelper.MockTypedEntity();
            TypedEntity entityGrandchild = HiveModelCreationHelper.MockTypedEntity();

            entityParent.Attributes.SetValueOrAdd(new NodeNameAttribute("homepage"));
            entityChild.Attributes.SetValueOrAdd(new NodeNameAttribute("news"));
            entityGrandchild.Attributes.SetValueOrAdd(new NodeNameAttribute("newsitem1"));

            var root = new SystemRoot();
            root.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entityParent);
            entityParent.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entityChild);
            entityChild.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entityGrandchild);

            using (IReadWriteUnitOfWork writer = DirectReadWriteProvider.CreateReadWriteUnitOfWork())
            {
                writer.ReadWriteRepository.AddOrUpdate(root);
                writer.Commit();
            }

            using (DisposableTimer timer = DisposableTimer.TraceDuration<AbstractHivePersistenceTest>("Start perf test", "End perf test"))
            {
                for (int i = 0; i < 5; i++)
                {
                    PostWriteCallback.Invoke();

                    using (IReadOnlyUnitOfWork reader = DirectReaderProvider.CreateReadOnlyUnitOfWork())
                    {
                        var nhReader = reader.ReadRepository as RepositoryReader;
                        var hp = nhReader.GetByPath<TypedEntity>(new HiveId("/homepage/"), FixedRelationTypes.ContentTreeRelationType, FixedStatusTypes.Created);
                        var news = nhReader.GetByPath<TypedEntity>(new HiveId("/homepage/news"), FixedRelationTypes.ContentTreeRelationType, FixedStatusTypes.Created);
                        var newsitem1 = nhReader.GetByPath<TypedEntity>(new HiveId("/homepage/news/newsitem1"), FixedRelationTypes.ContentTreeRelationType, FixedStatusTypes.Created);
                        Assert.IsNotNull(hp);
                        Assert.IsNotNull(news);
                        Assert.IsNotNull(newsitem1);

                        var newsitem1_bad1 = nhReader.GetByPath<TypedEntity>(new HiveId("/homepage/newsitem1"));
                        var newsitem1_bad2 = nhReader.GetByPath<TypedEntity>(new HiveId("newsitem1"));
                        Assert.IsNull(newsitem1_bad1);
                        Assert.IsNull(newsitem1_bad2);
                    }
                }

                LogHelper.TraceIfEnabled<AbstractHivePersistenceTest>("Avg of {0}ms per run", () => timer.Stopwatch.ElapsedMilliseconds / 5);
            }
        }
        private void SetupContentTest(IHiveManager hive)
        {
            AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry());

            // Ensure parent schema and content root exists for this test
            var contentVirtualRoot = FixedEntities.ContentVirtualRoot;
            var systemRoot = new SystemRoot();
            var contentRootSchema = new ContentRootSchema();
            hive.AutoCommitTo<IContentStore>(
                x =>
                {
                    x.Repositories.AddOrUpdate(systemRoot);
                    x.Repositories.AddOrUpdate(contentVirtualRoot);
                    x.Repositories.Schemas.AddOrUpdate(contentRootSchema);
                });
        }
        public void Create_Typed_Entity_Under_Root_Then_Copy_To_Another_Parent()
        {
            //Arrange

            var root = new SystemRoot();
            Revision<TypedEntity> content = HiveModelCreationHelper.MockVersionedTypedEntity();
            Revision<TypedEntity> newParent = HiveModelCreationHelper.MockVersionedTypedEntity();
            AssignFakeIdsIfPassthrough(ProviderSetup.ProviderMetadata, content, newParent);

            root.RelationProxies.EnlistChild(content.Item, FixedRelationTypes.DefaultRelationType);

            using (var uow = ProviderSetup.UnitFactory.Create())
            {
                uow.EntityRepository.AddOrUpdate(root);
                uow.EntityRepository.Revisions.AddOrUpdate(content);
                uow.EntityRepository.Revisions.AddOrUpdate(newParent);
                uow.Complete();

                // Guard for the fact that the relation proxy must have had its lazyload delegate set as a result of the
                // above calls
                Assert.True(root.RelationProxies.IsConnected);
                Assert.True(content.Item.RelationProxies.IsConnected);
                Assert.True(newParent.Item.RelationProxies.IsConnected);
            }
            PostWriteCallback.Invoke();

            //Act

            TypedEntity copied;
            using (var uow = ProviderSetup.UnitFactory.Create())
            {
                //create a new copied entity
                copied = content.Item.CreateDeepCopyToNewParent(newParent.Item, FixedRelationTypes.DefaultRelationType, 0);
                AssignFakeIdsIfPassthrough(ProviderSetup.ProviderMetadata, copied);

                uow.EntityRepository.AddOrUpdate(copied);
                uow.Complete();
            }
            PostWriteCallback.Invoke();

            //Assert

            using (var uow = ProviderSetup.UnitFactory.Create())
            {
                var queriesCopiedContent = uow.EntityRepository.Get<TypedEntity>(copied.Id);
                Assert.IsNotNull(queriesCopiedContent);
                Assert.IsTrue(queriesCopiedContent.RelationProxies.IsConnected);
                Assert.AreEqual(FixedRelationTypes.DefaultRelationType.RelationName, queriesCopiedContent.RelationProxies.Single().Item.Type.RelationName);
                Assert.AreEqual(newParent.Item.Id, queriesCopiedContent.RelationProxies.Single().Item.SourceId);
            }
            PostWriteCallback.Invoke();
        }
        public void SaveAndLoad_InbuiltSchemas()
        {
            var originalSecurity = new UserGroupSchema();
            var systemRoot = new SystemRoot();

            using (var writer = ProviderSetup.UnitFactory.Create())
            {
                writer.EntityRepository.AddOrUpdate(systemRoot); // Need to add a system root because UserGroupSchema advertises that it's related to it
                writer.EntityRepository.Schemas.AddOrUpdate(originalSecurity);
                writer.Complete();
            }

            // Clear session to avoid caching when testing readbacks
            PostWriteCallback.Invoke();

            using (var reader = ReadonlyProviderSetup.ReadonlyUnitFactory.CreateReadonly())
            {
                // Reload. Shouldn't matter that we're newing up the schemas to get the Id as Id should 
                // have been left alone when saving, so leave it here as a test case
                var securitySchema = reader.EntityRepository.Schemas.Get<EntitySchema>(originalSecurity.Id);

                Assert.IsNotNull(securitySchema, "Security schema");

                Assert.AreEqual(originalSecurity.AttributeDefinitions.Count, securitySchema.AttributeDefinitions.Count, "Security attrib defs count differ");
                Assert.AreEqual(originalSecurity.AttributeGroups.Count, securitySchema.AttributeGroups.Count, "Security attrib groups count differ");
                Assert.AreEqual(originalSecurity.AttributeTypes.Count(), securitySchema.AttributeTypes.Count(), "Security attrib types count differ");
            }
        }
        private void AddParentRelation(Action<ProviderUnit, SystemRoot, TypedEntity> addRelation)
        {
            // Arrange
            var parentRoot = new SystemRoot();
            var contentChild = HiveModelCreationHelper.MockTypedEntity();
            AssignFakeIdsIfPassthrough(ProviderSetup.ProviderMetadata, contentChild);

            // Act
            using (var writer = ProviderSetup.UnitFactory.Create())
            {
                writer.EntityRepository.AddOrUpdate(parentRoot);
                writer.EntityRepository.AddOrUpdate(contentChild);
                addRelation.Invoke(writer, parentRoot, contentChild);
                writer.Complete();
            }

            PostWriteCallback.Invoke();

            // Assert
            Assert.NotNull(parentRoot.RelationProxies.LazyLoadDelegate);
            Assert.NotNull(parentRoot.RelationProxies.FirstOrDefault());

            // Check loading the relation from the repo
            using (var writer = ProviderSetup.UnitFactory.Create())
            {
                var ancestorRelations = writer.EntityRepository.GetLazyAncestorRelations(contentChild.Id, FixedRelationTypes.DefaultRelationType);
                var ancestor = ancestorRelations.Where(x => x.SourceId == parentRoot.Id).FirstOrDefault();
                Assert.NotNull(ancestor);
                Assert.NotNull(ancestor.Source);
                Assert.AreEqual(ancestor.SourceId, parentRoot.Id);
                Assert.AreEqual(ancestor.DestinationId, contentChild.Id);

                var descendentRelations = writer.EntityRepository.GetLazyDescendentRelations(parentRoot.Id, FixedRelationTypes.DefaultRelationType);
                var descendent = descendentRelations.Where(x => x.DestinationId == contentChild.Id).FirstOrDefault();
                Assert.NotNull(descendent);
                Assert.NotNull(descendent.Source);
                Assert.AreEqual(descendent.SourceId, parentRoot.Id);
                Assert.AreEqual(descendent.DestinationId, contentChild.Id);
            }

            // Check loading the relation from the lazy-loaded collection on the entity
            using (var writer = ProviderSetup.UnitFactory.Create())
            {
                var reloadedRoot = writer.EntityRepository.Get<TypedEntity>(parentRoot.Id);
                var child = reloadedRoot.RelationProxies.FirstOrDefault();
                Assert.NotNull(child);
            }
        }
        public void Create_Typed_Entity_Under_Root_Then_Move_To_Another_Parent()
        {
            //Arrange

            var root = new SystemRoot();
            Revision<TypedEntity> content = HiveModelCreationHelper.MockVersionedTypedEntity();
            Revision<TypedEntity> newParent = HiveModelCreationHelper.MockVersionedTypedEntity();
            AssignFakeIdsIfPassthrough(ProviderSetup.ProviderMetadata, content, newParent);

            using (var uow = ProviderSetup.UnitFactory.Create())
            {
                uow.EntityRepository.AddOrUpdate(root);
                uow.EntityRepository.Revisions.AddOrUpdate(content);
                uow.EntityRepository.Revisions.AddOrUpdate(newParent);
                uow.EntityRepository.AddRelation(root, content.Item, FixedRelationTypes.DefaultRelationType, 0);
                uow.Complete();

                // Guard for the fact that the relation proxy must have had its lazyload delegate set as a result of the
                // above calls
                Assert.True(root.RelationProxies.IsConnected);
                Assert.True(content.Item.RelationProxies.IsConnected);
                Assert.True(newParent.Item.RelationProxies.IsConnected);
            }
            PostWriteCallback.Invoke();

            //Act

            using (var uow = ProviderSetup.UnitFactory.Create())
            {
                var reloadedContent = uow.EntityRepository.Revisions.Get<TypedEntity>(content.Item.Id, content.MetaData.Id);
                Assert.NotNull(reloadedContent);

                var rootRelations = uow.EntityRepository
                    .GetChildRelations(root, FixedRelationTypes.DefaultRelationType);

                var rootRelation = rootRelations
                    .Where(x => x.DestinationId == reloadedContent.Item.Id)
                    .FirstOrDefault();
                Assert.NotNull(rootRelation);

                uow.EntityRepository.RemoveRelation(rootRelation);
                uow.EntityRepository.AddRelation(newParent.Item, content.Item, FixedRelationTypes.DefaultRelationType, 0);
                uow.Complete();
            }
            PostWriteCallback.Invoke();

            //Assert

            using (var uow = ReadonlyProviderSetup.ReadonlyUnitFactory.CreateReadonly())
            {
                var contentReloaded = uow.EntityRepository.Get<TypedEntity>(content.Item.Id);
                Assert.IsNotNull(contentReloaded);
                var relations = contentReloaded.RelationProxies.ToList();
                Assert.That(relations.Count, Is.EqualTo(1));
                var relation = relations.Single().Item;
                Assert.AreEqual(FixedRelationTypes.DefaultRelationType.RelationName, relation.Type.RelationName);
                Assert.AreEqual(newParent.Item.Id, relation.SourceId);

                var rootReloaded = uow.EntityRepository.Get<TypedEntity>(root.Id);
                Assert.NotNull(rootReloaded);
                var rootRelations = uow.EntityRepository.GetDescendentRelations(root, FixedRelationTypes.DefaultRelationType);
                Assert.IsFalse(rootRelations.Any());
            }
            PostWriteCallback.Invoke();
        }