public ActionResult Install() { var dataTypeService = _serviceContext.DataTypeService; //var dataType = dataTypeService.GetAll(Constants.DataTypes.DefaultContentListView); //if (!dict.ContainsKey("pageSize")) dict["pageSize"] = new PreValue("10"); //dict["pageSize"].Value = "200"; //dataTypeService.SavePreValues(dataType, dict); var contentTypeService = _serviceContext.ContentTypeService; var contentType = new ContentType(-1) { Alias = _contentAlias, Name = "LoadTest Content", Description = "Content for LoadTest", Icon = "icon-document" }; var def = _serviceContext.DataTypeService.GetDataType(_textboxDefinitionId); contentType.AddPropertyType(new PropertyType(def) { Name = "Origin", Alias = "origin", Description = "The origin of the content.", }); contentTypeService.Save(contentType); var containerTemplate = ImportTemplate(_serviceContext, "LoadTestContainer", "LoadTestContainer", _containerTemplateText); var containerType = new ContentType(-1) { Alias = _containerAlias, Name = "LoadTest Container", Description = "Container for LoadTest content", Icon = "icon-document", AllowedAsRoot = true, IsContainer = true }; containerType.AllowedContentTypes = containerType.AllowedContentTypes.Union(new[] { new ContentTypeSort(new Lazy <int>(() => contentType.Id), 0, contentType.Alias), }); containerType.AllowedTemplates = containerType.AllowedTemplates.Union(new[] { containerTemplate }); containerType.SetDefaultTemplate(containerTemplate); contentTypeService.Save(containerType); var contentService = _serviceContext.ContentService; var content = contentService.Create("LoadTestContainer", -1, _containerAlias); contentService.SaveAndPublish(content); return(ContentHtml("Installed.")); }
private void CreateTypes(out IContentType iContentType, out IContentType vContentType) { var globalSettings = new GlobalSettings(); var langDe = new Language(globalSettings, "de") { IsDefault = true }; LocalizationService.Save(langDe); var langRu = new Language(globalSettings, "ru"); LocalizationService.Save(langRu); var langEs = new Language(globalSettings, "es"); LocalizationService.Save(langEs); iContentType = new ContentType(ShortStringHelper, -1) { Alias = "ict", Name = "Invariant Content Type", Variations = ContentVariation.Nothing }; iContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing }); ContentTypeService.Save(iContentType); vContentType = new ContentType(ShortStringHelper, -1) { Alias = "vct", Name = "Variant Content Type", Variations = ContentVariation.Culture }; vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing }); vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "vp") { Variations = ContentVariation.Culture }); ContentTypeService.Save(vContentType); }
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); }
private int?CreateDocumentType(Item item, int parentId, int userId = 0) { ContentType contentType = new ContentType(parentId); contentType.Name = item.Name; contentType.Alias = item.Alias; contentType.Icon = "icon-message"; var textstringDef = new DataTypeDefinition(-1, "Umbraco.Textbox"); var richtextEditorDef = new DataTypeDefinition(-1, "Umbraco.TinyMCEv3"); var textboxMultipleDef = new DataTypeDefinition(-1, "Umbraco.TextboxMultiple"); if (item.Tabs != null && item.Tabs.Any()) { foreach (var tab in item.Tabs) { if (!string.IsNullOrEmpty(tab.Name)) { contentType.AddPropertyGroup(tab.Name); foreach (var property in tab.Properties) { contentType.AddPropertyType( new PropertyType(textstringDef) { Alias = property.Alias, Name = property.Name, Description = "", Mandatory = property.Mandatory, SortOrder = 1 }, tab.Name); } } } } _contentTypeService.Save(contentType); if (contentType != null) { return(contentType.Id); } else { return(parentId); } }
public IActionResult Install() { var contentType = new ContentType(_shortStringHelper, -1) { Alias = ContentAlias, Name = "LoadTest Content", Description = "Content for LoadTest", Icon = "icon-document" }; IDataType def = _dataTypeService.GetDataType(TextboxDefinitionId); contentType.AddPropertyType(new PropertyType(_shortStringHelper, def) { Name = "Origin", Alias = "origin", Description = "The origin of the content.", }); _contentTypeService.Save(contentType); Template containerTemplate = ImportTemplate( "LoadTestContainer", "LoadTestContainer", s_containerTemplateText); var containerType = new ContentType(_shortStringHelper, -1) { Alias = ContainerAlias, Name = "LoadTest Container", Description = "Container for LoadTest content", Icon = "icon-document", AllowedAsRoot = true, IsContainer = true }; containerType.AllowedContentTypes = containerType.AllowedContentTypes.Union(new[] { new ContentTypeSort(new Lazy <int>(() => contentType.Id), 0, contentType.Alias), }); containerType.AllowedTemplates = containerType.AllowedTemplates.Union(new[] { containerTemplate }); containerType.SetDefaultTemplate(containerTemplate); _contentTypeService.Save(containerType); IContent content = _contentService.Create("LoadTestContainer", -1, ContainerAlias); _contentService.SaveAndPublish(content); return(ContentHtml("Installed.")); }
private static void SetContentTypeProperties(IShortStringHelper shortStringHelper, DataType labelDataType, DataType rteDataType, ContentNodeKit kit, ContentType contentType) { foreach (KeyValuePair <string, PropertyData[]> property in kit.DraftData.Properties) { var propertyType = new PropertyType(shortStringHelper, labelDataType, property.Key); if (!contentType.PropertyTypeExists(propertyType.Alias)) { if (propertyType.Alias == "content") { propertyType.DataTypeId = rteDataType.Id; } contentType.AddPropertyType(propertyType); } } }
public void Can_Save_ContentType_Structure_And_Create_Content_Based_On_It() { // Arrange var cs = ServiceContext.ContentService; var cts = ServiceContext.ContentTypeService; var dtdYesNo = ServiceContext.DataTypeService.GetDataTypeDefinitionById(-49); var ctBase = new ContentType(-1) { Name = "Base", Alias = "Base", Icon = "folder.gif", Thumbnail = "folder.png" }; ctBase.AddPropertyType(new PropertyType(dtdYesNo) { Name = "Hide From Navigation", Alias = Constants.Conventions.Content.NaviHide } /*,"Navigation"*/); cts.Save(ctBase); var ctHomePage = new ContentType(ctBase) { Name = "Home Page", Alias = "HomePage", Icon = "settingDomain.gif", Thumbnail = "folder.png", AllowedAsRoot = true }; ctHomePage.AddPropertyType(new PropertyType(dtdYesNo) { Name = "Some property", Alias = "someProperty" } /*,"Navigation"*/); cts.Save(ctHomePage); // Act var homeDoc = cs.CreateContent("Home Page", -1, "HomePage"); cs.SaveAndPublish(homeDoc); // Assert Assert.That(ctBase.HasIdentity, Is.True); Assert.That(ctHomePage.HasIdentity, Is.True); Assert.That(homeDoc.HasIdentity, Is.True); Assert.That(homeDoc.ContentTypeId, Is.EqualTo(ctHomePage.Id)); }
public static ContentType CreateSimpleTagsContentType(string alias, string name, IContentType parent = null, bool randomizeAliases = false, string propertyGroupName = "Content", int defaultTemplateId = 1) { ContentType contentType = CreateSimpleContentType(alias, name, parent, randomizeAliases: randomizeAliases, propertyGroupName: propertyGroupName, defaultTemplateId: defaultTemplateId); PropertyType propertyType = new PropertyTypeBuilder() .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.Tags) .WithValueStorageType(ValueStorageType.Nvarchar) .WithAlias(RandomAlias("tags", randomizeAliases)) .WithName("Tags") .WithDataTypeId(Constants.DataTypes.Tags) .WithSortOrder(99) .Build(); contentType.AddPropertyType(propertyType); return(contentType); }
private static PropertyType CreateAndAddPropertyTypeToDocumentType(string propertyAlias, ContentType documentType, DocumentTypePropertyAttribute propertyAttribute) { var dataTypeDefinition = DataTypeDefinition.GetDataTypeDefinition(propertyAttribute.DataTypeId); if (dataTypeDefinition == null) { throw new DataTypeDefinitionUnknownException(propertyAttribute.DataTypeId); } var propertyType = documentType.AddPropertyType(dataTypeDefinition, propertyAlias, propertyAttribute.Name); SetPropertyTypeMandatoryIfDifferent(propertyType, propertyAttribute.Mandatory); SetPropertyTypeValidationExpressionIfDifferent(propertyType, propertyAttribute.ValidationExpression); SetPropertyTypeSortOrderIfDifferent(propertyType, propertyAttribute.SortOrder); SetPropertyTypeDescriptionIfDifferent(propertyType, propertyAttribute.Description); SetPropertyTypeTabIfDifferent(documentType, propertyType, propertyAttribute.Tab); return(propertyType); }
public override void SetUp() { base.SetUp(); _contentType = MockedContentTypes.CreateTextPageContentType(ContentTypeAlias); // add complex editor _contentType.AddPropertyType( new PropertyType("complexTest", ValueStorageType.Ntext) { Alias = "complex", Name = "Complex", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = ComplexDataTypeId }, "Content"); // make them all validate with a regex rule that will not pass foreach (var prop in _contentType.PropertyTypes) { prop.ValidationRegExp = "^donotmatch$"; prop.ValidationRegExpMessage = "Does not match!"; } }
private static ContentType CreateContentType(string name, IDataType dataType, IReadOnlyDictionary <string, string> propertyAliasesAndNames) { var contentType = new ContentType(TestHelper.ShortStringHelper, -1) { Alias = name, Name = name, Key = Guid.NewGuid(), Id = name.GetHashCode() }; foreach (var prop in propertyAliasesAndNames) { contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, dataType, prop.Key) { Name = prop.Value }); } return(contentType); }
public override void Setup() { base.Setup(); _propertyType = new PropertyType(TestHelper.ShortStringHelper, "Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Culture }; _contentType = new ContentType(TestHelper.ShortStringHelper, -1) { Id = 2, Alias = "alias-ct", Variations = ContentVariation.Culture }; _contentType.AddPropertyType(_propertyType); var contentTypes = new[] { _contentType }; InitializedCache(new[] { CreateKit() }, contentTypes); }
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 = "Property"; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.Key = new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}"); content.SetPropertyValue("Property", fieldValue); _contentService.Save(content); }
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); }
public override void Setup() { base.Setup(); var propertyType = new PropertyType(TestHelper.ShortStringHelper, "Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Nothing, }; _contentTypeInvariant = new ContentType(TestHelper.ShortStringHelper, -1) { Id = 2, Alias = "itype", Variations = ContentVariation.Nothing, }; _contentTypeInvariant.AddPropertyType(propertyType); propertyType = new PropertyType(TestHelper.ShortStringHelper, "Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Culture, }; _contentTypeVariant = new ContentType(TestHelper.ShortStringHelper, -1) { Id = 3, Alias = "vtype", Variations = ContentVariation.Culture, }; _contentTypeVariant.AddPropertyType(propertyType); _contentTypes = new[] { _contentTypeInvariant, _contentTypeVariant }; }
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); }
private void CreateProperties(ContentType item, IEnumerable <ContentTypeTab> tabs) { foreach (var tab in tabs) { foreach (var property in tab.Properties) { LogHelper.Info <ContentTypeBuilder>("Looking for DocType: {0}", () => property.DataType); var dataType = _dataTypeService.GetDataTypeDefinitionByName(property.DataType); var itemProperty = item.PropertyTypes.SingleOrDefault(x => x.Alias == property.Alias); if (itemProperty == null) { // create it. itemProperty = new PropertyType(dataType, property.Alias) { Name = property.Name }; if (!property.Description.IsNullOrWhiteSpace()) { itemProperty.Description = property.Description; } if (!property.Validation.IsNullOrWhiteSpace()) { itemProperty.ValidationRegExp = property.Validation; } itemProperty.Mandatory = property.Mandatory; itemProperty.SortOrder = property.SortOrder; itemProperty.PropertyEditorAlias = dataType.PropertyEditorAlias; item.AddPropertyType(itemProperty, tab.TabName); } } } }
private void CreatePagePromotionComposition() { var contentService = ApplicationContext.Current.Services.ContentTypeService; var dataTypeService = ApplicationContext.Current.Services.DataTypeService; var compositionFolder = contentService.GetContentTypeContainers(CoreInstallationConstants.DocumentTypesContainerNames.Compositions, 1).Single(); var pagePromotionCompositionType = contentService.GetContentType(PagePromotionInstallationConstants.DocumentTypeAliases.PagePromotionComposition); if (pagePromotionCompositionType != null) { return; } pagePromotionCompositionType = new ContentType(compositionFolder.Id) { Name = PagePromotionInstallationConstants.DocumentTypeNames.PagePromotionComposition, Alias = PagePromotionInstallationConstants.DocumentTypeAliases.PagePromotionComposition }; pagePromotionCompositionType.AddPropertyGroup(PagePromotionInstallationConstants.DocumentTypeTabNames.Promotion); var promotionPropertyGroup = pagePromotionCompositionType.PropertyGroups.Single(group => group.Name == PagePromotionInstallationConstants.DocumentTypeTabNames.Promotion); promotionPropertyGroup.SortOrder = PagePromotionInstallationConstants.DocumentTypeTabSortOrder.Promotion; var pagePromotionDataType = dataTypeService.GetDataTypeDefinitionByName(PagePromotionInstallationConstants.DataTypeNames.PagePromotion); var pagePromotionConfigProperty = new PropertyType(pagePromotionDataType) { Name = PagePromotionInstallationConstants.DocumentTypePropertyNames.PagePromotionConfig, Alias = PagePromotionInstallationConstants.DocumentTypePropertyAliases.PagePromotionConfig }; pagePromotionCompositionType.AddPropertyType(pagePromotionConfigProperty, PagePromotionInstallationConstants.DocumentTypeTabNames.Promotion); contentService.Save(pagePromotionCompositionType); }
private void CreateBasePageWithContentGrid() { var contentService = ApplicationContext.Current.Services.ContentTypeService; var basePageDocumentType = contentService.GetContentType(DocumentTypeAliases.BasePageWithContentGrid); if (basePageDocumentType != null) { return; } var basePage = contentService.GetContentType(DocumentTypeAliases.BasePage); basePageDocumentType = new ContentType(basePage.Id) { Name = DocumentTypeNames.BasePageWithContentGrid, Alias = DocumentTypeAliases.BasePageWithContentGrid }; basePageDocumentType.AddPropertyGroup(DataTypePropertyGroupNames.Content); basePageDocumentType.AddPropertyType(InstallationStepsHelper.GetGridPropertyType(DataTypeNames.ContentGrid), DataTypePropertyGroupNames.Content); contentService.Save(basePageDocumentType); }
private void AddSearchDocumentTypeAndPage() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) { return; } var contentTypeService = ApplicationContext.Current.Services.ContentTypeService; var searchContentType = contentTypeService.GetContentType("search"); if (searchContentType == null) { var contentType = new ContentType(-1) { Name = "Search", Alias = "search", Icon = "icon-search" }; contentType.PropertyGroups.Add(new PropertyGroup { Name = "Content" }); var checkbox = new DataTypeDefinition("Umbraco.TrueFalse"); var checkboxPropertyType = new PropertyType(checkbox, "umbracoNaviHide") { Name = "Hide in navigation?" }; contentType.AddPropertyType(checkboxPropertyType, "Content"); contentTypeService.Save(contentType); searchContentType = contentTypeService.GetContentType("search"); var templateCreateResult = ApplicationContext.Current.Services.FileService.CreateTemplateForContentType("search", "Search"); if (templateCreateResult.Success) { var template = ApplicationContext.Current.Services.FileService.GetTemplate("search"); var masterTemplate = ApplicationContext.Current.Services.FileService.GetTemplate("master"); template.SetMasterTemplate(masterTemplate); ApplicationContext.Current.Services.FileService.SaveTemplate(template); searchContentType.AllowedTemplates = new List <ITemplate> { template }; searchContentType.SetDefaultTemplate(template); contentTypeService.Save(searchContentType); var contentService = ApplicationContext.Current.Services.ContentService; var rootContent = contentService.GetRootContent().FirstOrDefault(); if (rootContent != null) { var searchPage = rootContent.Children().FirstOrDefault(x => x.Name == "Search"); contentService.Delete(searchPage); searchPage = contentService.CreateContent("Search", rootContent.Id, "search"); var saveResult = contentService.SaveAndPublishWithStatus(searchPage); } } } } catch (Exception ex) { LogHelper.Error <MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
public static void CreateDocTypes() { var cts = ApplicationContext.Current.Services.ContentTypeService; // CampaignDetail var foundContentType = cts.GetContentType(DocTypeAliases.PhoneManagerCampaignDetail); if (foundContentType == null) { // create doctype ContentType ctModel = new ContentType(-1); ctModel.Name = "Campaign Detail"; ctModel.Alias = DocTypeAliases.PhoneManagerCampaignDetail; ctModel.Icon = "icon-phone"; var tabName = "Campaign Detail"; ctModel.AddPropertyGroup(tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TextString) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.TelephoneNumber, Name = "Telephone number", Description = "The campaign phone number", Mandatory = true, SortOrder = 1 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TextString) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.CampaignCode, Name = "Campaign code", Description = "The campaign code sent as a querystring 'fsource=' with the request", Mandatory = false, SortOrder = 2 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TextString) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.Referrer, Name = "Referrer", Description = "With the following referrer domains. E.g. with could be search engine domains. Use 'none' for direct entry.", Mandatory = false, SortOrder = 3 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.ContentPicker2) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.EntryPage, Name = "Entry page", Description = "If user enters the site on this page", Mandatory = false, SortOrder = 4 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TrueFalse) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.DoNotPersistAcrossVisits, Name = "Do not persist across visits", Description = "Persist this number across user sessions. i.e. using cookies", Mandatory = false, SortOrder = 5 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.Numeric) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.PersistDurationOverride, Name = "Persist duration override", Description = "If persisting, for how many days?", Mandatory = true, SortOrder = 6 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TrueFalse) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.OverwritePersistingItem, Name = "Overwrite persisting item", Description = "This number will overwrite an exisiting persistent number", Mandatory = false, SortOrder = 7 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TextString) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.AltMarketingCode, Name = "Alt marketing code", Description = "Additional marketing code associated with this campaign", Mandatory = false, SortOrder = 8 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TextString) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.UseAltCampaignQueryStringKey, Name = "Override campaign querystring key", Description = "Use this as the QueryString key instead of the default one.", Mandatory = false, SortOrder = 9 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TrueFalse) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel_PhoneManagerCampaignDetail.IsDefault, Name = "Is Default", Description = "Use this if no other matching campaigns are found", Mandatory = false, SortOrder = 10 }, tabName); cts.Save(ctModel); } // CampaignPhoneManagerModel foundContentType = cts.GetContentType(DocTypeAliases.PhoneManager); if (foundContentType == null) { // create doctype ContentType ctModel = new ContentType(-1); ctModel.Name = "Phone Manager"; ctModel.Alias = DocTypeAliases.PhoneManager; ctModel.Icon = "icon-phone-ring color-orange"; var tabName = "Settings"; ctModel.AddPropertyGroup(tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TextString) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel.DefaultCampaignQueryStringKey, Name = "Campaign querystring key", Description = "The http request querystring key used by the marketing campaign", Mandatory = true, SortOrder = 1 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.Numeric) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel.DefaultPersistDurationInDays, Name = "Default persist duration in days", Description = "The default number of days to persist the campaign for a customer", Mandatory = true, SortOrder = 3 }, tabName); ctModel.AddPropertyType(new PropertyType(UmbracoDataTypes.TrueFalse) { Alias = AppConstants.UmbracoDocTypeAliases.PhoneManagerModel.GlobalDisableOverwritePersistingItems, Name = "Disable any campaign from overwriting persisting items. This is recommended if possible.", Mandatory = false, SortOrder = 4 }, tabName); // Add the CampaignDetail content type as allowed under this var foundCampaignDetailType = cts.GetContentType(DocTypeAliases.PhoneManagerCampaignDetail); ctModel.AllowedContentTypes = new List <ContentTypeSort>(foundCampaignDetailType.Id); cts.Save(ctModel); } }
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); x.Delegate(y => y.Delegated).GetValue(GetDelegatedValue); }); 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); Assert.AreEqual("happy", result.Delegated); }
private void UpdateDocumentType() { const string propertyAlias = "bannerSlider", propertyName = "Banner Slider", propertyDescription = "Slider with banner images"; try { #region Nested Document Type var container = contentTypeService.GetContainers(DOCUMENT_TYPE_CONTAINER, 1).FirstOrDefault(); int containerId = -1; if (container != null) { containerId = container.Id; } var contentType = contentTypeService.Get(NESTED_DOCUMENT_TYPE_ALIAS); if (contentType == null) { ContentType docType = (ContentType)contentType ?? new ContentType(containerId) { Name = NESTED_DOCUMENT_TYPE_NAME, Alias = NESTED_DOCUMENT_TYPE_ALIAS, AllowedAsRoot = false, Description = NESTED_DOCUMENT_TYPE_DESCRIPTION, Icon = NESTED_DOCUMENT_TYPE_ICON, IsElement = true, SortOrder = 0, ParentId = contentTypeService.Get(NESTED_DOCUMENT_TYPE_PARENT_ALIAS).Id, Variations = ContentVariation.Culture }; docType.AddPropertyGroup(SLIDERS_TAB); #region Nested Document Type Properties PropertyType ImagePropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemImage") { Name = "Image", Description = "Image used in the Slider", Variations = ContentVariation.Nothing }; docType.AddPropertyType(ImagePropType, SLIDERS_TAB); PropertyType ButtonLabelPropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemButtonLabel") { Name = " Button Label", Description = "Label for the Button", Variations = ContentVariation.Nothing }; docType.AddPropertyType(ButtonLabelPropType, SLIDERS_TAB); PropertyType TitlePropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemTitle") { Name = "Title", Description = "Title for the banner item", Variations = ContentVariation.Nothing }; docType.AddPropertyType(TitlePropType, SLIDERS_TAB); PropertyType SubtitlePropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemSubtitle") { Name = "Subtitle", Description = "Subtitle for the banner item", Variations = ContentVariation.Nothing }; docType.AddPropertyType(SubtitlePropType, SLIDERS_TAB); PropertyType UrlPropType = new PropertyType(dataTypeService.GetDataType(-88), "sliderItemUrl") { Name = "Url", Description = "The Link to the item", Variations = ContentVariation.Nothing }; docType.AddPropertyType(UrlPropType, SLIDERS_TAB); #endregion contentTypeService.Save(docType); ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{NESTED_DOCUMENT_TYPE_ALIAS}' has been created"); } else { if (contentType.PropertyTypeExists("sliderItemImage") && contentType.PropertyTypes.Single(x => x.Alias == "sliderItemImage").DataTypeId == -88) { var mediaPickerContainer = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault(); var mediaPickerContainerId = -1; if (mediaPickerContainer != null) { mediaPickerContainerId = mediaPickerContainer.Id; } var dataTypeExists = dataTypeService.GetDataType("sliderItemImageMediaPicker") != null; if (!dataTypeExists) { var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.MediaPicker", out IDataEditor editor); if (created) { DataType mediaPickerSliderImage = new DataType(editor, mediaPickerContainerId) { Name = "sliderItemImageMediaPicker", ParentId = mediaPickerContainerId, Configuration = new MediaPickerConfiguration { DisableFolderSelect = true, Multiple = false, OnlyImages = true } }; dataTypeService.Save(mediaPickerSliderImage); contentType.PropertyTypes.Single(x => x.Alias == "sliderItemImage").DataTypeId = mediaPickerSliderImage.Id; contentTypeService.Save(contentType); } } } } #endregion #region Update Home Document Type var homeDocumentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS); var dataTypeContainer = dataTypeService.GetContainers(DATA_TYPE_CONTAINER, 1).FirstOrDefault(); var dataTypeContainerId = -1; if (dataTypeContainer != null) { dataTypeContainerId = dataTypeContainer.Id; } var exists = dataTypeService.GetDataType(propertyName) != null; if (!exists) { var created = Web.Composing.Current.PropertyEditors.TryGet("Umbraco.NestedContent", out IDataEditor editor); if (!created) { DataType bannerSliderNestedDataType = new DataType(editor, dataTypeContainerId) { Name = propertyName, ParentId = dataTypeContainerId, Configuration = new NestedContentConfiguration { MinItems = 0, MaxItems = 999, ConfirmDeletes = true, HideLabel = false, ShowIcons = true, ContentTypes = new[] { new NestedContentConfiguration.ContentType { Alias = NESTED_DOCUMENT_TYPE_ALIAS, TabAlias = SLIDERS_TAB } } } }; dataTypeService.Save(bannerSliderNestedDataType); } } if (!homeDocumentType.PropertyTypeExists("bannerSlider")) { var bannerSliderNestedDataType = dataTypeService.GetDataType(propertyName); PropertyType BannerSlider = new PropertyType(bannerSliderNestedDataType, propertyAlias) { Name = propertyName, Description = propertyDescription, Variations = ContentVariation.Culture }; var propertyGroup = homeDocumentType.PropertyGroups.SingleOrDefault(x => x.Name == SLIDERS_TAB); if (propertyGroup == null) { homeDocumentType.AddPropertyGroup(SLIDERS_TAB); } homeDocumentType.AddPropertyType(BannerSlider, SLIDERS_TAB); contentTypeService.Save(homeDocumentType); ConnectorContext.AuditService.Add(AuditType.Save, -1, homeDocumentType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_ALIAS}' has been updated"); } #endregion } catch (System.Exception ex) { logger.Error(typeof(_17_HomeDocumentTypeSlider), ex.Message); logger.Error(typeof(_17_HomeDocumentTypeSlider), ex.StackTrace); } }
public void GivenIndexingDocument_WhenGridPropertyData_ThenDataIndexedInSegregatedFields() { using (GetSynchronousContentIndex(false, out UmbracoContentIndex index, out _, out ContentValueSetBuilder contentValueSetBuilder, null)) { index.CreateIndex(); ContentType contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext) { Alias = "grid", Name = "Grid", PropertyEditorAlias = Cms.Core.Constants.PropertyEditors.Aliases.Grid }); Content content = ContentBuilder.CreateBasicContent(contentType); content.Id = 555; content.Path = "-1,555"; var gridVal = new GridValue { Name = "n1", Sections = new List <GridValue.GridSection> { new GridValue.GridSection { Grid = "g1", Rows = new List <GridValue.GridRow> { new GridValue.GridRow { Id = Guid.NewGuid(), Name = "row1", Areas = new List <GridValue.GridArea> { new GridValue.GridArea { Grid = "g2", Controls = new List <GridValue.GridControl> { new GridValue.GridControl { Editor = new GridValue.GridEditor { Alias = "editor1", View = "view1" }, Value = "value1" }, new GridValue.GridControl { Editor = new GridValue.GridEditor { Alias = "editor1", View = "view1" }, Value = "value2" } } } } } } } } }; var json = JsonConvert.SerializeObject(gridVal); content.Properties["grid"].SetValue(json); IEnumerable <ValueSet> valueSet = contentValueSetBuilder.GetValueSets(content); index.IndexItems(valueSet); ISearchResults results = index.Searcher.CreateQuery().Id(555).Execute(); Assert.AreEqual(1, results.TotalItemCount); ISearchResult result = results.First(); Assert.IsTrue(result.Values.ContainsKey("grid.row1")); Assert.AreEqual("value1", result.AllValues["grid.row1"][0]); Assert.AreEqual("value2", result.AllValues["grid.row1"][1]); Assert.IsTrue(result.Values.ContainsKey("grid")); Assert.AreEqual("value1 value2 ", result["grid"]); Assert.IsTrue(result.Values.ContainsKey($"{UmbracoExamineFieldNames.RawFieldPrefix}grid")); Assert.AreEqual(json, result[$"{UmbracoExamineFieldNames.RawFieldPrefix}grid"]); } }
private void CreateHomeDocumentType() { try { var container = contentTypeService.GetContainers(CONTAINER, 1).FirstOrDefault(); int containerId = 0; if (container == null) { var newcontainer = contentTypeService.CreateContainer(-1, CONTAINER); if (newcontainer.Success) { containerId = newcontainer.Result.Entity.Id; } } else { containerId = container.Id; } var contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS); if (contentType == null) { //http://refreshwebsites.co.uk/blog/umbraco-document-types-explained-in-60-seconds/ //https://our.umbraco.org/forum/developers/api-questions/43278-programmatically-creating-a-document-type ContentType docType = (ContentType)contentType ?? new ContentType(containerId) { Name = DOCUMENT_TYPE_NAME, Alias = DOCUMENT_TYPE_ALIAS, AllowedAsRoot = true, Description = DOCUMENT_TYPE_DESCRIPTION, Icon = ICON, SortOrder = 0, Variations = ContentVariation.Culture }; // Create the Template if it doesn't exist if (fileService.GetTemplate(TEMPLATE_ALIAS) == null) { //then create the template Template newTemplate = new Template(TEMPLATE_NAME, TEMPLATE_ALIAS); fileService.SaveTemplate(newTemplate); } // Set templates for document type var template = fileService.GetTemplate(TEMPLATE_ALIAS); docType.AllowedTemplates = new List <ITemplate> { template }; docType.SetDefaultTemplate(template); docType.AddPropertyGroup(CONTENT_TAB); docType.AddPropertyGroup(TENANT_TAB); // Set Document Type Properties #region Tenant Home Page Content PropertyType brandLogoPropType = new PropertyType(dataTypeService.GetDataType(1043), "brandLogo") { Name = "Brand Logo", Variations = ContentVariation.Nothing }; docType.AddPropertyType(brandLogoPropType, CONTENT_TAB); PropertyType homeContentProType = new PropertyType(dataTypeService.GetDataType(-87), "homeContent") { Name = "Content", Variations = ContentVariation.Culture }; docType.AddPropertyType(homeContentProType, CONTENT_TAB); #endregion #region Tenant Info Tab PropertyType tenantUidPropType = new PropertyType(dataTypeService.GetDataType(-92), "tenantUid") { Name = "Tenant Uid", Description = "Tenant Unique Id", Variations = ContentVariation.Nothing }; docType.AddPropertyType(tenantUidPropType, TENANT_TAB); PropertyType brandNamePropType = new PropertyType(dataTypeService.GetDataType(-92), "brandName") { Name = "Brand Name", Variations = ContentVariation.Nothing }; docType.AddPropertyType(brandNamePropType, TENANT_TAB); PropertyType domainPropType = new PropertyType(dataTypeService.GetDataType(-92), "domain") { Name = "Domain", Variations = ContentVariation.Nothing }; docType.AddPropertyType(domainPropType, TENANT_TAB); PropertyType subDomainPropType = new PropertyType(dataTypeService.GetDataType(-92), "subDomain") { Name = "Sub Domain", Variations = ContentVariation.Nothing }; docType.AddPropertyType(subDomainPropType, TENANT_TAB); PropertyType appIdPropType = new PropertyType(dataTypeService.GetDataType(-92), "appId") { Name = "App Id", Variations = ContentVariation.Nothing }; docType.AddPropertyType(appIdPropType, TENANT_TAB); PropertyType apiKeyPropType = new PropertyType(dataTypeService.GetDataType(-92), "apiKey") { Name = "Api Key", Variations = ContentVariation.Nothing }; docType.AddPropertyType(apiKeyPropType, TENANT_TAB); PropertyType defaultLanguagePropType = new PropertyType(dataTypeService.GetDataType(-92), "defaultLanguage") { Name = "Default Language", Description = "System Default Language", Variations = ContentVariation.Nothing }; docType.AddPropertyType(defaultLanguagePropType, TENANT_TAB); PropertyType languagestPropType = new PropertyType(dataTypeService.GetDataType(-92), "languages") { Name = "Alternate Languages", Variations = ContentVariation.Nothing }; docType.AddPropertyType(languagestPropType, TENANT_TAB); PropertyType tenantStatusPropType = new PropertyType(dataTypeService.GetDataType(-92), "tenantStatus") { Name = "Tenant Status", Description = "Total Code Tenant Status", Variations = ContentVariation.Nothing }; docType.AddPropertyType(tenantStatusPropType, TENANT_TAB); #endregion contentTypeService.Save(docType); ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_NAME}' has been created"); ContentHelper.CopyPhysicalAssets(new EmbeddedResources()); } } catch (System.Exception ex) { logger.Error(typeof(HomeDocumentType), ex.Message); logger.Error(typeof(HomeDocumentType), ex.StackTrace); } }
public void StandaloneVariations() { // this test implements a full standalone NuCache (based upon a test IDataSource, does not // use any local db files, does not rely on any database) - and tests variations Current.Reset(); Current.UnlockConfigs(); Current.Configs.Add(SettingsForTests.GenerateMockUmbracoSettings); Current.Configs.Add <IGlobalSettings>(() => new GlobalSettings()); var globalSettings = Current.Configs.Global(); // create a content node kit var kit = new ContentNodeKit { ContentTypeId = 2, Node = new ContentNode(1, Guid.NewGuid(), 0, "-1,1", 0, -1, DateTime.Now, 0), DraftData = new ContentData { Name = "It Works2!", Published = false, TemplateId = 0, VersionId = 2, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary <string, PropertyData[]> { { "prop", new[] { new PropertyData { Culture = "", Segment = "", Value = "val2" }, new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr2" }, new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk2" } } } }, CultureInfos = new Dictionary <string, CultureVariation> { { "fr-FR", new CultureVariation { Name = "name-fr2", Date = new DateTime(2018, 01, 03, 01, 00, 00) } }, { "en-UK", new CultureVariation { Name = "name-uk2", Date = new DateTime(2018, 01, 04, 01, 00, 00) } } } }, PublishedData = new ContentData { Name = "It Works1!", Published = true, TemplateId = 0, VersionId = 1, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary <string, PropertyData[]> { { "prop", new[] { new PropertyData { Culture = "", Segment = "", Value = "val1" }, new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr1" }, new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk1" } } } }, CultureInfos = new Dictionary <string, CultureVariation> { { "fr-FR", new CultureVariation { Name = "name-fr1", Date = new DateTime(2018, 01, 01, 01, 00, 00) } }, { "en-UK", new CultureVariation { Name = "name-uk1", Date = new DateTime(2018, 01, 02, 01, 00, 00) } } } } }; // create a data source for NuCache var dataSource = new TestDataSource(kit); var runtime = Mock.Of <IRuntimeState>(); Mock.Get(runtime).Setup(x => x.Level).Returns(RuntimeLevel.Run); // create data types, property types and content types var dataType = new DataType(new VoidEditor("Editor", Mock.Of <ILogger>())) { Id = 3 }; var dataTypes = new[] { dataType }; var propertyType = new PropertyType("Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Culture }; var contentType = new ContentType(-1) { Id = 2, Alias = "alias-ct", Variations = ContentVariation.Culture }; contentType.AddPropertyType(propertyType); var contentTypes = new[] { contentType }; var contentTypeService = Mock.Of <IContentTypeService>(); Mock.Get(contentTypeService).Setup(x => x.GetAll()).Returns(contentTypes); Mock.Get(contentTypeService).Setup(x => x.GetAll(It.IsAny <int[]>())).Returns(contentTypes); var dataTypeService = Mock.Of <IDataTypeService>(); Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes); // create a service context var serviceContext = ServiceContext.CreatePartial( dataTypeService: dataTypeService, memberTypeService: Mock.Of <IMemberTypeService>(), memberService: Mock.Of <IMemberService>(), contentTypeService: contentTypeService, localizationService: Mock.Of <ILocalizationService>() ); // create a scope provider var scopeProvider = Mock.Of <IScopeProvider>(); Mock.Get(scopeProvider) .Setup(x => x.CreateScope( It.IsAny <IsolationLevel>(), It.IsAny <RepositoryCacheMode>(), It.IsAny <IEventDispatcher>(), It.IsAny <bool?>(), It.IsAny <bool>(), It.IsAny <bool>())) .Returns(Mock.Of <IScope>); // create a published content type factory var contentTypeFactory = new PublishedContentTypeFactory( Mock.Of <IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty <IPropertyValueConverter>()), dataTypeService); // create a variation accessor var variationAccessor = new TestVariationContextAccessor(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotService.Options { IgnoreLocalDb = true }; var snapshotService = new PublishedSnapshotService(options, null, runtime, serviceContext, contentTypeFactory, null, new TestPublishedSnapshotAccessor(), variationAccessor, Mock.Of <ILogger>(), scopeProvider, Mock.Of <IDocumentRepository>(), Mock.Of <IMediaRepository>(), Mock.Of <IMemberRepository>(), new TestDefaultCultureAccessor(), dataSource, globalSettings, new SiteDomainHelper()); // get a snapshot, get a published content var snapshot = snapshotService.CreatePublishedSnapshot(previewToken: null); var publishedContent = snapshot.Content.GetById(1); // invariant is the current default variationAccessor.VariationContext = new VariationContext(); Assert.IsNotNull(publishedContent); Assert.AreEqual("It Works1!", publishedContent.Name); Assert.AreEqual("val1", publishedContent.Value <string>("prop")); Assert.AreEqual("val-fr1", publishedContent.Value <string>("prop", "fr-FR")); Assert.AreEqual("val-uk1", publishedContent.Value <string>("prop", "en-UK")); Assert.AreEqual("name-fr1", publishedContent.GetCulture("fr-FR").Name); Assert.AreEqual("name-uk1", publishedContent.GetCulture("en-UK").Name); var draftContent = snapshot.Content.GetById(true, 1); Assert.AreEqual("It Works2!", draftContent.Name); Assert.AreEqual("val2", draftContent.Value <string>("prop")); Assert.AreEqual("val-fr2", draftContent.Value <string>("prop", "fr-FR")); Assert.AreEqual("val-uk2", draftContent.Value <string>("prop", "en-UK")); Assert.AreEqual("name-fr2", draftContent.GetCulture("fr-FR").Name); Assert.AreEqual("name-uk2", draftContent.GetCulture("en-UK").Name); // now french is default variationAccessor.VariationContext = new VariationContext("fr-FR"); Assert.AreEqual("val-fr1", publishedContent.Value <string>("prop")); Assert.AreEqual("name-fr1", publishedContent.GetCulture().Name); Assert.AreEqual("name-fr1", publishedContent.Name); Assert.AreEqual(new DateTime(2018, 01, 01, 01, 00, 00), publishedContent.GetCulture().Date); // now uk is default variationAccessor.VariationContext = new VariationContext("en-UK"); Assert.AreEqual("val-uk1", publishedContent.Value <string>("prop")); Assert.AreEqual("name-uk1", publishedContent.GetCulture().Name); Assert.AreEqual("name-uk1", publishedContent.Name); Assert.AreEqual(new DateTime(2018, 01, 02, 01, 00, 00), publishedContent.GetCulture().Date); // invariant needs to be retrieved explicitely, when it's not default Assert.AreEqual("val1", publishedContent.Value <string>("prop", culture: "")); // but, // if the content type / property type does not vary, then it's all invariant again // modify the content type and property type, notify the snapshot service contentType.Variations = ContentVariation.Nothing; propertyType.Variations = ContentVariation.Nothing; snapshotService.Notify(new[] { new ContentTypeCacheRefresher.JsonPayload("IContentType", publishedContent.ContentType.Id, ContentTypeChangeTypes.RefreshMain) }); // get a new snapshot (nothing changed in the old one), get the published content again var anotherSnapshot = snapshotService.CreatePublishedSnapshot(previewToken: null); var againContent = anotherSnapshot.Content.GetById(1); Assert.AreEqual(ContentVariation.Nothing, againContent.ContentType.Variations); Assert.AreEqual(ContentVariation.Nothing, againContent.ContentType.GetPropertyType("prop").Variations); // now, "no culture" means "invariant" Assert.AreEqual("It Works1!", againContent.Name); Assert.AreEqual("val1", againContent.Value <string>("prop")); }
public void Initialize() { try { var container = contentTypeService.GetContainers(DOCUMENT_TYPE_CONTAINER, 1).FirstOrDefault(); int containerId = -1; if (container != null) { containerId = container.Id; } var contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS); if (contentType != null) { return; } const string CONTENT_TAB = "CONTENT"; ContentType docType = (ContentType)contentType ?? new ContentType(containerId) { Name = DOCUMENT_TYPE_NAME, Alias = DOCUMENT_TYPE_ALIAS, AllowedAsRoot = true, Description = "", Icon = NESTED_DOCUMENT_TYPE_ICON, ParentId = contentTypeService.Get(NESTED_DOCUMENT_TYPE_PARENT_ALIAS).Id, SortOrder = 0, Variations = ContentVariation.Culture, }; // Create the Template if it doesn't exist if (fileService.GetTemplate(TEMPLATE_ALIAS) == null) { //then create the template Template newTemplate = new Template(TEMPLATE_NAME, TEMPLATE_ALIAS); ITemplate masterTemplate = fileService.GetTemplate(PARENT_TEMPLATE_ALIAS); newTemplate.SetMasterTemplate(masterTemplate); fileService.SaveTemplate(newTemplate); } var template = fileService.GetTemplate(TEMPLATE_ALIAS); docType.AllowedTemplates = new List <ITemplate> { template }; docType.SetDefaultTemplate(template); docType.AddPropertyGroup(CONTENT_TAB); #region Content PropertyType CotentPageTitlePropType = new PropertyType(dataTypeService.GetDataType(-88), "genericInfoPageTitle") { Name = "Page Title", Variations = ContentVariation.Culture }; docType.AddPropertyType(CotentPageTitlePropType, CONTENT_TAB); PropertyType CotentPageContentPropType = new PropertyType(dataTypeService.GetDataType(-87), "genericInfoPageContent") { Name = "Page Content", Variations = ContentVariation.Culture }; docType.AddPropertyType(CotentPageContentPropType, CONTENT_TAB); #endregion contentTypeService.Save(docType); ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_NAME}' has been created"); ContentHelper.CopyPhysicalAssets(new GenericInfoPageEmbeddedResources()); } catch (Exception ex) { logger.Error(typeof(_40_GenericInfoPageDocumentType), ex.Message); logger.Error(typeof(_40_GenericInfoPageDocumentType), ex.StackTrace); } }
private void Init() { Current.Reset(); var factory = Mock.Of <IFactory>(); Current.Factory = factory; var configs = new Configs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); var globalSettings = new GlobalSettings(); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add <IGlobalSettings>(() => globalSettings); var publishedModelFactory = new NoopPublishedModelFactory(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(IPublishedModelFactory))).Returns(publishedModelFactory); // create a content node kit var kit = new ContentNodeKit { ContentTypeId = 2, Node = new ContentNode(1, Guid.NewGuid(), 0, "-1,1", 0, -1, DateTime.Now, 0), DraftData = new ContentData { Name = "It Works2!", Published = false, TemplateId = 0, VersionId = 2, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary <string, PropertyData[]> { { "prop", new[] { new PropertyData { Culture = "", Segment = "", Value = "val2" }, new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr2" }, new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk2" }, new PropertyData { Culture = "dk-DA", Segment = "", Value = "val-da2" }, new PropertyData { Culture = "de-DE", Segment = "", Value = "val-de2" } } } }, CultureInfos = new Dictionary <string, CultureVariation> { // draft data = everything, and IsDraft indicates what's edited { "fr-FR", new CultureVariation { Name = "name-fr2", IsDraft = true, Date = new DateTime(2018, 01, 03, 01, 00, 00) } }, { "en-UK", new CultureVariation { Name = "name-uk2", IsDraft = true, Date = new DateTime(2018, 01, 04, 01, 00, 00) } }, { "dk-DA", new CultureVariation { Name = "name-da2", IsDraft = true, Date = new DateTime(2018, 01, 05, 01, 00, 00) } }, { "de-DE", new CultureVariation { Name = "name-de1", IsDraft = false, Date = new DateTime(2018, 01, 02, 01, 00, 00) } } } }, PublishedData = new ContentData { Name = "It Works1!", Published = true, TemplateId = 0, VersionId = 1, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary <string, PropertyData[]> { { "prop", new[] { new PropertyData { Culture = "", Segment = "", Value = "val1" }, new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr1" }, new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk1" } } } }, CultureInfos = new Dictionary <string, CultureVariation> { // published data = only what's actually published, and IsDraft has to be false { "fr-FR", new CultureVariation { Name = "name-fr1", IsDraft = false, Date = new DateTime(2018, 01, 01, 01, 00, 00) } }, { "en-UK", new CultureVariation { Name = "name-uk1", IsDraft = false, Date = new DateTime(2018, 01, 02, 01, 00, 00) } }, { "de-DE", new CultureVariation { Name = "name-de1", IsDraft = false, Date = new DateTime(2018, 01, 02, 01, 00, 00) } } } } }; // create a data source for NuCache var dataSource = new TestDataSource(kit); var runtime = Mock.Of <IRuntimeState>(); Mock.Get(runtime).Setup(x => x.Level).Returns(RuntimeLevel.Run); // create data types, property types and content types var dataType = new DataType(new VoidEditor("Editor", Mock.Of <ILogger>())) { Id = 3 }; var dataTypes = new[] { dataType }; _propertyType = new PropertyType("Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Culture }; _contentType = new ContentType(-1) { Id = 2, Alias = "alias-ct", Variations = ContentVariation.Culture }; _contentType.AddPropertyType(_propertyType); var contentTypes = new[] { _contentType }; var contentTypeService = new Mock <IContentTypeService>(); contentTypeService.Setup(x => x.GetAll()).Returns(contentTypes); contentTypeService.Setup(x => x.GetAll(It.IsAny <int[]>())).Returns(contentTypes); var mediaTypeService = new Mock <IMediaTypeService>(); mediaTypeService.Setup(x => x.GetAll()).Returns(Enumerable.Empty <IMediaType>()); mediaTypeService.Setup(x => x.GetAll(It.IsAny <int[]>())).Returns(Enumerable.Empty <IMediaType>()); var contentTypeServiceBaseFactory = new Mock <IContentTypeBaseServiceProvider>(); contentTypeServiceBaseFactory.Setup(x => x.For(It.IsAny <IContentBase>())).Returns(contentTypeService.Object); var dataTypeService = Mock.Of <IDataTypeService>(); Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes); // create a service context var serviceContext = ServiceContext.CreatePartial( dataTypeService: dataTypeService, memberTypeService: Mock.Of <IMemberTypeService>(), memberService: Mock.Of <IMemberService>(), contentTypeService: contentTypeService.Object, mediaTypeService: mediaTypeService.Object, localizationService: Mock.Of <ILocalizationService>(), domainService: Mock.Of <IDomainService>() ); // create a scope provider var scopeProvider = Mock.Of <IScopeProvider>(); Mock.Get(scopeProvider) .Setup(x => x.CreateScope( It.IsAny <IsolationLevel>(), It.IsAny <RepositoryCacheMode>(), It.IsAny <IEventDispatcher>(), It.IsAny <bool?>(), It.IsAny <bool>(), It.IsAny <bool>())) .Returns(Mock.Of <IScope>); // create a published content type factory var contentTypeFactory = new PublishedContentTypeFactory( Mock.Of <IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty <IPropertyValueConverter>()), dataTypeService); // create a variation accessor _variationAccesor = new TestVariationContextAccessor(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; _snapshotService = new PublishedSnapshotService(options, null, runtime, serviceContext, contentTypeFactory, null, new TestPublishedSnapshotAccessor(), _variationAccesor, Mock.Of <IProfilingLogger>(), scopeProvider, Mock.Of <IDocumentRepository>(), Mock.Of <IMediaRepository>(), Mock.Of <IMemberRepository>(), new TestDefaultCultureAccessor(), dataSource, globalSettings, Mock.Of <IEntityXmlSerializer>(), Mock.Of <IPublishedModelFactory>(), new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() })); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(IVariationContextAccessor))).Returns(_variationAccesor); }
public void ContentPublishVariations() { const string langFr = "fr-FR"; const string langUk = "en-UK"; const string langEs = "es-ES"; var propertyType = new PropertyType("editor", ValueStorageType.Nvarchar) { Alias = "prop" }; var contentType = new ContentType(-1) { Alias = "contentType" }; contentType.AddPropertyType(propertyType); var content = new Content("content", -1, contentType) { Id = 1, VersionId = 1 }; // change - now we vary by culture contentType.Variations |= ContentVariation.Culture; propertyType.Variations |= ContentVariation.Culture; Assert.Throws <NotSupportedException>(() => content.SetValue("prop", "a")); // invariant = no content.SetValue("prop", "a-fr", langFr); content.SetValue("prop", "a-uk", langUk); content.SetValue("prop", "a-es", langEs); // cannot publish without a name Assert.IsFalse(content.PublishCulture(langFr)); // works with a name // and then FR is available, and published content.SetCultureName("name-fr", langFr); Assert.IsTrue(content.PublishCulture(langFr)); // now UK is available too content.SetCultureName("name-uk", langUk); // test available, published Assert.IsTrue(content.IsCultureAvailable(langFr)); Assert.IsTrue(content.IsCulturePublished(langFr)); Assert.AreEqual("name-fr", content.GetPublishName(langFr)); Assert.AreNotEqual(DateTime.MinValue, content.GetPublishDate(langFr)); Assert.IsFalse(content.IsCultureEdited(langFr)); // once published, edited is *wrong* until saved Assert.IsTrue(content.IsCultureAvailable(langUk)); Assert.IsFalse(content.IsCulturePublished(langUk)); Assert.IsNull(content.GetPublishName(langUk)); Assert.IsNull(content.GetPublishDate(langUk)); // not published Assert.IsFalse(content.IsCultureAvailable(langEs)); Assert.IsFalse(content.IsCultureEdited(langEs)); // not avail, so... not edited Assert.IsFalse(content.IsCulturePublished(langEs)); // not published! Assert.IsNull(content.GetPublishName(langEs)); Assert.IsNull(content.GetPublishDate(langEs)); // cannot test IsCultureEdited here - as that requires the content service and repository // see: ContentServiceTests.Can_SaveRead_Variations }
public void ContentPublishValues() { const string langFr = "fr-FR"; var propertyType = new PropertyType("editor", ValueStorageType.Nvarchar) { Alias = "prop" }; var contentType = new ContentType(-1) { Alias = "contentType" }; contentType.AddPropertyType(propertyType); var content = new Content("content", -1, contentType) { Id = 1, VersionId = 1 }; // can set value // and get edited value, published is null // because publishing content.SetValue("prop", "a"); Assert.AreEqual("a", content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); // cannot set non-supported variation value Assert.Throws <NotSupportedException>(() => content.SetValue("prop", "x", langFr)); Assert.IsNull(content.GetValue("prop", langFr)); // can publish value // and get edited and published values Assert.IsTrue(content.PublishCulture()); Assert.AreEqual("a", content.GetValue("prop")); Assert.AreEqual("a", content.GetValue("prop", published: true)); // can set value // and get edited and published values content.SetValue("prop", "b"); Assert.AreEqual("b", content.GetValue("prop")); Assert.AreEqual("a", content.GetValue("prop", published: true)); // can clear value content.UnpublishCulture(); Assert.AreEqual("b", content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); // change - now we vary by culture contentType.Variations |= ContentVariation.Culture; propertyType.Variations |= ContentVariation.Culture; // can set value // and get values content.SetValue("prop", "c", langFr); Assert.IsNull(content.GetValue("prop")); // there is no invariant value anymore Assert.IsNull(content.GetValue("prop", published: true)); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.IsNull(content.GetValue("prop", langFr, published: true)); // can publish value // and get edited and published values Assert.IsFalse(content.PublishCulture(langFr)); // no name content.SetCultureName("name-fr", langFr); Assert.IsTrue(content.PublishCulture(langFr)); Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.AreEqual("c", content.GetValue("prop", langFr, published: true)); // can clear all content.UnpublishCulture("*"); Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.IsNull(content.GetValue("prop", langFr, published: true)); // can publish all Assert.IsTrue(content.PublishCulture("*")); Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.AreEqual("c", content.GetValue("prop", langFr, published: true)); // same for culture content.UnpublishCulture(langFr); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.IsNull(content.GetValue("prop", langFr, published: true)); content.PublishCulture(langFr); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.AreEqual("c", content.GetValue("prop", langFr, published: true)); content.UnpublishCulture(); // clears invariant props if any Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); content.PublishCulture(); // publishes invariant props if any Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); var other = new Content("other", -1, contentType) { Id = 2, VersionId = 1 }; Assert.Throws <NotSupportedException>(() => other.SetValue("prop", "o")); // don't even try other.SetValue("prop", "o1", langFr); // can copy other's edited value content.CopyFrom(other); Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); Assert.AreEqual("o1", content.GetValue("prop", langFr)); Assert.AreEqual("c", content.GetValue("prop", langFr, published: true)); // can copy self's published value content.CopyFrom(content); Assert.IsNull(content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); Assert.AreEqual("c", content.GetValue("prop", langFr)); Assert.AreEqual("c", content.GetValue("prop", langFr, published: true)); }