Пример #1
0
        public static Content CreateAllTypesContent(IContentType contentType, string name, int parentId)
        {
            var content = new Content("Random Content Name", parentId, contentType) { Language = "en-US", Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0 };

            content.SetValue("isTrue", true);
            content.SetValue("number", 42);
            content.SetValue("bodyText", "Lorem Ipsum Body Text Test");
            content.SetValue("singleLineText", "Single Line Text Test");
            content.SetValue("multilineText", "Multiple lines \n in one box");
            content.SetValue("upload", "/media/1234/koala.jpg");
            content.SetValue("label", "Non-editable label");
            content.SetValue("dateTime", DateTime.Now.AddDays(-20));
            content.SetValue("colorPicker", "black");
            content.SetValue("folderBrowser", "");
            content.SetValue("ddlMultiple", "1234,1235");
            content.SetValue("rbList", "random");
            content.SetValue("date", DateTime.Now.AddDays(-10));
            content.SetValue("ddl", "1234");
            content.SetValue("chklist", "randomc");
            content.SetValue("contentPicker", 1090);
            content.SetValue("mediaPicker", 1091);
            content.SetValue("memberPicker", 1092);
            content.SetValue("simpleEditor", "This is simply edited");
            content.SetValue("ultimatePicker", "1234,1235");
            content.SetValue("relatedLinks", "<links><link title=\"google\" link=\"http://google.com\" type=\"external\" newwindow=\"0\" /></links>");
            content.SetValue("tags", "this,is,tags");
            content.SetValue("macroContainer", "");
            content.SetValue("imgCropper", "");

            return content;
        }
        public void ConnectionTest()
        {
            var unitOfWork = Global.CreateUnitOfWork();

            var repoFactory = new RepositoryFactory();

            var service = new ContentService(unitOfWork, repoFactory);
            var cTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                                     new ContentService(unitOfWork),
                                                                     new MediaService(unitOfWork, repoFactory));
            
            ContentType cType = new ContentType(-1);
            cType.Name = "TestType";
            cType.Alias = "TestType";
            cType.Thumbnail = string.Empty;

            cTypeService.Save(cType);

            Console.WriteLine("Ctype " + cType.Id);
            Assert.Greater(cType.Id, 0);

            Content content = new Content("METest", -1, cType);
            service.Save(content);

            Assert.Greater(content.Id, 0);

            var content2 = service.GetById(content.Id);
            Assert.AreEqual(content.Name, content2.Name);
        }
		public void General_RetrieveItemsAndFieldsFromUmbraco_ReturnPopulatedClass()
		{
			const string fieldValue = "test field value";
			const string name = "Target";
			const string contentTypeAlias = "TestType";
			const string contentTypeName = "Test Type";
			const string contentTypeProperty = "TestProperty";

            var context = WindsorContainer.GetContext();
			var loader = new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration");
			context.Load(loader);

			IContentType contentType = new ContentType(-1);
			contentType.Name = contentTypeName;
			contentType.Alias = contentTypeAlias;
			contentType.Thumbnail = string.Empty;
			ContentTypeService.Save(contentType);
			Assert.Greater(contentType.Id, 0);

			var definitions = DataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"));
			var firstDefinition = definitions.FirstOrDefault();
			DataTypeService.Save(firstDefinition);
			var propertyType = new PropertyType(firstDefinition)
				{
					Alias = contentTypeProperty
				};
			contentType.AddPropertyType(propertyType);
			ContentTypeService.Save(contentType);
			Assert.Greater(contentType.Id, 0);

			var content = new Content(name, -1, contentType);
			content.SetPropertyValue(contentTypeProperty, fieldValue);
			ContentService.Save(content);


            var umbracoService = new UmbracoService(ContentService, context);

			//Act
			var result = umbracoService.GetItem<AttributeStub>(content.Id);

			//Assert
			Assert.IsNotNull(result);
			Assert.AreEqual(fieldValue, result.TestProperty);
			Assert.AreEqual(content.Id, result.Id);
			Assert.AreEqual(content.Key, result.Key);
			Assert.AreEqual(name, result.Name);
			Assert.AreEqual(contentTypeName, result.ContentTypeName);
			Assert.AreEqual(content.ParentId + "," + content.Id, result.Path);
			Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias);
			Assert.AreEqual(content.Version, result.Version);
		}
Пример #4
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;
        }
Пример #5
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;
		}
Пример #6
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;
        }
