Пример #1
0
        public static Content CreateSimpleContent(IContentType contentType)
        {
            var content = new Content("Home", -1, contentType) { Language = "en-US", Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0 };
            object obj =
                new
                    {
                        title = "Welcome to our Home page",
                        bodyText = "This is the welcome message on the first page",
                        author = "John Doe"
                    };

            content.PropertyValues(obj);

            return content;
        }
Пример #2
0
		public static Content CreateSimpleContent(IContentType contentType, string name, IContent parent)
		{
			var content = new Content(name, parent, contentType) { Language = "en-US", CreatorId = 0, WriterId = 0 };
			object obj =
				new
				{
					title = name + " Subpage",
					bodyText = "This is a subpage",
					author = "John Doe"
				};

			content.PropertyValues(obj);

			return content;
		}
Пример #3
0
        public static Content CreateTextpageContent(IContentType contentType, string name, int parentId)
        {
            var content = new Content(name, parentId, contentType) { Language = "en-US", CreatorId = 0, WriterId = 0};
            object obj =
                new
                {
                    title = name + " textpage",
                    bodyText = string.Format("This is a textpage based on the {0} ContentType", contentType.Alias),
                    keywords = "text,page,meta",
                    metaDescription = "This is the meta description for a textpage"
                };

            content.PropertyValues(obj);

            return content;
        }
Пример #4
0
        public static IEnumerable<Content> CreateTextpageContent(IContentType contentType, int parentId, int amount)
        {
            var list = new List<Content>();

            for (int i = 0; i < amount; i++)
            {
                var name = "Textpage No-" + i;
                var content = new Content(name, parentId, contentType) { Language = "en-US", CreatorId = 0, WriterId = 0 };
                object obj =
                    new
                    {
                        title = name + " title",
                        bodyText = string.Format("This is a textpage based on the {0} ContentType", contentType.Alias),
                        keywords = "text,page,meta",
                        metaDescription = "This is the meta description for a textpage"
                    };

                content.PropertyValues(obj);
                list.Add(content);
            }

            return list;
        }
Пример #5
0
        public void Can_Update_Variation_Of_Element_Type_Property()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                ContentTypeRepository repository;
                var contentRepository = CreateRepository((IScopeAccessor)provider, out repository);

                // Create elementType
                var elementType = new ContentType(-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("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", SortOrder = 1
                });
                elementType.ResetDirtyProperties(false);
                elementType.SetDefaultTemplate(new Template("ElementType", "elementType"));
                repository.Save(elementType);

                // Create the basic "home" doc type that uses element type as comp
                var docType = new ContentType(-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 = ServiceContext.ContentService.GetById(content.Id);
                var hasCulture     = renewedContent.Properties["title"].Values.First().Culture != null;
                Assert.That(hasCulture, Is.True);
            }
        }
        public void Validate_Data_Upgrade()
        {
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            ContentTypeRepository contentTypeRepository;
            var insertedContent = new List<IContent>();
            using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
            {
                //we need to populate some data to upgrade
                var contentTypeWith1Tag = MockedContentTypes.CreateSimpleContentType(
                    "tags1", "tags1",
                    new PropertyTypeCollection(new[]
                        {
                            new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags1", Name = "tags1", SortOrder = 1, DataTypeDefinitionId = 1041},
                        }));
                var contentTypeWith2Tags = MockedContentTypes.CreateSimpleContentType(
                    "tags2", "tags2",
                    new PropertyTypeCollection(new[]
                        {
                            new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags1", Name = "tags1", SortOrder = 1, DataTypeDefinitionId = 1041},
                            new PropertyType("test", DataTypeDatabaseType.Ntext) {Alias = "tags2", Name = "tags2", SortOrder = 1, DataTypeDefinitionId = 1041}
                        }));

                contentTypeRepository.AddOrUpdate(contentTypeWith1Tag);
                contentTypeRepository.AddOrUpdate(contentTypeWith2Tags);
                unitOfWork.Commit();

                for (var i = 0; i < 10; i++)
                {
                    var content = new Content("test" + i, -1, contentTypeWith1Tag) { Language = "en-US", CreatorId = 0, WriterId = 0 };
                    var obj = new
                        {
                            tags1 = "tag1,tag2,tag3,tag4,tag5"                            
                        };
                    content.PropertyValues(obj);
                    content.ResetDirtyProperties(false);
                    insertedContent.Add(content);
                    repository.AddOrUpdate(content);
                }
                for (var i = 0; i < 10; i++)
                {
                    var content = new Content("test-multi" + i, -1, contentTypeWith2Tags) { Language = "en-US", CreatorId = 0, WriterId = 0 };
                    var obj = new
                    {
                        //NOTE: These will always be the same during an upgrade since we can only support tags per document not per property
                        tags1 = "tag1,tag2,tag3,anothertag1,anothertag2",
                        tags2 = "tag1,tag2,tag3,anothertag1,anothertag2"
                    };
                    content.PropertyValues(obj);
                    content.ResetDirtyProperties(false);
                    insertedContent.Add(content);
                    repository.AddOrUpdate(content);
                }
                unitOfWork.Commit();
            }
            //now that we have to create some test tag data
            foreach (var tag in "tag1,tag2,tag3,tag4,tag5,anothertag1,anothertag2".Split(','))
            {
                DatabaseContext.Database.Insert(new TagDto {Tag = tag, Group = "default"});
            }
            var alltags = DatabaseContext.Database.Fetch<TagDto>("SELECT * FROM cmsTags").ToArray();
            foreach (var content in insertedContent)
            {
                if (content.ContentType.Alias == "tags1")
                {
                    var tags1Tags = alltags.Where(x => "tag1,tag2,tag3,tag4,tag5".Split(',').Contains(x.Tag));
                    foreach (var t in tags1Tags)
                    {
                        DatabaseContext.Database.Insert(new TagRelationshipDto {NodeId = content.Id, TagId = t.Id});
                    }                    
                }
                else
                {
                    var tags1Tags = alltags.Where(x => "tag1,tag2,tag3,anothertag1,anothertag2".Split(',').Contains(x.Tag));
                    foreach (var t in tags1Tags)
                    {
                        DatabaseContext.Database.Insert(new TagRelationshipDto { NodeId = content.Id, TagId = t.Id });
                    }   
                }
            }
            
            //lastly, we'll insert a tag relation with a relation to only an umbracoNode - 
            // this will generate a delete clause and a warning
            DatabaseContext.Database.Insert(new TagRelationshipDto { NodeId = -1, TagId = alltags.First().Id });


            var migration = new AlterTagRelationsTable();
            var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, DatabaseContext.Database);
            migration.GetUpExpressions(migrationContext);

            Assert.AreEqual(
                (10 * 5) //the docs that only have 1 tag prop per document
                + (10 * 5) //the docs that have 2 tag prop per document - these are the update statements
                + (10 * 5) //the docs that have 2 tag prop per document - these are the insert statements
                + 1//the delete clause
                + 7 , //additional db expressions
                migrationContext.Expressions.Count);
        }