Exemplo n.º 1
0
        public void DataInstallTest_CoreData_NHibernate()
        {
            //Arrange

            var nhibernateTestSetup = new NhibernateTestSetupHelper();

            var storageProvider = new IoHiveTestSetupHelper(nhibernateTestSetup.FakeFrameworkContext);

            var hiveManager =
                new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                nhibernateTestSetup.ReadonlyProviderSetup,
                                nhibernateTestSetup.ProviderSetup,
                                nhibernateTestSetup.FakeFrameworkContext),
                            storageProvider.CreateGroup("uploader", "storage://file-uploader")
                        },
                    nhibernateTestSetup.FakeFrameworkContext);

            RunTest(hiveManager, nhibernateTestSetup.FakeFrameworkContext, () =>
                {
                    nhibernateTestSetup.SessionForTest.Clear();
                    hiveManager.Context.GenerationScopedCache.Clear();
                });

            hiveManager.Dispose();
        }
Exemplo n.º 2
0
        public void Session_ContainerWithChildren_WillRepresentAsRelations()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            //Act
            var directoryInfo = setup.TestDirectory.GetDirectories("*.*", SearchOption.TopDirectoryOnly)
                .Where(x => x.GetDirectories().Any())
                .First();

            var file = setup.EntityRepository.Get<File>(new HiveId(directoryInfo.FullName));

            //Assert
            var children = directoryInfo.GetDirectories();
            Assert.IsTrue(children.Count() > 0);

            var childrenViaProxy = file.RelationProxies.AllChildRelations();
            Assert.AreEqual(children.Count(), childrenViaProxy.Count());

            var firstChildRelationViaProxy = childrenViaProxy.First();
            // Source & Destination should be null because we're not going via a EntityRepositoryGroup which can lazy-load relation entities
            Assert.IsNull(firstChildRelationViaProxy.Item.Source);
            Assert.IsNull(firstChildRelationViaProxy.Item.Destination);

            var loadDestination = setup.EntityRepository.Get<File>(firstChildRelationViaProxy.Item.DestinationId);
            Assert.IsNotNull(loadDestination);
            Assert.That(loadDestination, Is.InstanceOf<File>());

            Assert.AreEqual(children.First().Name, ((File)loadDestination).Name);
        }
Exemplo n.º 3
0
        public void Session_GetAll_FindsOnlySpecificExtensions()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            //Act
            var files = setup.EntityRepository.GetAll<File>();

            //Assert
            var count = files.Count();
            Assert.AreEqual(setup.TestDirectory.GetFiles(setup.Settings.SupportedExtensions, SearchOption.TopDirectoryOnly).OfType<FileSystemInfo>().Concat(setup.TestDirectory.GetDirectories()).Count(), count);
            Assert.IsTrue(setup.TestDirectory.GetFiles("*.*", SearchOption.TopDirectoryOnly).OfType<FileSystemInfo>().Concat(setup.TestDirectory.GetDirectories()).Count() >= count);
        }
        protected void SetupFakeEnvironment()
        {
            // TODO: Prettify and extract smaller methods

            NhibernateTestSetup = new NhibernateTestSetupHelper();

            var storageProvider = new IoHiveTestSetupHelper(NhibernateTestSetup.FakeFrameworkContext);

            Hive = new HiveManager(
                new[]
                    {
                        new ProviderMappingGroup(
                            "test",
                            new WildcardUriMatch("content://"),
                            NhibernateTestSetup.ReadonlyProviderSetup,
                            NhibernateTestSetup.ProviderSetup,
                            NhibernateTestSetup.FakeFrameworkContext),
                        storageProvider.CreateGroup("uploader", "storage://file-uploader"),
                    },
                NhibernateTestSetup.FakeFrameworkContext);

            AppContext = new FakeUmbracoApplicationContext(Hive, false);

            var resolverContext = new MockedMapResolverContext(NhibernateTestSetup.FakeFrameworkContext, Hive,
                                                               new MockedPropertyEditorFactory(AppContext),
                                                               new MockedParameterEditorFactory());
            var webmModelMapper = new CmsModelMapper(resolverContext);
            var renderModelMapper = new RenderTypesModelMapper(resolverContext);

            NhibernateTestSetup.FakeFrameworkContext.SetTypeMappers(
                new FakeTypeMapperCollection(new AbstractMappingEngine[]
                                             	{
                                             		webmModelMapper, renderModelMapper,
                                             		new FrameworkModelMapper(NhibernateTestSetup.FakeFrameworkContext)
                                             	}));

            var membersMembershipProvider = new MembersMembershipProvider { AppContext = AppContext };
            membersMembershipProvider.Initialize("MembersMembershipProvider", new NameValueCollection());
            MembershipService = new MembershipService<Member, MemberProfile>(AppContext.FrameworkContext, Hive,
                                                                             "security://member-profiles",
                                                                             "security://member-groups",
                                                                             Umbraco.Framework.Security.Model.FixedHiveIds.
                                                                                MemberProfileVirtualRoot,
                                                                             membersMembershipProvider,
                                                                             Enumerable.Empty<MembershipProviderElement>());

            PublicAccessService = new PublicAccessService(Hive, MembershipService, AppContext.FrameworkContext);
        }
