Exemplo n.º 1
0
        public void Can_Perform_Query_On_ContentTypeRepository_Sort_By_Name()
        {
            IContentType contentType;

            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;
                contentType = repository.Get(_textpageContentType.Id);
                ContentType child1 = ContentTypeBuilder.CreateSimpleContentType("abc", "abc", contentType, randomizeAliases: true, defaultTemplateId: 0);
                repository.Save(child1);
                ContentType child3 = ContentTypeBuilder.CreateSimpleContentType("zyx", "zyx", contentType, randomizeAliases: true, defaultTemplateId: 0);
                repository.Save(child3);
                ContentType child2 = ContentTypeBuilder.CreateSimpleContentType("a123", "a123", contentType, randomizeAliases: true, defaultTemplateId: 0);
                repository.Save(child2);

                scope.Complete();
            }

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                // Act
                IEnumerable <IContentType> contentTypes = repository.Get(scope.SqlContext.Query <IContentType>().Where(x => x.ParentId == contentType.Id));

                // Assert
                Assert.That(contentTypes.Count(), Is.EqualTo(3));
                Assert.AreEqual("a123", contentTypes.ElementAt(0).Name);
                Assert.AreEqual("abc", contentTypes.ElementAt(1).Name);
                Assert.AreEqual("zyx", contentTypes.ElementAt(2).Name);
            }
        }
Exemplo n.º 2
0
        public void Can_Perform_Delete_With_Heirarchy_On_ContentTypeRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;
                ContentType           ctMain     = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: 0);
                ContentType           ctChild1   = ContentTypeBuilder.CreateSimpleContentType("child1", "Child 1", ctMain, randomizeAliases: true, defaultTemplateId: 0);
                ContentType           ctChild2   = ContentTypeBuilder.CreateSimpleContentType("child2", "Child 2", ctChild1, randomizeAliases: true, defaultTemplateId: 0);

                repository.Save(ctMain);
                repository.Save(ctChild1);
                repository.Save(ctChild2);

                // Act
                IContentType resolvedParent = repository.Get(ctMain.Id);
                repository.Delete(resolvedParent);

                // Assert
                Assert.That(repository.Exists(ctMain.Id), Is.False);
                Assert.That(repository.Exists(ctChild1.Id), Is.False);
                Assert.That(repository.Exists(ctChild2.Id), Is.False);
            }
        }
Exemplo n.º 3
0
        public void Can_Verify_AllowedChildContentTypes_On_ContentType()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                ContentType subpageContentType       = ContentTypeBuilder.CreateSimpleContentType("umbSubpage", "Subpage");
                ContentType simpleSubpageContentType = ContentTypeBuilder.CreateSimpleContentType("umbSimpleSubpage", "Simple Subpage");
                repository.Save(subpageContentType);
                repository.Save(simpleSubpageContentType);

                // Act
                IContentType contentType = repository.Get(_simpleContentType.Id);
                contentType.AllowedContentTypes = new List <ContentTypeSort>
                {
                    new ContentTypeSort(new Lazy <int>(() => subpageContentType.Id), 0, subpageContentType.Alias),
                    new ContentTypeSort(new Lazy <int>(() => simpleSubpageContentType.Id), 1, simpleSubpageContentType.Alias)
                };
                repository.Save(contentType);

                // Assert
                IContentType updated = repository.Get(_simpleContentType.Id);

                Assert.That(updated.AllowedContentTypes.Any(), Is.True);
                Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == subpageContentType.Alias), Is.True);
                Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == simpleSubpageContentType.Alias), Is.True);
            }
        }
Exemplo n.º 4
0
        public void Can_Perform_Delete_When_Assigned_To_Doc()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var templateRepository = CreateRepository(ScopeProvider);

                var tagRepository         = new TagRepository((IScopeAccessor)ScopeProvider, AppCaches.Disabled, Logger);
                var contentTypeRepository = new ContentTypeRepository((IScopeAccessor)ScopeProvider, AppCaches.Disabled, Logger, templateRepository);
                var languageRepository    = new LanguageRepository((IScopeAccessor)ScopeProvider, AppCaches.Disabled, Logger);
                var contentRepo           = new DocumentRepository((IScopeAccessor)ScopeProvider, AppCaches.Disabled, Logger, contentTypeRepository, templateRepository, tagRepository, languageRepository);

                var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
                ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
                contentTypeRepository.Save(contentType);
                var textpage = MockedContent.CreateSimpleContent(contentType);
                contentRepo.Save(textpage);

                var template = new Template("test", "test")
                {
                    Content = @"<%@ Master Language=""C#"" %>"
                };
                templateRepository.Save(template);

                textpage.TemplateId = template.Id;
                contentRepo.Save(textpage);

                // Act
                var templates = templateRepository.Get("test");
                templateRepository.Delete(templates);

                // Assert
                Assert.IsNull(templateRepository.Get("test"));
            }
        }
