private void CreateAndPublish(Post p) { var stream = getStream(); if (stream != null) { var cs = new ContentService(); int postId; IContent post; if (TryGetPostId(p, out postId)) post = cs.GetById(postId); else { var parent = createFolderScructure(p.Date, stream); post = cs.CreateContent(p.Name, parent, PostTypeAlias); } MarkdownSharp.Markdown md = new Markdown(); post.SetValue("bodyText", md.Transform(p.Content)); post.SetValue("postDate", p.Date); if (p.Draft) cs.Save(post); else cs.SaveAndPublish(post); } }
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); }
//Updates a Match document public Match Put(Match match) { var cs = new ContentService(); var content = cs.GetById(match.Id); content.Name = match.Name; cs.SaveAndPublish(content); return match; }
public void Delete(Post p) { int id; if (TryGetPostId(p, out id)) { var cs = new ContentService(); var post = cs.GetById(id); cs.UnPublish(post); cs.Delete(post); } }
public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService() { //Assign var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{C382AE57-D325-4357-A32A-0A959BBD4101}")); var service = Substitute.For<IUmbracoService>(); service.ContentService.Returns(contentService); var context = new UmbracoDataMappingContext(null, content, service); var config = new UmbracoParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new UmbracoParentMapper(); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act mapper.MapToProperty(context); //Assert //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails. service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is<IContent>(x => x.Id == content.ParentId), false, false); }
public void MapToProperty_UmbracoInfoType_GetsExpectedValueFromUmbraco( [Values( //UmbracoInfoType.Url, UmbracoInfoType.ContentTypeAlias, UmbracoInfoType.ContentTypeName, UmbracoInfoType.Name, UmbracoInfoType.Creator )] UmbracoInfoType type, [Values( //"target", //Url "TestType", //ContentTypeAlias "Test Type", //ContentTypeName "Target", //Name "admin" //Creator )] object expected ) { //Assign var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var dataContext = new UmbracoDataMappingContext(null, content, null); //Act var value = mapper.MapToProperty(dataContext); Console.WriteLine(type); //Assert Assert.AreEqual(expected, value); }
private int Plant(int rootDocId) { var contentService = new ContentService(); var rootDoc = contentService.GetById(rootDocId); if (rootDoc.Level <= _maxDepth) { var allowedContentTypes = rootDoc.ContentType.AllowedContentTypes.ToArray(); if (!allowedContentTypes.Any()) return 0; foreach (var docType in allowedContentTypes) { for (int i = 0; i < _numberOfEachDocTypeToCreate; i++) { var newContent = contentService.CreateContent("Forrester Created Content", rootDoc, docType.Alias, User.Id); SetDynamicNodeName(newContent); if (_publish) { contentService.SaveAndPublish(newContent); } else { contentService.Save(newContent); } _nodesCreated++; Plant(newContent.Id); } } } return _nodesCreated; }
//Deletes a Match document public void Delete(int matchId) { var cs = new ContentService(); var content = cs.GetById(matchId); cs.Delete(content); }
public void MapToProperty_UmbracoInfoTypeNotSet_ThrowsException() { //Assign UmbracoInfoType type = UmbracoInfoType.NotSet; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var dataContext = new UmbracoDataMappingContext(null, content, null); //Act var value = mapper.MapToProperty(dataContext); //Assert //No asserts expect exception }
public void MapToCms_SavingName_UpdatesTheItemName() { //Assign var type = UmbracoInfoType.Name; var expected = "new name"; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); var oldName = content.Name; Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var context = Context.Create(DependencyResolver.CreateStandardResolver()); var dataContext = new UmbracoDataMappingContext(null, content, new UmbracoService(contentService, context)); dataContext.PropertyValue = expected; string actual = string.Empty; //Act mapper.MapToCms(dataContext); content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); actual = content.Name; //Assert Assert.AreEqual(expected, actual); content.Name = oldName; contentService.Save(content); }
public void MapToProperty_UmbracoInfoTypeUpdateDate_ReturnsUpdateDateAsDateTime() { //Assign var type = UmbracoInfoType.UpdateDate; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); var expected = content.UpdateDate; Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var dataContext = new UmbracoDataMappingContext(null, content, null); //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); }