Exemplo n.º 5
0
        public void Session_GetEntityOfFile_ReturnsFoundEntity()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            //Act
            var existingFile = setup.TestDirectory.GetFiles(setup.Settings.SupportedExtensions, SearchOption.AllDirectories).First();
            var file = setup.EntityRepository.Get<File>(setup.EntityRepository.GenerateId(existingFile.FullName));

            //Assert
            Assert.IsNotNull(file);
            Assert.AreEqual(existingFile.Name, file.Name);
            Assert.IsTrue(existingFile.LastWriteTime == file.UtcModified);
            Assert.AreEqual(existingFile.FullName, file.RootedPath);
            Assert.IsFalse(file.IsContainer);

        }
Exemplo n.º 6
0
        public void Session_GetEntityOfDirectory_ReturnsFoundEntity()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            //Act
            var directoryInfo = setup.TestDirectory.GetDirectories("*.*", SearchOption.TopDirectoryOnly).First();
            var file = setup.EntityRepository.Get<File>(setup.EntityRepository.GenerateId(directoryInfo.FullName));

            //Assert
            Assert.IsNotNull(file);
            Assert.AreEqual(directoryInfo.Name, file.Name);
            Assert.IsTrue(directoryInfo.LastWriteTime == file.UtcModified);
            Assert.AreEqual(directoryInfo.FullName, file.RootedPath);
            Assert.IsTrue(file.IsContainer);

        }
Exemplo n.º 7
0
        public void Session_CreateContainerEntity()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            //Act
            var file = IoHiveTestSetupHelper.CreateFile(string.Empty);
            setup.EntityRepository.AddOrUpdate(file);

            //Assert
            Assert.IsNotNull(file.Id);
            Assert.IsTrue(file.IsContainer);
            Assert.IsTrue(Directory.Exists(file.RootedPath));
        }
Exemplo n.º 8
0
        public void Session_GetDescendents_CanObtainAllDescendents_DefaultRelationType()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();
            var actualFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var parentFolderForScanning = actualFile.Directory.Parent;

            // Act
            var parentFolderItem = setup.EntityRepository.Get<File>(new HiveId(parentFolderForScanning.FullName));
            var aChildItem = setup.EntityRepository.Get<File>(new HiveId(actualFile.FullName));
            var childRelations = setup.EntityRepository.GetLazyRelations(parentFolderItem, Direction.Descendents, FixedRelationTypes.DefaultRelationType);
            var childItems = childRelations.Select(x => x.Destination).ToList();

            // Assert
            // Check for iterator block mistakes
            Assert.AreEqual(childRelations.Count(), childRelations.ToList().Count());
            Assert.That(childItems.Count, Is.GreaterThanOrEqualTo(2));
            Assert.That(childItems.Select(x => x.Id), Has.Some.EqualTo(aChildItem.Id));
        }
