public void SchemaBuilder_CanCreateEntitySchema_WithAttributeTypeAndGroupSubBuilders() { AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); var schema = Hive .NewSchema <EntitySchema, IContentStore>("mySchema") .Define("title", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Define("bodyText", type => type.UseExistingType("richTextEditor"), FixedGroupDefinitions.GeneralGroup) .Define("extraBodyText", type => type.UseExistingType("richTextEditor"), FixedGroupDefinitions.GeneralGroup) .Commit(); if (schema.Errors.Any()) { Assert.Fail(schema.Errors.FirstOrDefault().ToString()); } Assert.True(schema.Success); Assert.NotNull(schema.Item); ClearCaches(); var schemaReloaded = AssertSchemaPartExists <EntitySchema, IContentStore>(Hive, schema.Item.Id); Assert.That(schemaReloaded.AttributeDefinitions.Any()); Assert.That(schemaReloaded.AttributeDefinitions.Count(), Is.EqualTo(3)); Assert.That(schemaReloaded.AttributeDefinitions[0].Alias, Is.EqualTo("title")); Assert.NotNull(schemaReloaded.AttributeDefinitions["title"]); Assert.NotNull(schemaReloaded.AttributeDefinitions[0].AttributeType); Assert.That(schemaReloaded.AttributeDefinitions[0].AttributeType.Alias, Is.EqualTo("singleLineTextBox")); Assert.That(schemaReloaded.AttributeDefinitions[1].AttributeType.Alias, Is.EqualTo("richTextEditor")); Assert.That(schemaReloaded.AttributeDefinitions[2].AttributeType.Alias, Is.EqualTo("richTextEditor")); }
protected virtual void Init() { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); FrameworkContext = new FakeFrameworkContext(); var hive = CreateHiveManager(); RebelApplicationContext = CreateApplicationContext(hive); var resolverContext = new MockedMapResolverContext(FrameworkContext, hive, new MockedPropertyEditorFactory(RebelApplicationContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); FrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(FrameworkContext) })); DevDataset = DemoDataHelper.GetDemoData(RebelApplicationContext, attributeTypeRegistry); FixedPropertyEditors = new FixedPropertyEditors(RebelApplicationContext); //ensure model binders ModelBinders.Binders.Remove(typeof(HiveId)); ModelBinders.Binders.Add(typeof(HiveId), new HiveIdModelBinder()); ModelBinders.Binders.Remove(typeof(DocumentTypeEditorModel)); ModelBinders.Binders.Add(typeof(DocumentTypeEditorModel), new DocumentTypeModelBinder()); ModelBinders.Binders.Remove(typeof(SizeModelBinder)); ModelBinders.Binders.Add(typeof(SizeModelBinder), new SizeModelBinder()); //set the model meta data provider ModelMetadataProviders.Current = new RebelModelMetadataProvider(); }
public void Can_Iterate_Over_Multi_Value_Property() { AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); SetupContentTest(); // Make a new content type with a listBox var doctype = HiveManager.Cms <IContentStore>() .NewContentType("newsItem") .Define("newsTypes", "listBox", "tab1") .Commit(); // Make a new revision without specifying properties var vals = new[] { "option1", "option2" }; var firstRev = HiveManager.Cms().NewRevision("article", "article", "newsItem") .SetValue("newsTypes", vals[0], "val0") //select option1 .SetValue("newsTypes", vals[1], "val1") //select option2 .Publish() .Commit(); var bent = new Content(firstRev.Item).Bend(HiveManager, MembershipService, PublicAccessService); Assert.NotNull(bent); Assert.AreEqual(2, Enumerable.Count(bent.newsTypes)); for (var i = 0; i < Enumerable.Count(bent.newsTypes); i++) { //we don't know the order that the values get saved, so we'll just check with contains //Assert.Contains(vals[i], bent.newsTypes); var val = Enumerable.ElementAt(bent.newsTypes, i).Value; Assert.That(vals.Any(x => val == x)); } }
public void SchemaPartBuilder_CanCreateAttributeTypes_UsingCurrentRegistry() { AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); var innerBuilder = new BuilderStarter <AttributeType, IContentStore>(Hive); var type = innerBuilder.UseExistingType("richTextEditor"); Assert.NotNull(type); Assert.That(type.Item, Is.Not.Null); }
private void RunTest( HiveManager hiveManager, FakeFrameworkContext frameworkContext, Action installCallback = null) { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); var appContext = new FakeUmbracoApplicationContext(hiveManager, false); var mockedPropertyEditorFactory = new MockedPropertyEditorFactory(appContext); var resolverContext = new MockedMapResolverContext(frameworkContext, hiveManager, mockedPropertyEditorFactory, new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(frameworkContext) })); var devDataset = DemoDataHelper.GetDemoData(appContext, attributeTypeRegistry); //Seup permissions var permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), new CopyPermission(), new MovePermission() } .Select(x => new Lazy <Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary <string, object> { { "Id", x.Id }, { "Name", x.Name }, { "Type", x.Type } }))).ToArray(); var coreDataInstallTask = new EnsureCoreDataTask(frameworkContext, hiveManager, permissions); var devDatasetInstallTask = new DevDatasetInstallTask(frameworkContext, mockedPropertyEditorFactory, hiveManager, attributeTypeRegistry); //Act coreDataInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } devDatasetInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } //Assert var totalSchemaCount = CoreCmsData.RequiredCoreSchemas().Count() + devDataset.DocTypes.Count() + 1; // +1 for SystemRoot schema var totalEntityCount = CoreCmsData.RequiredCoreUserGroups(permissions).Count() + CoreCmsData.RequiredCoreRootNodes().Count() + devDataset.ContentData.Count(); var totalAttributeTypeCount = CoreCmsData.RequiredCoreSystemAttributeTypes().Count() + CoreCmsData.RequiredCoreUserAttributeTypes().Count(); DoCoreAssertions(hiveManager, totalSchemaCount, totalEntityCount, totalAttributeTypeCount, 2, permissions); }
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); }); }
public override void Boot(RouteCollection routes) { base.Boot(routes); //we requrie that a custom GlobalFilter is added so see if it is there: if (!GlobalFilters.Filters.ContainsFilter <ProxyableResultAttribute>()) { GlobalFilters.Filters.Add(new ProxyableResultAttribute()); } routes.RegisterArea(_installRegistration); //register all component areas foreach (var c in _componentAreas) { routes.RegisterArea(c); } //IMPORTANT: We need to register the Rebel area after the components because routes overlap. // For example, a surface controller might have a url of: // /Rebel/MyPackage/Surface/MySurface // and because the default action is 'Index' its not required to be there, however this same route // matches the default Rebel back office route of Rebel/{controller}/{action}/{id} // so we want to make sure that the plugin routes are matched first routes.RegisterArea(_areaRegistration); //ensure that the IAttributeTypeRegistry is set AttributeTypeRegistry.SetCurrent(_attributeTypeRegistry); //register validation extensions DataAnnotationsModelValidatorProviderExtensions.RegisterValidationExtensions(); LocalizationWebConfig.RegisterRoutes(routes, _settings.RebelPaths.LocalizationPath); //If this is outside of an ASP.Net application (i.e. Unit test) and RegisterVirtualPathProvider is called then an exception is thrown. if (HostingEnvironment.IsHosted) { HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedViewVirtualPathProvider()); HostingEnvironment.RegisterVirtualPathProvider(new CodeDelegateVirtualPathProvider()); } //register custom validation adapters DataAnnotationsModelValidatorProvider.RegisterAdapterFactory( typeof(HiveIdRequiredAttribute), (metadata, controllerContext, attribute) => new RequiredHiveIdAttributeAdapter(metadata, controllerContext, (HiveIdRequiredAttribute)attribute)); }
public void BeforeTest() { _nhibernateTestSetup = new NhibernateTestSetupHelper(useNhProf: true); var storageProvider = new IoHiveTestSetupHelper(_nhibernateTestSetup.FakeFrameworkContext); Hive = new HiveManager( new[] { new ProviderMappingGroup( "test1", new WildcardUriMatch("content://"), _nhibernateTestSetup.ReadonlyProviderSetup, _nhibernateTestSetup.ProviderSetup, _nhibernateTestSetup.FakeFrameworkContext), new ProviderMappingGroup( "test2", new WildcardUriMatch("security://members"), _nhibernateTestSetup.ReadonlyProviderSetup, _nhibernateTestSetup.ProviderSetup, _nhibernateTestSetup.FakeFrameworkContext), storageProvider.CreateGroup("uploader", "storage://") }, _nhibernateTestSetup.FakeFrameworkContext); var appContext = new FakeRebelApplicationContext(Hive, true); AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); var task = new EnsureCoreDataTask(Hive.FrameworkContext, Hive, Enumerable.Empty <Lazy <Permission, PermissionMetadata> >(), null); task.InstallOrUpgrade(); Provider = new MembersMembershipProvider(Hive, appContext); Provider.Initialize("MembersMembershipProvider", new NameValueCollection()); }
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 Create_Dynamic_Search_With_Results() { AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); // Ensure parent exists for this test Hive.AutoCommitTo <IContentStore>(x => x.Repositories.Schemas.AddOrUpdate(new ContentRootSchema())); // Create schema var schema1 = Hive.Cms().NewContentType <EntitySchema, IContentStore>("homePage") .Define("pageTitle", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Define("pageContent", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Commit(); var schema2 = Hive.Cms().NewContentType <EntitySchema, IContentStore>("contentPage") .Define("pageTitle", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Define("pageContent", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Commit(); Assert.True(schema1.Success); Assert.True(schema2.Success); var item1 = new Content(); item1.SetupFromSchema(schema1.Item); item1.Id = new HiveId(Guid.NewGuid()); item1["pageTitle"] = "Hello There"; item1["pageContent"] = "some page content"; var item2 = new Content(); item2.SetupFromSchema(schema2.Item); item2.Id = new HiveId(Guid.NewGuid()); item2["pageTitle"] = "Title 1"; item2["pageContent"] = "this is some page content. hi, hello, goodbye."; var item3 = new Content(); item3.SetupFromSchema(schema1.Item); item3.Id = new HiveId(Guid.NewGuid()); item3["pageTitle"] = "Another page"; item3["pageContent"] = "Say hello to my little friend."; var writerResult = Hive.AutoCommitTo <IContentStore>(x => { x.Repositories.AddOrUpdate(item1); x.Repositories.AddOrUpdate(item2); x.Repositories.AddOrUpdate(item3); }); Assert.True(writerResult.WasCommitted); AddRevision(item1, FixedStatusTypes.Published); AddRevision(item2, FixedStatusTypes.Published); AddRevision(item3, FixedStatusTypes.Published); // Check can get the items normally using (var uow = Hive.OpenReader <IContentStore>()) { Assert.True(uow.Repositories.Exists <Content>(item1.Id)); Assert.True(uow.Repositories.Exists <Content>(item2.Id)); Assert.True(uow.Repositories.Exists <Content>(item3.Id)); } //Create a dynamic search var docTypes = new[] { "homePage", "contentPage" }; var fields = new[] { "pageTitle", "pageContent" }; var searchTerm = "hello"; using (var uow = GroupUnitFactory.Create()) { var predicate = ExpressionExtensions.False <TypedEntity>(); var query = uow.Repositories.Query(); foreach (var d in docTypes) { //this will add an 'AND' clause, not an 'OR' clause //query = query.Where(x => x.EntitySchema.Alias == d); var d1 = d; predicate = predicate.Or(x => x.EntitySchema.Alias == d1); } foreach (var f in fields) { //this will add an 'AND' clause, not an 'OR' clause //query = query.Where(x => x.Attribute<string>(f) == searchTerm); var f1 = f; predicate = predicate.Or(x => x.Attribute <string>(f1) == searchTerm); } var result = query.Where(predicate).ToArray(); Assert.AreEqual(3, result.Count()); } }
public void WhenTypedEntity_QueriedWithStringEquals_AndOrderBy_ResultsAreOrdered() { var item1Id = Guid.NewGuid(); var item2Id = Guid.NewGuid(); var item3Id = Guid.NewGuid(); var parentId = Guid.NewGuid(); AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry()); // Ensure parent exists for this test Hive.AutoCommitTo <IContentStore>(x => x.Repositories.Schemas.AddOrUpdate(new ContentRootSchema())); // Create schema var schema = Hive.Cms().NewContentType <EntitySchema, IContentStore>("withTitle") .Define("title", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Define("random", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Define("tag", type => type.UseExistingType("singleLineTextBox"), FixedGroupDefinitions.GeneralGroup) .Define("bodyText", type => type.UseExistingType("richTextEditor"), FixedGroupDefinitions.GeneralGroup) .Commit(); Assert.True(schema.Success); var item1 = new Content(); item1.SetupFromSchema(schema.Item); item1.Id = new HiveId(item1Id); item1["title"] = "Item1"; item1["random"] = "Random3"; item1["tag"] = "apple"; var item2 = new Content(); item2.SetupFromSchema(schema.Item); item2.Id = new HiveId(item2Id); item2["title"] = "Item2"; item2["random"] = "Random1"; item2["tag"] = "blueberry"; var item3 = new Content(); item3.SetupFromSchema(schema.Item); item3.Id = new HiveId(item3Id); item3["title"] = "Item3"; item3["random"] = "Random2"; item3["tag"] = "apple"; var writerResult = Hive.AutoCommitTo <IContentStore>(x => { x.Repositories.AddOrUpdate(item1); x.Repositories.AddOrUpdate(item2); x.Repositories.AddOrUpdate(item3); }); Assert.True(writerResult.WasCommitted); // Check can get the items normally using (var uow = Hive.OpenReader <IContentStore>()) { Assert.True(uow.Repositories.Exists <Content>(item1.Id)); Assert.True(uow.Repositories.Exists <Content>(item2.Id)); Assert.True(uow.Repositories.Exists <Content>(item3.Id)); } // query all with sortorder - first check is actually order of insertion anyway var allQuery_NaturalSort = Hive.QueryContent().OrderBy(x => x.Attribute <string>("title")).ToArray(); Assert.That(allQuery_NaturalSort.Any()); Assert.That(allQuery_NaturalSort[0]["title"], Is.EqualTo("Item1")); Assert.That(allQuery_NaturalSort[1]["title"], Is.EqualTo("Item2")); Assert.That(allQuery_NaturalSort[2]["title"], Is.EqualTo("Item3")); var allQuerySortByTag = Hive.QueryContent().OrderBy(x => x.Attribute <string>("tag")).ToArray(); Assert.That(allQuerySortByTag.Any()); Assert.That(allQuerySortByTag[0]["tag"], Is.EqualTo("apple")); Assert.That(allQuerySortByTag[0]["random"], Is.EqualTo("Random3").Or.EqualTo("Random2")); Assert.That(allQuerySortByTag[1]["tag"], Is.EqualTo("apple")); Assert.That(allQuerySortByTag[1]["random"], Is.EqualTo("Random3").Or.EqualTo("Random2")); Assert.That(allQuerySortByTag[2]["tag"], Is.EqualTo("blueberry")); Assert.That(allQuerySortByTag[2]["random"], Is.EqualTo("Random1")); var allQuerySortByTagThenRandom = Hive.QueryContent().OrderBy(x => x.Attribute <string>("tag")).ThenBy(x => x.Attribute <string>("random")).ToArray(); Assert.That(allQuerySortByTagThenRandom.Any()); Assert.That(allQuerySortByTagThenRandom[0]["tag"], Is.EqualTo("apple")); Assert.That(allQuerySortByTagThenRandom[0]["random"], Is.EqualTo("Random2")); Assert.That(allQuerySortByTagThenRandom[1]["tag"], Is.EqualTo("apple")); Assert.That(allQuerySortByTagThenRandom[1]["random"], Is.EqualTo("Random3")); Assert.That(allQuerySortByTagThenRandom[2]["tag"], Is.EqualTo("blueberry")); Assert.That(allQuerySortByTagThenRandom[2]["random"], Is.EqualTo("Random1")); // query invoking the executesingle methods var firstByTagDescending = Hive.QueryContent().OrderByDescending(x => x.Attribute <string>("tag")).FirstOrDefault(); Assert.NotNull(firstByTagDescending); Assert.That(firstByTagDescending["tag"], Is.EqualTo("blueberry")); var singleByTagDescending = Hive.QueryContent().OrderByDescending(x => x.Attribute <string>("tag")).SingleOrDefault(x => x.Attribute <string>("random") == "Random2"); Assert.NotNull(singleByTagDescending); Assert.That(singleByTagDescending["tag"], Is.EqualTo("apple")); }
private void RunTest( HiveManager hiveManager, FakeFrameworkContext frameworkContext, Action installCallback = null) { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); var appContext = new FakeRebelApplicationContext(hiveManager, false); var mockedPropertyEditorFactory = new MockedPropertyEditorFactory(appContext); var resolverContext = new MockedMapResolverContext(frameworkContext, hiveManager, mockedPropertyEditorFactory, new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(frameworkContext) })); var devDataset = DemoDataHelper.GetDemoData(appContext, attributeTypeRegistry); //Setup permissions var permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), new CopyPermission(), new MovePermission() } .Select(x => new Lazy <Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary <string, object> { { "Id", x.Id }, { "Name", x.Name }, { "Type", x.Type }, { "UserType", x.UserType } }))).ToArray(); //Setup security service var usersMembershipProvider = new UsersMembershipProvider { AppContext = appContext }; usersMembershipProvider.Initialize("UsersMembershipProvider", new NameValueCollection()); var usersMembershipService = new MembershipService <User, UserProfile>(frameworkContext, hiveManager, "security://user-profiles", "security://user-groups", Framework.Security.Model.FixedHiveIds.UserProfileVirtualRoot, usersMembershipProvider, Enumerable.Empty <MembershipProviderElement>()); ResetMembershipProvider(usersMembershipService.MembershipProvider); var membersMembershipProvider = new MembersMembershipProvider { AppContext = appContext }; membersMembershipProvider.Initialize("MembersMembershipProvider", new NameValueCollection()); var membersMembershipService = new MembershipService <Member, MemberProfile>(frameworkContext, hiveManager, "security://member-profiles", "security://member-groups", Framework.Security.Model.FixedHiveIds.MemberProfileVirtualRoot, membersMembershipProvider, Enumerable.Empty <MembershipProviderElement>()); ResetMembershipProvider(membersMembershipService.MembershipProvider); var permissionService = new PermissionsService(hiveManager, permissions, usersMembershipService); var publicAccessService = new PublicAccessService(hiveManager, membersMembershipService, appContext.FrameworkContext); var securityService = new SecurityService(usersMembershipService, membersMembershipService, permissionService, publicAccessService); var coreDataInstallTask = new EnsureCoreDataTask(frameworkContext, hiveManager, permissions, securityService); //var devDatasetInstallTask = new DevDatasetInstallTask(frameworkContext, mockedPropertyEditorFactory, hiveManager, attributeTypeRegistry); //Act coreDataInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } //devDatasetInstallTask.InstallOrUpgrade(); //if (installCallback != null) installCallback(); //Assert var totalSchemaCount = CoreCmsData.RequiredCoreSchemas().Count() + devDataset.DocTypes.Count() + 1; // +1 for SystemRoot schema var totalEntityCount = CoreCmsData.RequiredCoreUserGroups(permissions).Count() + CoreCmsData.RequiredCoreRootNodes().Count() + devDataset.ContentData.Count(); var totalAttributeTypeCount = CoreCmsData.RequiredCoreSystemAttributeTypes().Count() + CoreCmsData.RequiredCoreUserAttributeTypes().Count(); DoCoreAssertions(hiveManager, totalSchemaCount, totalEntityCount, totalAttributeTypeCount, 2, permissions, securityService); //CoreCmsData.RequiredCoreUsers().ForEach( // x => // { // securityService.UsersMembershipService.DeleteUser(x.Username, true); // securityService.MembersMembershipService.DeleteUser(x.Username, true); // }); ResetMembershipProvider(securityService.Users.MembershipProvider); ResetMembershipProvider(securityService.Members.MembershipProvider); }