Exemplo n.º 5
0
        public void Maps_Templates_Correctly()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var templateRepo = new TemplateRepository((IScopeAccessor)provider, AppCaches.Disabled, LoggerFactory.CreateLogger <TemplateRepository>(), FileSystems, IOHelper, ShortStringHelper, Mock.Of <IViewHelper>());
                ContentTypeRepository repository = ContentTypeRepository;
                Template[]            templates  = new[]
                {
                    new Template(ShortStringHelper, "test1", "test1"),
                    new Template(ShortStringHelper, "test2", "test2"),
                    new Template(ShortStringHelper, "test3", "test3")
                };
                foreach (Template template in templates)
                {
                    templateRepo.Save(template);
                }

                ContentType contentType = ContentTypeBuilder.CreateSimpleContentType();
                contentType.AllowedTemplates = new[] { templates[0], templates[1] };
                contentType.SetDefaultTemplate(templates[0]);
                repository.Save(contentType);

                // re-get
                IContentType result = repository.Get(contentType.Id);

                Assert.AreEqual(2, result.AllowedTemplates.Count());
                Assert.AreEqual(templates[0].Id, result.DefaultTemplate.Id);
            }
        }
Exemplo n.º 6
0
        public void Can_Perform_Update_On_ContentTypeRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                // Act
                IContentType contentType = repository.Get(_textpageContentType.Id);

                contentType.Thumbnail = "Doc2.png";
                contentType.PropertyGroups["content"].PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "subtitle")
                {
                    Name        = "Subtitle",
                    Description = "Optional Subtitle",
                    Mandatory   = false,
                    SortOrder   = 1,
                    DataTypeId  = -88,
                    LabelOnTop  = true
                });
                repository.Save(contentType);

                bool dirty = contentType.IsDirty();

                // Assert
                Assert.That(contentType.HasIdentity, Is.True);
                Assert.That(dirty, Is.False);
                Assert.That(contentType.Thumbnail, Is.EqualTo("Doc2.png"));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True);
                Assert.That(contentType.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop, Is.True);
            }
        }
Exemplo n.º 7
0
        public void Can_Verify_Usage_Of_New_PropertyType_On_Content()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                IContentType contentType = repository.Get(_textpageContentType.Id);

                Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                DocumentRepository.Save(subpage);

                PropertyGroup propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
                propertyGroup.PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "metaAuthor")
                {
                    Name = "Meta Author", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88
                });
                repository.Save(contentType);

                // Act
                IContent content = DocumentRepository.Get(subpage.Id);
                content.SetValue("metaAuthor", "John Doe");
                DocumentRepository.Save(content);

                // Assert
                IContent updated = DocumentRepository.Get(subpage.Id);
                Assert.That(updated.GetValue("metaAuthor").ToString(), Is.EqualTo("John Doe"));
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True);
            }
        }
Exemplo n.º 8
0
        public void Can_Move()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;
                var container1 = new EntityContainer(Constants.ObjectTypes.DocumentType)
                {
                    Name = "blah1"
                };
                DocumentTypeContainerRepository.Save(container1);

                var container2 = new EntityContainer(Constants.ObjectTypes.DocumentType)
                {
                    Name = "blah2", ParentId = container1.Id
                };
                DocumentTypeContainerRepository.Save(container2);

                var contentType = (IContentType)ContentTypeBuilder.CreateBasicContentType("asdfasdf");
                contentType.ParentId = container2.Id;
                repository.Save(contentType);

                // create a
                var contentType2 = (IContentType) new ContentType(ShortStringHelper, contentType, "hello")
                {
                    Name = "Blahasdfsadf"
                };
                contentType.ParentId = contentType.Id;
                repository.Save(contentType2);

                global::Umbraco.Cms.Core.Events.MoveEventInfo <IContentType>[] result = repository.Move(contentType, container1).ToArray();

                Assert.AreEqual(2, result.Count());

                // re-get
                contentType  = repository.Get(contentType.Id);
                contentType2 = repository.Get(contentType2.Id);

                Assert.AreEqual(container1.Id, contentType.ParentId);
                Assert.AreNotEqual(result.Single(x => x.Entity.Id == contentType.Id).OriginalPath, contentType.Path);
                Assert.AreNotEqual(result.Single(x => x.Entity.Id == contentType2.Id).OriginalPath, contentType2.Path);
            }
        }