Exemplo n.º 9
0
        public void SessionExtensions_GetAncestorsOrSelf_CanObtainAllAncestors_DefaultRelationType()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            var actualFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var parentFolder = actualFile.Directory;
            var parent2ndLevelFolder = parentFolder.Parent;

            //Act
            var file = setup.EntityRepository.Get<File>(new HiveId(actualFile.FullName));
            var itemsOrSelf = setup.EntityRepository.GetAncestorsOrSelf(file, FixedRelationTypes.DefaultRelationType);

            var firstItemShouldBeSelf = (File)itemsOrSelf.First();
            var firstParent = (File)(itemsOrSelf.Skip(1).Take(1).FirstOrDefault());
            var secondParent = (File)(itemsOrSelf.Skip(2).Take(1).FirstOrDefault());

            //Assert
            // Check for iterator block mistakes
            Assert.AreEqual(itemsOrSelf.Count(), itemsOrSelf.ToList().Count());
            Assert.That(itemsOrSelf.Count(), Is.GreaterThanOrEqualTo(2));
            Assert.That(file.Id, Is.EqualTo(firstItemShouldBeSelf.Id));
            Assert.That(file.RootedPath, Is.EqualTo(firstItemShouldBeSelf.RootedPath));
            Assert.That(file.IsContainer, Is.EqualTo(firstItemShouldBeSelf.IsContainer));
            Assert.That(file.ContentBytes, Is.EqualTo(firstItemShouldBeSelf.ContentBytes));
            Assert.That(file.UtcCreated, Is.EqualTo(firstItemShouldBeSelf.UtcCreated));
            Assert.That(file.UtcModified, Is.EqualTo(firstItemShouldBeSelf.UtcModified));
            Assert.That(file.UtcStatusChanged, Is.EqualTo(firstItemShouldBeSelf.UtcStatusChanged));
            Assert.That(file, Is.EqualTo(firstItemShouldBeSelf));
            Assert.AreEqual(actualFile.FullName.NormaliseDirectoryPath(), file.RootedPath.NormaliseDirectoryPath());
            Assert.AreEqual(parentFolder.FullName.NormaliseDirectoryPath(), firstParent.RootedPath.NormaliseDirectoryPath());
            Assert.AreEqual(parent2ndLevelFolder.FullName.NormaliseDirectoryPath(), secondParent.RootedPath.NormaliseDirectoryPath());
        }
Exemplo n.º 10
0
        public void SessionExtensions_GetAncestors_CanObtainAllAncestors_DefaultRelationType()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            var actualFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var parentFolder = actualFile.Directory;
            var parent2ndLevelFolder = parentFolder.Parent;

            //Act
            var file = setup.EntityRepository.Get<File>(new HiveId(actualFile.FullName));
            var parents = setup.EntityRepository.GetLazyAncestorRelations(file.Id, FixedRelationTypes.DefaultRelationType);
            var firstParent = ((File)parents.First().Source);
            var secondParent = ((File)(parents.Skip(1).Take(1).FirstOrDefault()).Source);

            //Assert
            // Check for iterator block mistakes
            Assert.AreEqual(parents.Count(), parents.ToList().Count());
            Assert.That(parents.Count(), Is.GreaterThanOrEqualTo(2));
            Assert.AreEqual(actualFile.FullName.NormaliseDirectoryPath(), file.RootedPath.NormaliseDirectoryPath());
            Assert.AreEqual(parentFolder.FullName.NormaliseDirectoryPath(), firstParent.RootedPath.NormaliseDirectoryPath());
            Assert.AreEqual(parent2ndLevelFolder.FullName.NormaliseDirectoryPath(), secondParent.RootedPath.NormaliseDirectoryPath());
        }
        public void SetUp()
        {
            _nhibernateTestSetup = new NhibernateTestSetupHelper();

            var storageProvider = new IoHiveTestSetupHelper(_nhibernateTestSetup.FakeFrameworkContext);

            Hive =
                new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                _nhibernateTestSetup.ReadonlyProviderSetup,
                                _nhibernateTestSetup.ProviderSetup,
                                _nhibernateTestSetup.FakeFrameworkContext),
                                storageProvider.CreateGroup("uploader", "storage://")
                        },
                    _nhibernateTestSetup.FakeFrameworkContext);

            // Setup Schemas
            Hive.Cms()
                .UsingStore<IContentStore>()
                .NewSchema("textpageSchema")
                .Define(NodeNameAttributeDefinition.AliasValue, NodeNameAttributeType.AliasValue, "tab1")
                .Define(SelectedTemplateAttributeDefinition.AliasValue, SelectedTemplateAttributeType.AliasValue, "tab1")
                .Commit();

            // Setup Content
            var root = Hive.Cms().NewRevision("Root", "root", "textpageSchema")
                .SetSelectedTemplate(new HiveId("storage", "templates", new HiveIdValue("/textpageTemplate.cshtml")))
                .Publish()
                .Commit();

            // Avoid type scanning in a unit test runner by passing in the known assembly under test
            var dynamicExtensionAssemblies = typeof (RenderViewModelExtensions).Assembly.AsEnumerableOfOne();

            _root = new Content(root.Item).Bend(Hive, null, null, dynamicExtensionAssemblies);

            var children = new List<dynamic>();

            for (var i = 0; i < 10; i++)
            {
                // Create child
                var child = Hive.Cms().NewRevision("Child" + i, "child-" + i, "textpageSchema")
                    .SetSelectedTemplate(new HiveId("storage", "templates", new HiveIdValue("/textpageTemplate.cshtml")))
                    .SetParent(root.Item)
                    .Publish()
                    .Commit();

                children.Add(new Content(child.Item).Bend(Hive, null, null, dynamicExtensionAssemblies));
            }

            _children = children;

            // Setup dependency resolver
            var dependencyResolver = Substitute.For<IDependencyResolver>();
            dependencyResolver.GetService(typeof(IHiveManager)).Returns(Hive);

            DependencyResolver.SetResolver(dependencyResolver);
        }
        public void WhenEntityIsAdded_PreAddOrUpdateBeforeUnitComplete_TaskChangesItem_ItemIsSavedWithNewValues()
        {
            // Arrange
            var nhibernateTestSetup = new NhibernateTestSetupHelper();

            var storageProvider = new IoHiveTestSetupHelper(nhibernateTestSetup.FakeFrameworkContext);

            var hive = new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                nhibernateTestSetup.ReadonlyProviderSetup,
                                nhibernateTestSetup.ProviderSetup,
                                nhibernateTestSetup.FakeFrameworkContext),
                            storageProvider.CreateGroup("uploader", "storage://file-uploader"),
                        },
                    nhibernateTestSetup.FakeFrameworkContext);

            var eventMock = Substitute.For<AbstractTask>(hive.FrameworkContext);
            eventMock.When(x => x.Execute(Arg.Any<TaskExecutionContext>()))
                .Do(x =>
            {
                var context = x.Args()[0] as TaskExecutionContext;
                if(context != null)
                {
                    var uow = context.EventSource as IGroupUnit<IProviderTypeFilter>;
                    var args = context.EventArgs.CallerEventArgs as HiveEntityPreActionEventArgs;
                    if (uow != null && args != null)
                    {
                        var item = args.Entity as TypedEntity;
                        if (item != null &&
                            item.Attributes.Any(
                                y => y.AttributeDefinition.Alias == NodeNameAttributeDefinition.AliasValue))
                        {
                            item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["Name"] = "Something else";

                            uow.Repositories.AddOrUpdate(item);
                        }
                    }
                }
            });

            // Act
            hive.FrameworkContext.TaskManager.AddTask(TaskTriggers.Hive.PreAddOrUpdateOnUnitComplete, () => eventMock, true);

            var id = HiveId.Empty;

            using (var uow = hive.OpenWriter<IContentStore>())
            {
                var anything = HiveModelCreationHelper.MockTypedEntity();

                // Cause the task to be fired
                uow.Repositories.AddOrUpdate(anything);
                uow.Complete();

                id = anything.Id;
            }

            using (var uow = hive.OpenWriter<IContentStore>())
            {
                // Cause the task to be fired
                var getItem = uow.Repositories.Get(id); // Store is mocked

                Assert.NotNull(getItem);

                // Assert the task has been fired
                Assert.AreEqual("Something else", getItem.Attributes[NodeNameAttributeDefinition.AliasValue].Values["Name"]);
            }
        }