Пример #7
0
        /// <summary>
        /// Creates an <see cref="IContent"/> object using the alias of the <see cref="IContentType"/>
        /// that this Content should based on.
        /// </summary>
        /// <remarks>
        /// Note that using this method will simply return a new IContent without any identity
        /// as it has not yet been persisted. It is intended as a shortcut to creating new content objects
        /// that does not invoke a save operation against the database.
        /// </remarks>
        /// <param name="name">Name of the Content object</param>
        /// <param name="parentId">Id of Parent for the new Content</param>
        /// <param name="contentTypeAlias">Alias of the <see cref="IContentType"/></param>
        /// <param name="userId">Optional id of the user creating the content</param>
        /// <returns><see cref="IContent"/></returns>
        public IContent CreateContent(string name, int parentId, string contentTypeAlias, int userId = 0)
        {
            var contentType = FindContentTypeByAlias(contentTypeAlias);
            var content = new Content(name, parentId, contentType);

            if (Creating.IsRaisedEventCancelled(new NewEventArgs<IContent>(content, contentTypeAlias, parentId), this))
            {
                content.WasCancelled = true;
                return content;
            }

            content.CreatorId = userId;
            content.WriterId = userId;

            Created.RaiseEvent(new NewEventArgs<IContent>(content, false, contentTypeAlias, parentId), this);

            Audit.Add(AuditTypes.New, string.Format("Content '{0}' was created", name), content.CreatorId, content.Id);

            return content;
        }
Пример #8
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;
        }
Пример #9
0
        public void CreateStub()
        {
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            var unitOfWork = Global.CreateUnitOfWork();
            var repoFactory = new RepositoryFactory();
            _contentService = new ContentService(unitOfWork, repoFactory);
            var contentTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                            new ContentService(unitOfWork),
                                                            new MediaService(unitOfWork, repoFactory));
            
            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.Key = new Guid("{263768E1-E958-4B00-BB00-191CC33A3F48}");
            _contentService.Save(content);
        }
        public void CreateStub()
        {
            string fieldValue = "test field value";
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            var unitOfWork = Global.CreateUnitOfWork();
            var repoFactory = new RepositoryFactory();
            _contentService = new ContentService(unitOfWork, repoFactory);
            var contentTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                            new ContentService(unitOfWork),
                                                            new MediaService(unitOfWork, repoFactory));
            var dataTypeService = new DataTypeService(unitOfWork, repoFactory);

            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"));
            dataTypeService.Save(definitions.FirstOrDefault());
            var propertyType = new PropertyType(definitions.FirstOrDefault());
            propertyType.Alias = "TestProperty";
            contentType.AddPropertyType(propertyType);
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.Key = new Guid("{5F6D851E-46C0-40C7-A93A-EC3F6D7EBA3E}");
            content.SetPropertyValue("TestProperty", fieldValue);
            _contentService.Save(content);
        }
        public void CreateStub()
        {
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            var unitOfWork = Global.CreateUnitOfWork();
            var repoFactory = new RepositoryFactory();
            _contentService = new ContentService(unitOfWork, repoFactory);
            var contentTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                            new ContentService(unitOfWork),
                                                            new MediaService(unitOfWork, repoFactory));

            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var parentContent = new Content(name, -1, contentType);
            parentContent.Key = new Guid("{373D1D1C-BD0D-4A8C-9A67-1D513815FE10}");
            _contentService.Save(parentContent);

            var content = new Content(name, parentContent.Id, contentType);
            content.Key = new Guid("{3F34475B-D744-40E9-BC30-5D33249FA9FE}");
            _contentService.Save(content);
        }
        public void Can_Perform_Delete_On_ContentRepository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            ContentTypeRepository contentTypeRepository;
            using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
            {
                var contentType = contentTypeRepository.Get(NodeDto.NodeIdSeed);
                var content = new Content("Textpage 2 Child Node", NodeDto.NodeIdSeed + 3, contentType);
                content.CreatorId = 0;
                content.WriterId = 0;

                // Act
                repository.AddOrUpdate(content);
                unitOfWork.Commit();
                var id = content.Id;

                var repository2 = RepositoryResolver.Current.ResolveByType<IContentRepository>(unitOfWork);
                repository2.Delete(content);
                unitOfWork.Commit();

                var content1 = repository2.Get(id);

                // Assert
                Assert.That(content1, Is.Null);
            }            
        }