Exemplo n.º 9
0
        public void Can_Perform_Add_On_ContentTypeRepository_After_Model_Mapping()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                // Act
                var contentType = (IContentType)ContentTypeBuilder.CreateSimpleContentType2("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup");

                Assert.AreEqual(4, contentType.PropertyTypes.Count());

                // remove all templates - since they are not saved, they would break the (!) mapping code
                contentType.AllowedTemplates = new ITemplate[0];

                // there is NO mapping from display to contentType, but only from save
                // to contentType, so if we want to test, let's to it properly!
                DocumentTypeDisplay display = Mapper.Map <DocumentTypeDisplay>(contentType);
                DocumentTypeSave    save    = MapToContentTypeSave(display);
                IContentType        mapped  = Mapper.Map <IContentType>(save);

                Assert.AreEqual(4, mapped.PropertyTypes.Count());

                repository.Save(mapped);

                Assert.AreEqual(4, mapped.PropertyTypes.Count());

                // re-get
                contentType = repository.Get(mapped.Id);

                Assert.AreEqual(4, contentType.PropertyTypes.Count());

                // Assert
                Assert.That(contentType.HasIdentity, Is.True);
                Assert.That(contentType.PropertyGroups.All(x => x.HasIdentity), Is.True);
                Assert.That(contentType.PropertyTypes.All(x => x.HasIdentity), Is.True);
                Assert.That(contentType.Path.Contains(","), Is.True);
                Assert.That(contentType.SortOrder, Is.GreaterThan(0));

                Assert.That(contentType.PropertyGroups.ElementAt(0).Name == "testGroup", Is.True);
                int groupId = contentType.PropertyGroups.ElementAt(0).Id;

                IPropertyType[] propertyTypes = contentType.PropertyTypes.ToArray();
                Assert.AreEqual("gen", propertyTypes[0].Alias); // just to be sure
                Assert.IsNull(propertyTypes[0].PropertyGroupId);
                Assert.IsTrue(propertyTypes.Skip(1).All(x => x.PropertyGroupId.Value == groupId));
                Assert.That(propertyTypes.Single(x => x.Alias == "title").LabelOnTop, Is.True);
            }
        }
        public void Can_Perform_Delete_When_Assigned_To_Doc()
        {
            // Arrange
            IScopeProvider   provider        = ScopeProvider;
            var              scopeAccessor   = (IScopeAccessor)provider;
            IDataTypeService dataTypeService = GetRequiredService <IDataTypeService>();
            IFileService     fileService     = GetRequiredService <IFileService>();

            using (provider.CreateScope())
            {
                ITemplateRepository templateRepository = CreateRepository(provider);
                var globalSettings         = new GlobalSettings();
                var serializer             = new JsonNetSerializer();
                var tagRepository          = new TagRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <TagRepository>());
                var commonRepository       = new ContentTypeCommonRepository(scopeAccessor, templateRepository, AppCaches, ShortStringHelper);
                var languageRepository     = new LanguageRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <LanguageRepository>(), Microsoft.Extensions.Options.Options.Create(globalSettings));
                var contentTypeRepository  = new ContentTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <ContentTypeRepository>(), commonRepository, languageRepository, ShortStringHelper);
                var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <RelationTypeRepository>());
                var entityRepository       = new EntityRepository(scopeAccessor, AppCaches.Disabled);
                var relationRepository     = new RelationRepository(scopeAccessor, LoggerFactory.CreateLogger <RelationRepository>(), relationTypeRepository, entityRepository);
                var propertyEditors        = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty <IDataEditor>()));
                var dataValueReferences    = new DataValueReferenceFactoryCollection(() => Enumerable.Empty <IDataValueReferenceFactory>());
                var contentRepo            = new DocumentRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger <DocumentRepository>(), LoggerFactory, contentTypeRepository, templateRepository, tagRepository, languageRepository, relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, dataTypeService, serializer, Mock.Of <IEventAggregator>());

                Template template = TemplateBuilder.CreateTextPageTemplate();
                fileService.SaveTemplate(template); // else, FK violation on contentType!

                ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage2", "Textpage", defaultTemplateId: template.Id);
                contentTypeRepository.Save(contentType);

                Content textpage = ContentBuilder.CreateSimpleContent(contentType);
                contentRepo.Save(textpage);

                textpage.TemplateId = template.Id;
                contentRepo.Save(textpage);

                // Act
                ITemplate templates = templateRepository.Get("textPage");
                templateRepository.Delete(templates);

                // Assert
                Assert.IsNull(templateRepository.Get("textPage"));
            }
        }