Exemplo n.º 13
0
        public void Session_GetCurrentFolder_ReturnsCorrectDirectory()
        {
            // Arrange
            var setup = new IoHiveTestSetupHelper();

            var someFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();

            // Act
            var file = setup.EntityRepository.Get<File>(setup.EntityRepository.GenerateId(someFile.FullName));

            // Assert
            Assert.AreEqual(Path.GetDirectoryName(someFile.FullName) + @"\", setup.EntityRepository.GetContainingFolder(file));
        }
Exemplo n.º 14
0
        public void Session_DeleteNonContainerFile()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();
            var contents = "Test File Content";
            var file = IoHiveTestSetupHelper.CreateFile(contents);

            setup.EntityRepository.AddOrUpdate(file);

            Assert.IsTrue(System.IO.File.Exists(file.RootedPath));

            //Act
            setup.EntityRepository.Delete<File>(file.Id);

            //Assert
            Assert.IsFalse(System.IO.File.Exists(file.RootedPath));
        }
Exemplo n.º 15
0
        public void Session_UpdateNonContainerEntity()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();
            var contents = "Test File Content";
            var file = IoHiveTestSetupHelper.CreateFile(contents);

            setup.EntityRepository.AddOrUpdate(file);

            //Act
            file = setup.EntityRepository.Get<File>(file.Id);
            contents = "Updated file content";
            file.ContentBytes = Encoding.Default.GetBytes(contents);
            setup.EntityRepository.AddOrUpdate(file);

            //Assert
            Assert.IsNotNull(file.Id);
            var physicalFiles = setup.TestDirectory.GetFiles(file.Name);
            Assert.AreEqual(1, physicalFiles.Count());

            var physicalFile = physicalFiles[0];
            using (var reader = physicalFile.OpenText())
            {
                Assert.AreEqual(contents, reader.ReadToEnd());
            }
        }