Пример #13
0
        public void General_RetrieveContentAndPropertiesFromUmbraco_ReturnPopulatedClass()
        {
            //Assign
            string fieldValue = "test field value";
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";
            string contentTypeProperty = "TestProperty";

            var unitOfWork = Global.CreateUnitOfWork();
            var repoFactory = new RepositoryFactory();
            var contentService = new ContentService(unitOfWork, repoFactory);
            var contentTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                                     new ContentService(unitOfWork),
                                                                     new MediaService(unitOfWork, repoFactory));
            var dataTypeService = new DataTypeService(unitOfWork, repoFactory);
            var context = WindsorContainer.GetContext();

            var loader = new UmbracoFluentConfigurationLoader();
            var stubConfig = loader.Add<Stub>();
            stubConfig.Configure(x =>
            {
                x.Id(y => y.Id);
                x.Id(y => y.Key);
                x.Property(y => y.TestProperty);
                x.Info(y => y.Name).InfoType(UmbracoInfoType.Name);
                x.Info(y => y.ContentTypeName).InfoType(UmbracoInfoType.ContentTypeName);
                x.Info(y => y.ContentTypeAlias).InfoType(UmbracoInfoType.ContentTypeAlias);
                x.Info(y => y.Path).InfoType(UmbracoInfoType.Path);
                x.Info(y => y.Version).InfoType(UmbracoInfoType.Version);
                x.Info(y => y.CreateDate).InfoType(UmbracoInfoType.CreateDate);
                x.Info(y => y.UpdateDate).InfoType(UmbracoInfoType.UpdateDate);
                x.Info(y => y.Creator).InfoType(UmbracoInfoType.Creator);
            });

            context.Load(loader);

            IContentType contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

			var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"));
            dataTypeService.Save(definitions.FirstOrDefault());
            var propertyType = new PropertyType(definitions.FirstOrDefault());
            propertyType.Alias = contentTypeProperty;
            contentType.AddPropertyType(propertyType);
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.SetPropertyValue(contentTypeProperty, fieldValue);
            contentService.Save(content);

            var umbracoService = new UmbracoService(contentService, context);

            //Act
            var result = umbracoService.GetItem<Stub>(content.Id);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(fieldValue, result.TestProperty);
            Assert.AreEqual(content.Id, result.Id);
            Assert.AreEqual(content.Key, result.Key);
            Assert.AreEqual(name, result.Name);
            Assert.AreEqual(contentTypeName, result.ContentTypeName);
            Assert.AreEqual(content.ParentId + "," + content.Id, result.Path);
            Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias);
            Assert.AreEqual(content.Version, result.Version);
            Assert.AreEqual(content.CreateDate, result.CreateDate);
            Assert.AreEqual(content.UpdateDate, result.UpdateDate);
            Assert.AreEqual("admin", result.Creator);
        }
Пример #14
0
        /// <summary>
        /// Creates and saves an <see cref="IContent"/> object using the alias of the <see cref="IContentType"/>
        /// that this Content should based on.
        /// </summary>
        /// <remarks>
        /// This method returns an <see cref="IContent"/> object that has been persisted to the database
        /// and therefor has an identity.
        /// </remarks>
        /// <param name="name">Name of the Content object</param>
        /// <param name="parent">Parent <see cref="IContent"/> object for the new Content</param>
        /// <param name="contentTypeAlias">Alias of the <see cref="IContentType"/></param>
        /// <param name="userId">Optional id of the user creating the content</param>
        /// <returns><see cref="IContent"/></returns>
        public IContent CreateContentWithIdentity(string name, IContent parent, string contentTypeAlias, int userId = 0)
        {
            var contentType = FindContentTypeByAlias(contentTypeAlias);
            var content = new Content(name, parent, contentType);

            if (Creating.IsRaisedEventCancelled(new NewEventArgs<IContent>(content, contentTypeAlias, parent), this))
            {
                content.WasCancelled = true;
                return content;
            }

            var uow = _uowProvider.GetUnitOfWork();
            using (var repository = _repositoryFactory.CreateContentRepository(uow))
            {
                content.CreatorId = userId;
                content.WriterId = userId;
                repository.AddOrUpdate(content);
                uow.Commit();
            }

            Created.RaiseEvent(new NewEventArgs<IContent>(content, false, contentTypeAlias, parent), this);

            Audit.Add(AuditTypes.New, string.Format("Content '{0}' was created with Id {1}", name, content.Id), content.CreatorId, content.Id);

            return content;
        }
        public void CreateStub()
        {
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            _unitOfWork = Global.CreateUnitOfWork();
            _repoFactory = new RepositoryFactory();
            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var contentTypeService = new ContentTypeService(_unitOfWork, _repoFactory,
                                                            new ContentService(_unitOfWork),
                                                            new MediaService(_unitOfWork, _repoFactory));

            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.Key = new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}");
            contentService.Save(content);
            contentService.Publish(content);
        }
        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);
        }
        private void SetupContent(int parentId, List<string> log) {

            IContentTypeService cts = ApplicationContext.Current.Services.ContentTypeService;
            IContentService cs = ApplicationContext.Current.Services.ContentService;

            var contentDefinitions = new[] {
                new { parent = default(string), guid = SelfServiceConstants.Pages.Module, type = "SkySelfServiceModule", name = "Selvbetjening" },
                new { parent = "a3f0120e-ea17-4a6d-8355-2a66ccdb2cff", guid = SelfServiceConstants.Pages.Categories, type = "SkySelfServiceCategories", name = "Kategorier" },
                new { parent = "a3f0120e-ea17-4a6d-8355-2a66ccdb2cff", guid = SelfServiceConstants.Pages.ActionPages, type = "SkySelfServiceActionPages", name = "Handlingssider" }
            };

            foreach (var contentDefinition in contentDefinitions) {

                log.Add("Creating content node \"" + contentDefinition.name + "\"");

                Guid guid = Guid.Parse(contentDefinition.guid);

                IContent content = cs.GetById(guid);
                if (content != null) {
                    log.Add(" > Already exists with ID " + content.Id + " (GUID: " + content.Key + ")");
                    continue;
                }

                int pid = parentId;
                if (contentDefinition.parent != null) {
                    var parent = cs.GetById(Guid.Parse(contentDefinition.parent));
                    log.Add(" > Parent with GUID " + contentDefinition.parent + "not found");
                    pid = parent.Id;
                }

                IContentType contentType = cts.GetContentType(contentDefinition.type);

                content = new Content(contentDefinition.name, pid, contentType);
                content.Key = guid;
                cs.SaveAndPublishWithStatus(content);

                log.Add(" > Created with ID " + content.Id + " (GUID: " + content.Key + ")");

            }
            
        }
        public void CreateStub()
        {
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            _unitOfWork = Global.CreateUnitOfWork();
            _repoFactory = new RepositoryFactory();
            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var contentTypeService = new ContentTypeService(_unitOfWork, _repoFactory,
                                                            new ContentService(_unitOfWork),
                                                            new MediaService(_unitOfWork, _repoFactory));

            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var parentContent = new Content(name, -1, contentType);
            parentContent.Key = new Guid("{4172C94F-52C1-4301-9CDA-FD2142496C95}");
            contentService.Save(parentContent);

            var content = new Content(name, parentContent.Id, contentType);
            content.Key = new Guid("{C382AE57-D325-4357-A32A-0A959BBD4101}");
            contentService.Save(content);
        }