Exemplo n.º 11
0
        public void Can_Create_Container_Containing_Media_Types()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;
                var container = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah"
                };
                MediaTypeContainerRepository.Save(container);

                ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup", defaultTemplateId: 0);
                contentType.ParentId = container.Id;
                repository.Save(contentType);

                Assert.AreEqual(container.Id, contentType.ParentId);
            }
        }
Exemplo n.º 12
0
        public void Can_Perform_Get_By_Guid_On_ContentTypeRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository       = ContentTypeRepository;
                IContentType          contentType      = repository.Get(_textpageContentType.Id);
                ContentType           childContentType = ContentTypeBuilder.CreateSimpleContentType("blah", "Blah", contentType, randomizeAliases: true, defaultTemplateId: 0);
                repository.Save(childContentType);

                // Act
                IContentType result = repository.Get(childContentType.Key);

                // Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Id, Is.EqualTo(childContentType.Id));
            }
        }
Exemplo n.º 13
0
        public void Can_Perform_Delete_When_Assigned_To_Doc()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                var templateRepository = CreateRepository(ScopeProvider);

                var tagRepository          = new TagRepository(ScopeProvider, AppCaches.Disabled, Logger);
                var commonRepository       = new ContentTypeCommonRepository(ScopeProvider, templateRepository, AppCaches);
                var languageRepository     = new LanguageRepository(ScopeProvider, AppCaches.Disabled, Logger);
                var contentTypeRepository  = new ContentTypeRepository(ScopeProvider, AppCaches.Disabled, Logger, commonRepository, languageRepository);
                var relationTypeRepository = new RelationTypeRepository(ScopeProvider, AppCaches.Disabled, Logger);
                var entityRepository       = new EntityRepository(ScopeProvider);
                var relationRepository     = new RelationRepository(ScopeProvider, Logger, relationTypeRepository, entityRepository);
                var propertyEditors        = new Lazy <PropertyEditorCollection>(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty <IDataEditor>())));
                var dataValueReferences    = new DataValueReferenceFactoryCollection(Enumerable.Empty <IDataValueReferenceFactory>());
                var contentRepo            = new DocumentRepository(ScopeProvider, AppCaches.Disabled, Logger, contentTypeRepository, templateRepository, tagRepository, languageRepository, relationRepository, relationTypeRepository, propertyEditors, dataValueReferences);

                var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
                ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
                contentTypeRepository.Save(contentType);
                var textpage = MockedContent.CreateSimpleContent(contentType);
                contentRepo.Save(textpage);

                var template = new Template("test", "test")
                {
                    Content = @"<%@ Master Language=""C#"" %>"
                };
                templateRepository.Save(template);

                textpage.TemplateId = template.Id;
                contentRepo.Save(textpage);

                // Act
                var templates = templateRepository.Get("test");
                templateRepository.Delete(templates);

                // Assert
                Assert.IsNull(templateRepository.Get("test"));
            }
        }
Exemplo n.º 14
0
        public void Can_Verify_That_A_Combination_Of_Adding_And_Deleting_PropertyTypes_Doesnt_Cause_Issues_For_Content_And_ContentType()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                IContentType contentType = repository.Get(_textpageContentType.Id);

                Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                DocumentRepository.Save(subpage);

                // Remove PropertyType
                contentType.RemovePropertyType("keywords");

                // Add PropertyType
                PropertyGroup propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
                propertyGroup.PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "metaAuthor")
                {
                    Name = "Meta Author", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88
                });
                repository.Save(contentType);

                // Act
                IContent content = DocumentRepository.Get(subpage.Id);
                content.SetValue("metaAuthor", "John Doe");
                DocumentRepository.Save(content);

                // Assert
                IContent updated = DocumentRepository.Get(subpage.Id);
                Assert.That(updated.GetValue("metaAuthor").ToString(), Is.EqualTo("John Doe"));
                Assert.That(updated.Properties.First(x => x.Alias == "description").GetValue(), Is.EqualTo("This is the meta description for a textpage"));

                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(4));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True);
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "keywords"), Is.False);
            }
        }
