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); }
private IEnumerable <EntityContainer> GetEntityContainers(IContentTypeComposition?contentType, UmbracoObjectTypes type) { if (contentType == null) { return(Enumerable.Empty <EntityContainer>()); } switch (type) { case UmbracoObjectTypes.DocumentType: if (contentType is IContentType documentContentType) { return(ContentTypeService.GetContainers(documentContentType)); } return(Enumerable.Empty <EntityContainer>()); case UmbracoObjectTypes.MediaType: if (contentType is IMediaType mediaContentType) { return(MediaTypeService.GetContainers(mediaContentType)); } return(Enumerable.Empty <EntityContainer>()); case UmbracoObjectTypes.MemberType: return(Enumerable.Empty <EntityContainer>()); default: throw new ArgumentOutOfRangeException("The entity type was not a content type"); } }
public void Getting_1000_Uncached_Items() { // Arrange var contentType = ContentTypeService.Get(ContentType.Id); var pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); ContentService.Save(pages, 0); using (var scope = ScopeProvider.CreateScope()) { var repository = DocumentRepository; // Act var watch = Stopwatch.StartNew(); var contents = repository.GetMany(); watch.Stop(); var elapsed = watch.ElapsedMilliseconds; Debug.Print("1000 content items retrieved in {0} ms without caching", elapsed); // Assert // Assert.That(contents.Any(x => x.HasIdentity == false), Is.False); // Assert.That(contents.Any(x => x == null), Is.False); } }
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 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); }
protected virtual void Reset() { // reset and dispose scopes // ensures we don't leak an opened database connection // which would lock eg SqlCe .sdf files if (Factory?.TryGetInstance <IScopeProvider>() is ScopeProvider scopeProvider) { Scope scope; while ((scope = scopeProvider.AmbientScope) != null) { scope.Reset(); scope.Dispose(); } } Current.Reset(); // disposes the factory // reset all other static things that should not be static ;( UriUtility.ResetAppDomainAppVirtualPath(); SettingsForTests.Reset(); // fixme - should it be optional? Mapper.Reset(); // clear static events DocumentRepository.ClearScopeEvents(); MediaRepository.ClearScopeEvents(); MemberRepository.ClearScopeEvents(); ContentTypeService.ClearScopeEvents(); MediaTypeService.ClearScopeEvents(); MemberTypeService.ClearScopeEvents(); }
public void Getting_1000_Cached_Items() { // Arrange IContentType contentType = ContentTypeService.Get(ContentType.Id); IEnumerable <Content> pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); ContentService.Save(pages, 0); using (IScope scope = ScopeProvider.CreateScope()) { DocumentRepository repository = DocumentRepository; // Act IEnumerable <IContent> contents = repository.GetMany(); var watch = Stopwatch.StartNew(); IEnumerable <IContent> contentsCached = repository.GetMany(); watch.Stop(); long elapsed = watch.ElapsedMilliseconds; Debug.Print("1000 content items retrieved in {0} ms with caching", elapsed); // Assert // Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False); // Assert.That(contentsCached.Any(x => x == null), Is.False); // Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count())); } }
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 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); }
public void Setup() { _mockContentTypeRepository = new Mock <IContentTypeRepository>(); _mockSaleRepository = new Mock <ISaleRepository>(); _mockDataRepositoryFactory = new Mock <IDataRepositoryFactory>(); _contentTypeService = new ContentTypeService(_mockDataRepositoryFactory.Object); _saleService = new SaleService(_mockDataRepositoryFactory.Object); }
public void Run() { Initialise("TypeSet1"); var types = ContentTypeService.GetAllContentTypes(); var expectedTypes = GetTypes(); AssertContentTypes(types, expectedTypes); }
public static void AddSocialMediaChannelTheme(string theme) { string themesPath = HttpContext.Current.Server.MapPath(SOCIAL_MEDIA_CHANNELS_FOLDER); string newThemePath = Path.Combine(themesPath, theme); DirectoryInfo newThemeDir = new DirectoryInfo(newThemePath); MediaService mediaService = (MediaService)ApplicationContext.Current.Services.MediaService; var rootFolderId = mediaService.GetMediaOfMediaType(1031).Where(x => x.Name == SOCIAL_MEDIA_THEME_FOLDER_NAME).FirstOrDefault().Id; //Get the media type id ContentTypeService cts = (ContentTypeService)ApplicationContext.Current.Services.ContentTypeService; int mediaTypeId = cts.GetMediaType(SOCIAL_MEDIA_THEME_ALIAS).Id; FileInfo infoFile = newThemeDir.GetFiles("info.txt")[0]; string themeDir = newThemeDir.Name; string thumbnailPath = Path.Combine(newThemeDir.Parent.FullName, themeDir + ".jpg"); string themeNick, themeName, themeUrl, themeCreatedBy, themeCreatedDate; using (StreamReader reader = new StreamReader(infoFile.FullName)) { themeNick = reader.ReadLine(); themeName = reader.ReadLine(); themeCreatedBy = reader.ReadLine(); themeUrl = reader.ReadLine(); themeCreatedDate = reader.ReadLine(); } bool newTheme = mediaService.GetMediaOfMediaType(mediaTypeId).Where(x => x.GetValue("themeName").ToString() == themeName).Count() == 0; if (newTheme)//only add if it's new { var themePck = mediaService.CreateMedia(themeNick, rootFolderId, SOCIAL_MEDIA_THEME_ALIAS); var thumbnail = new FileStream(thumbnailPath, FileMode.Open); themePck.SetValue("umbracoFile", Path.GetFileName(thumbnailPath), thumbnail); themePck.SetValue("themeName", themeName); themePck.SetValue("themeUrl", themeUrl); themePck.SetValue("createdBy", themeCreatedBy); themePck.SetValue("createdDate", themeCreatedDate); mediaService.Save(themePck); int currThemeId = mediaService.GetMediaOfMediaType(mediaTypeId).Where(x => x.GetValue("themeName").ToString() == themeName).FirstOrDefault().Id; foreach (FileInfo image in newThemeDir.EnumerateFiles()) { if (!image.Extension.Equals(".txt") && !image.Extension.Equals(".xml")) { var media = mediaService.CreateMedia(image.Name, currThemeId, "Image"); var channel = new FileStream(image.FullName, FileMode.Open); media.SetValue("umbracoFile", Path.GetFileName(image.FullName), channel); mediaService.Save(media); } } } }
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); }
public void CreateTestData() { Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // Create and Save ContentType "textpage" -> ContentType.Id ContentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); ContentTypeService.Save(ContentType); }
public void CreateTestData() { var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // else, FK violation on contentType! var ct = ContentTypeBuilder.CreateSimpleContentType("blah", "Blah", defaultTemplateId: template.Id); ContentTypeService.Save(ct); _content = ContentBuilder.CreateSimpleContent(ct, "Test"); ContentService.Save(_content); }
public void Automatically_Track_Relations() { var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); MediaTypeService.Save(mt); var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); var m2 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); MediaService.Save(m1); MediaService.Save(m2); var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest", defaultTemplateId: template.Id); ct.AllowedTemplates = Enumerable.Empty <ITemplate>(); ContentTypeService.Save(ct); var c1 = ContentBuilder.CreateTextpageContent(ct, "my content 1", -1); ContentService.Save(c1); var c2 = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); // 'bodyText' is a property with a RTE property editor which we knows tracks relations c2.Properties["bodyText"].SetValue(@"<p> <img src='/media/12312.jpg' data-udi='umb://media/" + m1.Key.ToString("N") + @"' /> </p><p><img src='/media/234234.jpg' data-udi=""umb://media/" + m2.Key.ToString("N") + @""" /> </p> <p> <a href=""{locallink:umb://document/" + c1.Key.ToString("N") + @"}"">hello</a> </p>"); ContentService.Save(c2); var relations = RelationService.GetByParentId(c2.Id).ToList(); Assert.AreEqual(3, relations.Count); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias); Assert.AreEqual(m1.Id, relations[0].ChildId); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias); Assert.AreEqual(m2.Id, relations[1].ChildId); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias); Assert.AreEqual(c1.Id, relations[2].ChildId); }
private ValidateContentTypeFilterAttribute CreateFilter(IEnumerable <TextOutputFormatter> formatters = null) { if (formatters == null) { var formatter = Substitute.For <TextOutputFormatter>(); formatter.SupportedMediaTypes.Add("application/fhir+xml"); formatter.SupportedMediaTypes.Add("application/fhir+json"); formatter.CanWriteResult(Arg.Any <OutputFormatterCanWriteContext>()).Returns(true); formatters = new[] { formatter }; } var service = new ContentTypeService(_conformanceProvider, formatters); return(new ValidateContentTypeFilterAttribute(service)); }
public void CreateTestData() { var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // else, FK violation on contentType! _contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", defaultTemplateId: template.Id); _contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "tags") { DataTypeId = Constants.DataTypes.Tags }); ContentTypeService.Save(_contentType); }
private void SetupAllowedChildren(IEnumerable <KeyValuePair <IContentType, DocumentTypeMetadata> > contentTypes) { var allKnownContentTypes = ContentTypeService.GetAllContentTypes().ToArray(); foreach (var item in contentTypes) { var ct = item.Key; var metadata = item.Value; ct.AllowedContentTypes = allKnownContentTypes .Where(c => metadata.AllowedChildren.Any(x => x.Alias == c.Alias)) .Select((c, i) => new ContentTypeSort { Id = new System.Lazy <int>(() => c.Id), SortOrder = i }); } }
public void Creating_1000_Items() { // Arrange IContentType contentType = ContentTypeService.Get(ContentType.Id); IEnumerable <Content> pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); // Act var watch = Stopwatch.StartNew(); ContentService.Save(pages, 0); watch.Stop(); long elapsed = watch.ElapsedMilliseconds; Debug.Print("100 content items saved in {0} ms", elapsed); // Assert Assert.That(pages.Any(x => x.HasIdentity == false), Is.False); }
public void Run() { Initialise("TypeSet3"); var dataTypes = DataTypeService.GetAllDataTypeDefinitions(); var expectedDataTypes = GetDataTypes(); AssertDataTypes(dataTypes, expectedDataTypes); var docTypes = ContentTypeService.GetAllContentTypes(); var expectedDocTypes = GetDocTypes(); AssertContentTypes(docTypes, expectedDocTypes); var mediaTypes = ContentTypeService.GetAllMediaTypes(); var expectedMediaTypes = GetMediaTypes(); AssertContentTypes(mediaTypes, expectedMediaTypes); }
/// <summary> /// Creates a new api from the currently registered /// repositories. /// </summary> public Api( IContentFactory contentFactory, IAliasRepository aliasRepository, IArchiveRepository archiveRepository, IContentRepository contentRepository, IContentGroupRepository contentGroupRepository, IContentTypeRepository contentTypeRepository, ILanguageRepository languageRepository, IMediaRepository mediaRepository, IPageRepository pageRepository, IPageTypeRepository pageTypeRepository, IParamRepository paramRepository, IPostRepository postRepository, IPostTypeRepository postTypeRepository, ISiteRepository siteRepository, ISiteTypeRepository siteTypeRepository, ICache cache = null, IStorage storage = null, IImageProcessor processor = null, ISearch search = null) { // Store the cache _cache = cache; // Create services without dependencies ContentGroups = new ContentGroupService(contentGroupRepository, cache); ContentTypes = new ContentTypeService(contentTypeRepository, cache); Languages = new LanguageService(languageRepository, cache); PageTypes = new PageTypeService(pageTypeRepository, cache); Params = new ParamService(paramRepository, cache); PostTypes = new PostTypeService(postTypeRepository, cache); SiteTypes = new SiteTypeService(siteTypeRepository, cache); // Create services with dependencies Content = new ContentService(contentRepository, contentFactory, Languages, cache, search); Sites = new SiteService(siteRepository, contentFactory, Languages, cache); Aliases = new AliasService(aliasRepository, Sites, cache); Media = new MediaService(mediaRepository, Params, storage, processor, cache); Pages = new PageService(pageRepository, contentFactory, Sites, Params, Media, cache, search); Posts = new PostService(postRepository, contentFactory, Sites, Pages, Params, Media, cache, search); Archives = new ArchiveService(archiveRepository, Params, Posts); }
/// <summary> /// Gets a dictionary containg the pre values associated with a property matching the /// specified <code>contentTypeAlias</code> and <code>propertyAlias</code>. /// </summary> /// <param name="contentTypeAlias">The alias of the content type.</param> /// <param name="propertyAlias">The alias of the property.</param> public static IDictionary <string, string> GetPreValues(string contentTypeAlias, string propertyAlias) { // Get a reference to the content type IContentType contentType = ContentTypeService.GetContentType(contentTypeAlias); if (contentType == null) { return(new Dictionary <string, string>()); } // Find the property matching the specified property alias PropertyType property = ( contentType.PropertyTypes.FirstOrDefault(x => x.Alias == propertyAlias) ?? contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propertyAlias) ); // Get the pre values based on the data type definition ID return(property == null ? new Dictionary <string, string>() : GetPreValues(property.DataTypeDefinitionId)); }
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 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); }
public virtual void CreateTestData() { // NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested. var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // Create and Save ContentType "umbTextpage" -> 1051 (template), 1052 (content type) ContentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); ContentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"); ContentTypeService.Save(ContentType); // Create and Save Content "Homepage" based on "umbTextpage" -> 1053 Textpage = ContentBuilder.CreateSimpleContent(ContentType); Textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"); ContentService.Save(Textpage, 0); // Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054 Subpage = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 1", Textpage.Id); var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null); ContentService.Save(Subpage, 0, contentSchedule); // Create and Save Content "Text Page 1" based on "umbTextpage" -> 1055 Subpage2 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 2", Textpage.Id); ContentService.Save(Subpage2, 0); Subpage3 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 3", Textpage.Id); ContentService.Save(Subpage3, 0); // Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1056 Trashed = ContentBuilder.CreateSimpleContent(ContentType, "Text Page Deleted", -20); Trashed.Trashed = true; ContentService.Save(Trashed, 0); }
public static IServiceCollection AddSpeedWagonCms(this IServiceCollection services, string path, string uploadsPath, IFileProvider contentFileProvider, IFileProvider uploadFileProvider) { IContentService contentService = new CacheLessRuntimeContentService(path, null, contentFileProvider); IEditorService editorService = new EditorService(contentService, SPEEDWAGON_HOST); IContentTypeService contentTypeService = new ContentTypeService(contentService, SPEEDWAGON_HOST); IWebContentService webContentService = new WebContentService(contentService, SPEEDWAGON_HOST); IContentService uploadContentService = new CacheLessRuntimeContentService(uploadsPath, null, uploadFileProvider); IFileUploadService fileUploadService = new FileUploadService(uploadContentService, string.Empty, uploadFileProvider); ISearchService searchService = new LuceneSearchService(contentService, Path.Combine(path, "search")); services.AddSingleton <ISpeedWagonAdminContext>(s => new SpeedWagonAdminContext( path, contentService, contentTypeService, editorService, webContentService, fileUploadService, searchService) ); return(services); }
public void Retrieving_All_Content_In_Site() { // NOTE: Doing this the old 1 by 1 way and based on the results of the ContentServicePerformanceTest.Retrieving_All_Content_In_Site // the old way takes 143795ms, the new above way takes: // 14249ms // // ... NOPE, made some new changes, it is now.... // 5290ms !!!!!! // // that is a 96% savings of processing and sql calls! // // ... NOPE, made even more nice changes, it is now... // 4452ms !!!!!!! Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType1 = ContentTypeBuilder.CreateTextPageContentType("test1", "test1", defaultTemplateId: template.Id); ContentType contentType2 = ContentTypeBuilder.CreateTextPageContentType("test2", "test2", defaultTemplateId: template.Id); ContentType contentType3 = ContentTypeBuilder.CreateTextPageContentType("test3", "test3", defaultTemplateId: template.Id); ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); contentType1.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 0, contentType2.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType2.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType3.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 1, contentType2.Alias) }; ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); IEnumerable <Content> roots = ContentBuilder.CreateTextpageContent(contentType1, -1, 10); ContentService.Save(roots); foreach (Content root in roots) { IEnumerable <Content> item1 = ContentBuilder.CreateTextpageContent(contentType1, root.Id, 10); IEnumerable <Content> item2 = ContentBuilder.CreateTextpageContent(contentType2, root.Id, 10); IEnumerable <Content> item3 = ContentBuilder.CreateTextpageContent(contentType3, root.Id, 10); ContentService.Save(item1.Concat(item2).Concat(item3)); } var total = new List <IContent>(); using (GetTestProfilingLogger().TraceDuration <ContentServicePerformanceTest>("Getting all content in site")) { TestProfiler.Enable(); total.AddRange(ContentService.GetRootContent()); foreach (IContent content in total.ToArray()) { total.AddRange(ContentService.GetPagedDescendants(content.Id, 0, int.MaxValue, out long _)); } TestProfiler.Disable(); StaticApplicationLogging.Logger.LogInformation("Returned {Total} items", total.Count); } }
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); }