Exemplo n.º 16
0
        public void Session_DeeplySpecifiedId_WillBeResolvedFromId()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            var actualFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();

            //Act
            var file = setup.EntityRepository.Get<File>(setup.EntityRepository.GenerateId(actualFile.FullName));

            //Assert
            Assert.IsNotNull(file);
            Assert.AreEqual(actualFile.Name, file.Name);
        }
Exemplo n.º 17
0
        public void Session_DeleteContainerEntity()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            var file = IoHiveTestSetupHelper.CreateFile(string.Empty);

            setup.EntityRepository.AddOrUpdate(file);

            Assert.IsTrue(System.IO.Directory.Exists(file.RootedPath));

            //Act
            setup.EntityRepository.Delete<File>(file.Id);

            //Assert
            Assert.IsFalse(System.IO.Directory.Exists(file.RootedPath));
        }
Exemplo n.º 18
0
        private static HiveManager GetHiveForTest()
        {
            var nhibernateTestSetup = new NhibernateTestSetupHelper();

            var storageProvider = new IoHiveTestSetupHelper(nhibernateTestSetup.FakeFrameworkContext);


            var hive =
                new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                nhibernateTestSetup.ReadonlyProviderSetup,
                                nhibernateTestSetup.ProviderSetup,
                                nhibernateTestSetup.FakeFrameworkContext),
                            storageProvider.CreateGroup("uploader", "storage://")
                        },
                    nhibernateTestSetup.FakeFrameworkContext);

            return hive;
        }