Exemplo n.º 15
0
        public void Can_Verify_PropertyType_With_No_Group()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository  = ContentTypeRepository;
                IContentType          contentType = repository.Get(_textpageContentType.Id);

                Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(2));
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(4));

                // Act
                var urlAlias = new PropertyType(ShortStringHelper, "test", ValueStorageType.Nvarchar, "urlAlias")
                {
                    Name        = "Url Alias",
                    Description = string.Empty,
                    Mandatory   = false,
                    SortOrder   = 1,
                    DataTypeId  = -88
                };

                bool addedPropertyType = contentType.AddPropertyType(urlAlias);

                Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(2));
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5));

                repository.Save(contentType);

                // Assert
                IContentType updated = repository.Get(_textpageContentType.Id);
                Assert.That(addedPropertyType, Is.True);
                Assert.That(updated.PropertyGroups.Count, Is.EqualTo(2));
                Assert.That(updated.PropertyTypes.Count(), Is.EqualTo(5));
                Assert.That(updated.PropertyTypes.Any(x => x.Alias == "urlAlias"), Is.True);
                Assert.That(updated.PropertyTypes.First(x => x.Alias == "urlAlias").PropertyGroupId, Is.Null);
            }
        }
Exemplo n.º 16
0
        public void Can_Update_ContentType_With_PropertyType_Removed()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository  = ContentTypeRepository;
                IContentType          contentType = repository.Get(_textpageContentType.Id);

                // Act
                contentType.PropertyGroups["meta"].PropertyTypes.Remove("description");
                repository.Save(contentType);

                IContentType result = repository.Get(_textpageContentType.Id);

                // Assert
                Assert.That(result.PropertyTypes.Any(x => x.Alias == "description"), Is.False);
                Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(result.PropertyGroups.Count));
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(result.PropertyTypes.Count()));
            }
        }
Exemplo n.º 17
0
        public void Can_Perform_Delete_On_ContentTypeRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                // Act
                ContentType contentType = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: 0);
                repository.Save(contentType);

                IContentType contentType2 = repository.Get(contentType.Id);
                repository.Delete(contentType2);

                bool exists = repository.Exists(contentType.Id);

                // Assert
                Assert.That(exists, Is.False);
            }
        }
Exemplo n.º 18
0
        public void Can_Verify_Removal_Of_Used_PropertyType_From_ContentType()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository  = ContentTypeRepository;
                IContentType          contentType = repository.Get(_textpageContentType.Id);

                Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                DocumentRepository.Save(subpage);

                // Act
                contentType.RemovePropertyType("keywords");
                repository.Save(contentType);

                // Assert
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(3));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "keywords"), Is.False);
                Assert.That(subpage.Properties.First(x => x.Alias == "description").GetValue(), Is.EqualTo("This is the meta description for a textpage"));
            }
        }
Exemplo n.º 19
0
        public static IList<ContentType> CreateTestContentTypes()
        {
            List<ContentType> results = new List<ContentType>();

            ContentTypeRepository repo = new ContentTypeRepository();

            ContentType item = new ContentType()
            {
                Text = "text"
            };

            results.Add(item);
            repo.Add(item);

            item = new ContentType()
            {
                Text = "html"
            };

            results.Add(item);
            repo.Add(item);

            item = new ContentType()
            {
                Text = "xhtml"
            };

            results.Add(item);
            repo.Add(item);

            repo.Save();

            return results;
        }