Пример #19
0
        public void CreateStub()
        {
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            var unitOfWork = Global.CreateUnitOfWork();
            var repoFactory = new RepositoryFactory();
            _contentService = new ContentService(unitOfWork, repoFactory);
            var contentTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                            new ContentService(unitOfWork),
                                                            new MediaService(unitOfWork, repoFactory));
            var dataTypeService = new DataTypeService(unitOfWork, repoFactory);

            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);
            
            var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"));
            dataTypeService.Save(definitions.FirstOrDefault());
            var propertyType = new PropertyType(definitions.FirstOrDefault());
            propertyType.Alias = "Property";
            contentType.AddPropertyType(propertyType);
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.Key = new Guid("{2867D837-B258-4DF1-90F1-D5E849FCAF84}");
            _contentService.Save(content);
        }
Пример #20
0
        public void Can_Save_New_Content_With_Explicit_User()
        {
            var user = new User(ServiceContext.UserService.GetUserTypeByAlias("admin"))
                {
                    Name = "Test",
                    Email = "*****@*****.**",
                    Username = "******",
                    Password = "******"
                };
            ServiceContext.UserService.SaveUser(user);
            var content = new Content("Test", -1, ServiceContext.ContentTypeService.GetContentType("umbTextpage"));

            // Act
            ServiceContext.ContentService.Save(content, (int)user.Id);

            // Assert
            Assert.That(content.CreatorId, Is.EqualTo(user.Id));
            Assert.That(content.WriterId, Is.EqualTo(user.Id));
        }
        public void CreateStub()
        {
            bool fieldValue = false;
            string name = "Target";
            string contentTypeAlias = "TestType";
            string contentTypeName = "Test Type";

            var unitOfWork = Global.CreateUnitOfWork();
            var repoFactory = new RepositoryFactory();
            _contentService = new ContentService(unitOfWork, repoFactory);
            var contentTypeService = new ContentTypeService(unitOfWork, repoFactory,
                                                            new ContentService(unitOfWork),
                                                            new MediaService(unitOfWork, repoFactory));
            var dataTypeService = new DataTypeService(unitOfWork, repoFactory);

            var contentType = new ContentType(-1);
            contentType.Name = contentTypeName;
            contentType.Alias = contentTypeAlias;
            contentType.Thumbnail = string.Empty;
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("38b352c1-e9f8-4fd8-9324-9a2eab06d97a"));
            dataTypeService.Save(definitions.FirstOrDefault());
            var propertyType = new PropertyType(definitions.FirstOrDefault());
            propertyType.Alias = ContentTypeProperty;
            contentType.AddPropertyType(propertyType);
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.Key = new Guid("{5928EFBB-6DF2-4BB6-A026-BF4938D7ED7A}");
            content.SetPropertyValue(ContentTypeProperty, fieldValue);
            _contentService.Save(content);
        }