Exemplo n.º 19
0
        public void Session_RootLevelEntity_ParentIsNull()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            //Act
            var existingFile = setup.TestDirectory;
            var file = setup.EntityRepository.Get<File>(new HiveId(existingFile.FullName));

            //Assert
            var relationById = setup.EntityRepository.GetParentRelations(file.Id, FixedRelationTypes.DefaultRelationType).FirstOrDefault();
            Assert.IsNull(relationById);
            var relation = setup.EntityRepository.GetLazyParentRelations(file.Id, FixedRelationTypes.DefaultRelationType).FirstOrDefault();
            Assert.IsNull(relation);
            var relationByIdViaProxy = file.RelationProxies.AllParentRelations();
            Assert.That(relationByIdViaProxy.Count(), Is.EqualTo(0));
        }
        public void Integration_WhenEntityIsAdded_EnsureUniqueNameTask_RenamesItemIfNotUnique()
        {
            IHiveManager hive = null;
            try
            {
                var nhibernateTestSetup = new NhibernateTestSetupHelper(useNhProf:true);

                var storageProvider = new IoHiveTestSetupHelper(nhibernateTestSetup.FakeFrameworkContext);

                hive = new HiveManager(
                        new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                nhibernateTestSetup.ReadonlyProviderSetup,
                                nhibernateTestSetup.ProviderSetup,
                                nhibernateTestSetup.FakeFrameworkContext),
                            storageProvider.CreateGroup("uploader", "storage://file-uploader"),
                        },
                        nhibernateTestSetup.FakeFrameworkContext);


                SetupContentTest(hive);

                hive.FrameworkContext.TaskManager.AddTask(TaskTriggers.Hive.Revisions.PreAddOrUpdateOnUnitComplete,
                                          () => new EnsureUniqueNameTask(hive.FrameworkContext),
                                          true);

                hive.Cms().NewContentType("test-for-dupes")
                    .Define("sometext", "singleLineTextBox", "tab1")
                    .Commit();

                var parent = hive.Cms().NewRevision("My site root", "root", "test-for-dupes")
                    .SetValue("sometext", "hallow")
                    .Publish()
                    .Commit();

                var firstItem = hive.Cms().NewRevision("My Name", "my-name", "test-for-dupes")
                    .SetValue("sometext", "hallow")
                    .SetParent(parent.Item)
                    .Publish()
                    .Commit();

                var firstUnDupedItem = hive.Cms().NewRevision("My Name Unpublished", "my-name-unpublished", "test-for-dupes")
                    .SetValue("sometext", "hallow")
                    .SetParent(parent.Item)
                    .Publish()
                    .Commit();

                var shouldBeModified = hive.Cms().NewRevision("My Name", "my-name", "test-for-dupes")
                    .SetValue("sometext", "hallow")
                    .SetParent(parent.Item)
                    .Publish()
                    .Commit();

                var shouldBeModified2 = hive.Cms().NewRevision("My Name", "my-name", "test-for-dupes")
                    .SetValue("sometext", "hallow")
                    .SetParent(parent.Item)
                    .Publish()
                    .Commit();

                Assert.That(shouldBeModified.Success, Is.True);
                Assert.That(firstItem.Item.Id, Is.Not.EqualTo(shouldBeModified.Item.Id));
                Assert.That(firstItem.Item.Id, Is.Not.EqualTo(shouldBeModified2.Item.Id));
                Assert.That(shouldBeModified.Item.Id, Is.Not.EqualTo(shouldBeModified2.Item.Id));

                hive.Context.GenerationScopedCache.Clear();

                var queryForName = hive.Cms().QueryContent().Where(x => x.InnerAttribute<string>(NodeNameAttributeDefinition.AliasValue, "Name") == "My Name").ToList();
                Assert.That(queryForName.Count, Is.EqualTo(1));

                hive.Context.GenerationScopedCache.Clear();

                using(var uow = hive.OpenReader<IContentStore>())
                {
                    var checkFirstItem = uow.Repositories.Get(firstItem.Item.Id);
                    var checkRenamedItem = uow.Repositories.Get(shouldBeModified.Item.Id);
                    var checkRenamedItem2 = uow.Repositories.Get(shouldBeModified2.Item.Id);

                    var firstItemName = checkFirstItem.Attributes[NodeNameAttributeDefinition.AliasValue].Values["Name"];
                    var checkRenamedItemName = checkRenamedItem.Attributes[NodeNameAttributeDefinition.AliasValue].Values["Name"];
                    var checkRenamedItemName2 = checkRenamedItem2.Attributes[NodeNameAttributeDefinition.AliasValue].Values["Name"];

                    Assert.That(firstItemName, Is.Not.EqualTo(checkRenamedItemName));
                    Assert.That(firstItemName, Is.Not.EqualTo(checkRenamedItemName2));
                    Assert.That(checkRenamedItemName, Is.Not.EqualTo(checkRenamedItemName2));
                    Assert.That(checkRenamedItemName, Is.EqualTo("My Name (1)"));
                    Assert.That(checkRenamedItemName2, Is.EqualTo("My Name (2)"));

                    var firstItemUrlName = checkFirstItem.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"];
                    var checkRenamedItemUrlName = checkRenamedItem.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"];
                    var checkRenamedItemUrlName2 = checkRenamedItem2.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"];

                    Assert.That(firstItemUrlName, Is.Not.EqualTo(checkRenamedItemUrlName));
                    Assert.That(firstItemUrlName, Is.Not.EqualTo(checkRenamedItemUrlName2));
                    Assert.That(checkRenamedItemUrlName, Is.Not.EqualTo(checkRenamedItemUrlName2));
                    Assert.That(checkRenamedItemUrlName, Is.EqualTo("my-name-1"));
                    Assert.That(checkRenamedItemUrlName2, Is.EqualTo("my-name-2"));
                }
            }
            finally
            {
                hive.IfNotNull(x => x.Dispose());
            }
            
        }
Exemplo n.º 21
0
        public void Session_GetParent_ReturnsContainer()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            var someFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var someFileInfo = new FileInfo(someFile.FullName);
            var parentFolder = someFileInfo.Directory;

            //Act
            var fileId = setup.EntityRepository.GenerateId(someFile.FullName);
            var file = setup.EntityRepository.Get<File>(fileId);
            var parents = setup.EntityRepository.GetLazyParentRelations(fileId);

            // Assert
            Assert.AreEqual(1, parents.Count(), "No parent found for " + someFile.FullName + " with id " + fileId.ToString());
            Assert.AreEqual(parentFolder.FullName.NormaliseDirectoryPath(), ((File)parents.First().Source).RootedPath.NormaliseDirectoryPath());
        }