Exemplo n.º 20
0
        public void Can_Update_Variation_Of_Element_Type_Property()
        {
            var provider = ScopeProvider;

            using (var scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;
                var contentRepository            = DocumentRepository;

                // Create elementType
                var elementType = new ContentType(ShortStringHelper, -1)
                {
                    Alias       = "elementType",
                    Name        = "Element type",
                    Description = "Element type to use as compositions",
                    Icon        = ".sprTreeDoc3",
                    Thumbnail   = "doc.png",
                    SortOrder   = 1,
                    CreatorId   = 0,
                    Trashed     = false,
                    IsElement   = true,
                    Variations  = ContentVariation.Nothing
                };

                var contentCollection = new PropertyTypeCollection(true);
                contentCollection.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext)
                {
                    Alias       = "title",
                    Name        = "Title",
                    Description = "",
                    Mandatory   = false,
                    SortOrder   = 1,
                    DataTypeId  = Constants.DataTypes.Textbox,
                    LabelOnTop  = true,
                    Variations  = ContentVariation.Nothing
                });
                elementType.PropertyGroups.Add(new PropertyGroup(contentCollection)
                {
                    Name = "Content", Alias = "content", SortOrder = 1
                });
                elementType.ResetDirtyProperties(false);
                elementType.SetDefaultTemplate(new Template(ShortStringHelper, "ElementType", "elementType"));
                repository.Save(elementType);

                // Create the basic "home" doc type that uses element type as comp
                var docType = new ContentType(ShortStringHelper, -1)
                {
                    Alias       = "home",
                    Name        = "Home",
                    Description = "Home containing elementType",
                    Icon        = ".sprTreeDoc3",
                    Thumbnail   = "doc.png",
                    SortOrder   = 1,
                    CreatorId   = 0,
                    Trashed     = false,
                    Variations  = ContentVariation.Nothing
                };
                var comp = new List <IContentTypeComposition>();
                comp.Add(elementType);
                docType.ContentTypeComposition = comp;
                repository.Save(docType);

                // Create "home" content
                var content = new Content("Home", -1, docType)
                {
                    Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0
                };
                object obj = new { title = "test title" };
                content.PropertyValues(obj);
                content.ResetDirtyProperties(false);
                contentRepository.Save(content);

                // Update variation on element type
                elementType.Variations = ContentVariation.Culture;
                elementType.PropertyTypes.First().Variations = ContentVariation.Culture;
                repository.Save(elementType);

                // Update variation on doc type
                docType.Variations = ContentVariation.Culture;
                repository.Save(docType);

                // Re fetch renewedContent and make sure that the culture has been set.
                var renewedContent = ContentService.GetById(content.Id);
                var hasCulture     = renewedContent.Properties["title"].Values.First().Culture != null;
                Assert.That(hasCulture, Is.True);
            }
        }
Exemplo n.º 21
0
        public void Can_Perform_Update_On_ContentTypeRepository_After_Model_Mapping()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                ContentTypeRepository repository = ContentTypeRepository;

                // Act
                IContentType contentType = repository.Get(_textpageContentType.Id);

                // there is NO mapping from display to contentType, but only from save
                // to contentType, so if we want to test, let's to it properly!
                DocumentTypeDisplay display = Mapper.Map <DocumentTypeDisplay>(contentType);
                DocumentTypeSave    save    = MapToContentTypeSave(display);

                // modify...
                save.Thumbnail = "Doc2.png";
                PropertyGroupBasic <PropertyTypeBasic> contentGroup = save.Groups.Single(x => x.Name == "Content");
                contentGroup.Properties = contentGroup.Properties.Concat(new[]
                {
                    new PropertyTypeBasic
                    {
                        Alias       = "subtitle",
                        Label       = "Subtitle",
                        Description = "Optional Subtitle",
                        Validation  = new PropertyTypeValidation
                        {
                            Mandatory = false,
                            Pattern   = string.Empty
                        },
                        SortOrder  = 1,
                        DataTypeId = -88,
                        LabelOnTop = true
                    }
                });

                IContentType mapped = Mapper.Map(save, contentType);

                // just making sure
                Assert.AreEqual(mapped.Thumbnail, "Doc2.png");
                Assert.IsTrue(mapped.PropertyTypes.Any(x => x.Alias == "subtitle"));
                Assert.IsTrue(mapped.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop);

                repository.Save(mapped);

                bool dirty = mapped.IsDirty();

                // re-get
                contentType = repository.Get(_textpageContentType.Id);

                // Assert
                Assert.That(contentType.HasIdentity, Is.True);
                Assert.That(dirty, Is.False);
                Assert.That(contentType.Thumbnail, Is.EqualTo("Doc2.png"));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True);

                Assert.That(contentType.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop, Is.True);

                foreach (IPropertyType propertyType in contentType.PropertyTypes)
                {
                    Assert.IsTrue(propertyType.HasIdentity);
                    Assert.Greater(propertyType.Id, 0);
                }
            }
        }