internal object Flatten(string itemUrl, CustomTypedEntity <Content> typedEntity) { Dictionary <string, object> properties = ExtractProperties(typedEntity); IEnumerable <HiveId> children = typedEntity.AllChildIds(); List <string> childrenUrls = children .Select(child => _hiveManager.Cms().Content.GetById(child)) .Select(entity => entity.NiceUrl()) .ToList(); return(new { id = itemUrl, UtcCreated = ConvertDateTime(typedEntity.UtcCreated), UtcModified = ConvertDateTime(typedEntity.UtcModified), UtcStatusChanged = ConvertDateTime(typedEntity.UtcStatusChanged), properties, children = childrenUrls }); }
public void CreateContentType() { AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); // Ensure parent exists for this test Hive.AutoCommitTo <IContentStore>(x => x.Repositories.Schemas.AddOrUpdate(new ContentRootSchema())); var doctype = Hive.Cms().NewContentType <EntitySchema, IContentStore>("newsItem") .Define("title", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Commit(); if (doctype.Errors.Any()) { Assert.Fail(doctype.Errors.FirstOrDefault().ToString()); } Assert.True(doctype.Success); Assert.NotNull(doctype.Item); ClearCaches(); var schemaReloaded = HighLevelApiFixture.AssertSchemaPartExists <EntitySchema, IContentStore>(Hive, doctype.Item.Id); }
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 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(); //} }
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 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(); //} }
public void StringQueryByName() { // Act var whereNodes = Hive.Cms().Content.Where <Content>("Name == @0", "Child0"); var singleNode = Hive.Cms().Content.Single <Content>("Name == @0", "Child1"); var singleDefaultNode = Hive.Cms().Content.SingleOrDefault <Content>("Name == @0", "Child2"); var firstNode = Hive.Cms().Content.First <Content>("Name == @0", "Child3"); var firstDefaultNode = Hive.Cms().Content.FirstOrDefault <Content>("Name == @0", "Child4"); // Assert Assert.AreEqual(1, whereNodes.Count()); Assert.AreEqual("Child0", whereNodes.First().Name); Assert.IsNotNull(singleNode); Assert.AreEqual("Child1", singleNode.Name); Assert.IsNotNull(singleDefaultNode); Assert.AreEqual("Child2", singleDefaultNode.Name); Assert.IsNotNull(firstNode); Assert.AreEqual("Child3", firstNode.Name); Assert.IsNotNull(firstDefaultNode); Assert.AreEqual("Child4", firstDefaultNode.Name); }