Exemplo n.º 22
0
        public void Session_GetRelations_VerboseOverload_CanObtainParents_DefaultRelationType()
        {
            //Arrange
            var setup = new IoHiveTestSetupHelper();

            var actualFile = setup.TestDirectory.GetFiles("*.dll", SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(setup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var parentFolder = actualFile.Directory;

            //Act
            var file = setup.EntityRepository.Get<File>(setup.EntityRepository.GenerateId(actualFile.FullName));
            var parents = setup.EntityRepository.GetLazyRelations(file, Direction.Parents, FixedRelationTypes.DefaultRelationType);

            //Assert
            // Check for iterator block mistakes
            Assert.AreEqual(parents.Count(), parents.ToList().Count());
            Assert.GreaterOrEqual(1, parents.Count());
            Assert.AreEqual(parentFolder.FullName.NormaliseDirectoryPath(), ((File)parents.First().Source).RootedPath.NormaliseDirectoryPath());
        }
Exemplo n.º 23
0
        public void Setup()
        {
            // Setup Hive
            _nhibernateTestSetup = new NhibernateTestSetupHelper(useNhProf: true);

            var storageProvider = new IoHiveTestSetupHelper(_nhibernateTestSetup.FakeFrameworkContext);

            Hive =
                new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test",
                                new WildcardUriMatch("content://"),
                                _nhibernateTestSetup.ReadonlyProviderSetup,
                                _nhibernateTestSetup.ProviderSetup,
                                _nhibernateTestSetup.FakeFrameworkContext),
                            storageProvider.CreateGroup("uploader", "storage://")
                        },
                    _nhibernateTestSetup.FakeFrameworkContext);

            // Setup Schemas
            Hive.Cms()
                .UsingStore<IContentStore>()
                .NewSchema("homepageSchema")
                .Define(NodeNameAttributeDefinition.AliasValue, NodeNameAttributeType.AliasValue, "tab1")
                .Define(SelectedTemplateAttributeDefinition.AliasValue, SelectedTemplateAttributeType.AliasValue, "tab1")
                .Define("siteName", "system-string-type", "tab1")
                .Define("siteDescription", "system-string-type", "tab1")
                .Define("bodyText", "system-long-string-type", "tab2")
                .Commit();

            Hive.Cms()
                .UsingStore<IContentStore>()
                .NewSchema("textpageSchema")
                .Define(NodeNameAttributeDefinition.AliasValue, NodeNameAttributeType.AliasValue, "tab1")
                .Define(SelectedTemplateAttributeDefinition.AliasValue, SelectedTemplateAttributeType.AliasValue, "tab1")
                .Define("bodyText", "system-long-string-type", "tab1")
                .Commit();

            Hive.Cms()
                .UsingStore<IContentStore>()
                .NewSchema("complexpageSchema")
                .Define(NodeNameAttributeDefinition.AliasValue, NodeNameAttributeType.AliasValue, "tab1")
                .Define(SelectedTemplateAttributeDefinition.AliasValue, SelectedTemplateAttributeType.AliasValue, "tab1")
                .Define("color", "system-string-type", "tab1")
                .Define("integer", "system-integer-type", "tab1")
                .Define("date", "system-date-time-type", "tab1")
                .Define("bodyText", "system-long-string-type", "tab1")
                .Commit();

            // Setup Content with a specific DateTime
            _fixedDate = DateTime.Now.Subtract(TimeSpan.FromMinutes(5));
            _homePage = Hive.Cms().NewRevision("Home", "home", "homepageSchema")
                .SetSelectedTemplate(new HiveId("storage", "templates", new HiveIdValue("/homepageTemplate.cshtml")))
                .SetValue("siteName", "Test Site Name")
                .SetValue("siteDescription", "Test Site Description")
                .SetValue("bodyText", "<p>Test Site Body Text</p>")
                .Publish();

            _homePage.Revision.Item.UtcCreated = _fixedDate;
            _homePage.Revision.MetaData.UtcStatusChanged = _fixedDate;
            _homePage.Commit();

            for (var i = 0; i < 5; i++)
            {
                // Create child
                var child = Hive.Cms().NewRevision("Child" + i, "child-" + i, "textpageSchema")
                    .SetSelectedTemplate(new HiveId("storage", "templates", new HiveIdValue("/textpageTemplate.cshtml")))
                    .SetParent(_homePage.Item)
                    .SetValue("bodyText",
                              "<p>Child Content " + i + " Revision 1 " + Guid.NewGuid().ToString() + " " +
                              Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " +
                              Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
                    .Publish()
                    .Commit();

                // Create revisions
                //for (var j = 0; j < i; j++)
                //{
                //    Hive.Cms().NewRevisionOf(child.Item)
                //        .SetValue("bodyText", "<p>Child Content " + i + " Revision " + (j + 2) + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
                //        .Publish()
                //        .Commit();

                //}

                //if (i < 3)
                //{
                //    for (var j = 0; j < 6; j++)
                //    {
                //        // Create grand child
                //        var grandChild = Hive.Cms().NewRevision("Grand Child" + j, "grand-child-" + j, "textpageSchema")
                //            .SetParent(child.Item)
                //            .SetValue("bodyText", "<p>Grand Child Content " + j + " Revision 1 " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
                //            .Publish()
                //            .Commit();

                //        // Create revisions
                //        for (var k = 0; k < j; k++)
                //        {
                //            Hive.Cms().NewRevisionOf(grandChild.Item)
                //                .SetValue("bodyText", "<p>Grand Child Content " + j + " Revision " + (k + 2) + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
                //                .Publish()
                //                .Commit();

                //        }

                //        if (j < 2)
                //        {
                //            // Create great grand children
                //            for (var k = 0; k < 10; k++)
                //            {
                //                var greatGrandChild =
                //                    Hive.Cms().NewRevision("Great Grand Child" + k, "great-grand-child-" + k,
                //                                           "complexpageSchema")
                //                        .SetParent(grandChild.Item)
                //                        .SetValue("color", "#0000" + k.ToString() + k.ToString())
                //                        .SetValue("integer", k)
                //                        .SetValue("date", DateTimeOffset.Now.AddDays(k))
                //                        .SetValue("bodyText",
                //                                  "<p>Great Grand Child Content " + k + " Revision 1 " +
                //                                  Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " +
                //                                  Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " +
                //                                  Guid.NewGuid().ToString() + " the end.</p>")
                //                        .Publish()
                //                        .Commit();

                //                // Create revisions
                //                for (var l = 0; l < k; l++)
                //                {
                //                    Hive.Cms().NewRevisionOf(greatGrandChild.Item)
                //                        .SetValue("bodyText", "<p>Great Grand Child Content " + k + " Revision " + (l + 2) + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
                //                        .Publish()
                //                        .Commit();

                //                }

                //                if (k >= 8)
                //                {
                //                    // Create unpublished revisions
                //                    Hive.Cms().NewRevisionOf(greatGrandChild.Item)
                //                            .SetValue("bodyText", "<p>Great Grand Child Content " + k + " Unpublished Revision " + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
                //                            .Commit();
                //                }
                //            }
                //        }
                //    }
                //}
            }

            //for(var i = 0; i < 2; i++)
            //{
            //    var trashChild = Hive.Cms().NewRevision("Trash Child" + i, "trash-child-" + i, "textpageSchema")
            //        .SetParent(FixedHiveIds.ContentRecylceBin)
            //        .SetValue("bodyText", "<p>Trash Child Content " + i + " Revision 1 " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " " + Guid.NewGuid().ToString() + " the end.</p>")
            //        .Publish()
            //        .Commit();
            //}
        }
Exemplo n.º 24
0
        public void FileProvider_ViaManager_GetRelations_DefaultRelationType()
        {
            // Arrange
            var ioTestSetup = new IoHiveTestSetupHelper();
            var unitFactory = new ProviderUnitFactory(ioTestSetup.EntityRepositoryFactory);
            var readonlyUnitFactory = new ReadonlyProviderUnitFactory(ioTestSetup.EntityRepositoryFactory);
            var provider = new ProviderSetup(unitFactory, ioTestSetup.ProviderMetadata, null, null, 0);
            var readonlyProvider = new ReadonlyProviderSetup(readonlyUnitFactory, ioTestSetup.ProviderMetadata, null, null, 0);

            var providerMappingGroup = new ProviderMappingGroup("default", new WildcardUriMatch("storage://*"), readonlyProvider, provider, ioTestSetup.FrameworkContext);

            var manager = new HiveManager(new[] { providerMappingGroup }, ioTestSetup.FrameworkContext);

            var actualFile = ioTestSetup.TestDirectory.GetFiles(ioTestSetup.Settings.SupportedExtensions, SearchOption.AllDirectories)
                .Where(x => x.FullName.Replace(ioTestSetup.Settings.AbsoluteRootedPath, string.Empty).Contains(@"\"))
                .Last();
            var parentFolder = actualFile.Directory;

            // Act
            using (var store = manager.OpenReader<IFileStore>())
            {
                var file = store.Repositories.Get<File>(new HiveId(actualFile.FullName));
                var parentRelations = store.Repositories.GetParentRelations(file.Id, FixedRelationTypes.DefaultRelationType);
                var parentsViaHandyMethod = store.Repositories.GetParentFileRelations(file);
                var firstParentRelation = store.Repositories.Get<File>(parentRelations.First().SourceId);

                //Assert
                // Check for iterator block mistakes
                Assert.That(parentRelations, Is.EquivalentTo(parentsViaHandyMethod));
                Assert.That(parentRelations.Count(), Is.GreaterThanOrEqualTo(1));
                Assert.AreEqual(parentFolder.FullName.NormaliseDirectoryPath(), firstParentRelation.RootedPath.NormaliseDirectoryPath());
            }
        }