public void Can_Change_ContentType_On_Content_And_Set_Property_Value() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType); content.SetValue("author", "John Doe"); // Assert Assert.That(content.Properties.Contains("author"), Is.True); Assert.That(content.Properties["author"].Value, Is.EqualTo("John Doe")); }
public void Can_Change_ContentType_On_Content_And_Clear_Old_PropertyTypes() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType, true); // Assert Assert.That(content.Properties.Contains("author"), Is.True); Assert.That(content.Properties.Contains("keywords"), Is.False); Assert.That(content.Properties.Contains("description"), Is.False); }
public void To_Content_Item_Simple() { var contentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateSimpleContent(contentType); FixUsers(content); var result = Mapper.Map <IContent, ContentItemBasic <ContentPropertyBasic> >(content); AssertBasics(result, content); foreach (var p in content.Properties) { AssertBasicProperty(result, p); } }
public void TagsAreUpdatedWhenContentIsUnpublishedAndRePublished_Tree() { var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; var tagService = ServiceContext.TagService; var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType("test", ValueStorageType.Ntext, "tags") { DataTypeId = 1041 }); contentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); content1.AssignTags("tags", new[] { "hello", "world", "some", "tags", "bam" }); contentService.SaveAndPublish(content1); var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", content1); content2.AssignTags("tags", new[] { "hello", "world", "some", "tags" }); contentService.SaveAndPublish(content2); contentService.Unpublish(content1); var tags = tagService.GetTagsForEntity(content1.Id); Assert.AreEqual(0, tags.Count()); // fixme tag & tree issue // when we (un)publish, we 'just' publish the top one and not the ones below = fails // see similar note above tags = tagService.GetTagsForEntity(content2.Id); Assert.AreEqual(0, tags.Count()); var allTags = tagService.GetAllContentTags(); Assert.AreEqual(0, allTags.Count()); content1.PublishCulture(); contentService.SaveAndPublish(content1); tags = tagService.GetTagsForEntity(content2.Id); Assert.AreEqual(4, tags.Count()); allTags = tagService.GetAllContentTags(); Assert.AreEqual(5, allTags.Count()); }
private IEnumerable <IContent> PrimeDbWithLotsOfContent() { var contentType1 = MockedContentTypes.CreateSimpleContentType(); contentType1.AllowedAsRoot = true; ServiceContext.ContentTypeService.Save(contentType1); contentType1.AllowedContentTypes = new List <ContentTypeSort> { new ContentTypeSort { Alias = contentType1.Alias, Id = new Lazy <int>(() => contentType1.Id), SortOrder = 0 } }; var result = new List <IContent>(); ServiceContext.ContentTypeService.Save(contentType1); IContent lastParent = MockedContent.CreateSimpleContent(contentType1); ServiceContext.ContentService.SaveAndPublish(lastParent); result.Add(lastParent); //create 20 deep for (var i = 0; i < 20; i++) { //for each level, create 20 IContent content = null; for (var j = 1; j <= 10; j++) { content = MockedContent.CreateSimpleContent(contentType1, "Name" + j, lastParent); //only publish evens if (j % 2 == 0) { ServiceContext.ContentService.SaveAndPublish(content); } else { ServiceContext.ContentService.Save(content); } result.Add(content); } //assign the last one as the next parent lastParent = content; } return(result); }
public void Can_Merge_Tag_Relations() { var provider = TestObjects.GetScopeProvider(Logger); using (ScopeProvider.CreateScope()) { var contentRepository = CreateContentRepository(provider, out var contentTypeRepository); //create data to relate to var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! contentTypeRepository.Save(contentType); var content = MockedContent.CreateSimpleContent(contentType); contentRepository.Save(content); var repository = CreateRepository(provider); repository.Assign( content.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" }, }, false); repository.Assign( content.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" }, }, false); var result = repository.GetTagsForEntity(content.Id); Assert.AreEqual(3, result.Count()); } }
public void Can_Get_All_With_Ids() { var provider = TestObjects.GetScopeProvider(Logger); using (ScopeProvider.CreateScope()) { var contentRepository = CreateContentRepository(provider, out var contentTypeRepository); //create data to relate to var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! contentTypeRepository.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType); contentRepository.Save(content1); var content2 = MockedContent.CreateSimpleContent(contentType); contentRepository.Save(content2); var repository = CreateRepository(provider); var tags = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" }, new Tag { Text = "tag4", Group = "test" } }; repository.Assign( content1.Id, contentType.PropertyTypes.First().Id, tags, false); // TODO: This would be nice to be able to map the ids back but unfortunately we are not doing this //var result = repository.GetAll(new[] {tags[0].Id, tags[1].Id, tags[2].Id}); var all = repository.GetMany().ToArray(); var result = repository.GetMany(all[0].Id, all[1].Id, all[2].Id); Assert.AreEqual(3, result.Count()); } }
public void CacheActiveForIntsAndGuids() { var realCache = new CacheHelper( new ObjectCacheRuntimeCacheProvider(), new StaticCacheProvider(), new StaticCacheProvider(), new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider())); var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository, cacheHelper: realCache); var udb = (UmbracoDatabase)scope.Database; udb.EnableSqlCount = false; var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! contentTypeRepository.Save(contentType); var content = MockedContent.CreateSimpleContent(contentType); repository.Save(content); udb.EnableSqlCount = true; //go get it, this should already be cached since the default repository key is the INT repository.Get(content.Id); Assert.AreEqual(0, udb.SqlCount); //retrieve again, this should use cache repository.Get(content.Id); Assert.AreEqual(0, udb.SqlCount); //reset counter udb.EnableSqlCount = false; udb.EnableSqlCount = true; //now get by GUID, this won't be cached yet because the default repo key is not a GUID repository.Get(content.Key); var sqlCount = udb.SqlCount; Assert.Greater(sqlCount, 0); //retrieve again, this should use cache now repository.Get(content.Key); Assert.AreEqual(sqlCount, udb.SqlCount); } }
private Content[] BuildContentItems(int numberToCreate) { var contentType = MockedContentTypes.CreateSimpleContentType(); ServiceContext.ContentTypeService.Save(contentType); var startContentItems = new List <Content>(); for (var i = 0; i < numberToCreate; i++) { startContentItems.Add(MockedContent.CreateSimpleContent(contentType)); } ServiceContext.ContentService.Save(startContentItems); return(startContentItems.ToArray()); }
public void To_Content_Item_Dto() { var contentType = MockedContentTypes.CreateSimpleContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); var content = MockedContent.CreateSimpleContent(contentType); FixUsers(content); var result = Mapper.Map <IContent, ContentPropertyCollectionDto>(content); foreach (var p in content.Properties) { AssertProperty(result, p); } }
public void Can_Change_ContentType_On_Content_And_Still_Get_Old_Properties() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType); // Assert Assert.That(content.Properties.Contains("author"), Is.True); Assert.That(content.Properties.Contains("keywords"), Is.True); Assert.That(content.Properties.Contains("description"), Is.True); Assert.That(content.Properties["keywords"].Value, Is.EqualTo("text,page,meta")); Assert.That(content.Properties["description"].Value, Is.EqualTo("This is the meta description for a textpage")); }
public void Can_Change_ContentType_On_Content() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType); // Assert Assert.That(content.Properties.Contains("author"), Is.True); Assert.That(content.PropertyGroups.Count(), Is.EqualTo(1)); Assert.That(content.PropertyTypes.Count(), Is.EqualTo(3)); //Note: There was 4 properties, after changing ContentType 1 has been added (no properties are deleted) Assert.That(content.Properties.Count, Is.EqualTo(5)); }
public void Rebuild_All_Xml_Structures() { var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); ContentTypeRepository contentTypeRepository; using (var repository = CreateRepository(unitOfWork, out contentTypeRepository)) { var contentType1 = MockedContentTypes.CreateSimpleContentType("Textpage1", "Textpage1"); contentTypeRepository.AddOrUpdate(contentType1); var allCreated = new List <IContent>(); for (var i = 0; i < 100; i++) { //These will be non-published so shouldn't show up var c1 = MockedContent.CreateSimpleContent(contentType1); repository.AddOrUpdate(c1); allCreated.Add(c1); } for (var i = 0; i < 100; i++) { var c1 = MockedContent.CreateSimpleContent(contentType1); c1.ChangePublishedState(PublishedState.Published); repository.AddOrUpdate(c1); allCreated.Add(c1); } unitOfWork.Commit(); //now create some versions of this content - this shouldn't affect the xml structures saved for (int i = 0; i < allCreated.Count; i++) { allCreated[i].Name = "blah" + i; repository.AddOrUpdate(allCreated[i]); } unitOfWork.Commit(); //delete all xml unitOfWork.Database.Execute("DELETE FROM cmsContentXml"); Assert.AreEqual(0, unitOfWork.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM cmsContentXml")); repository.RebuildXmlStructures(media => new XElement("test"), 10); Assert.AreEqual(100, unitOfWork.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM cmsContentXml")); } }
public void Can_Change_ContentType_On_Content_And_Set_Property_Value() { // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType); content.SetValue("author", "John Doe"); // Assert Assert.That(content.Properties.Contains("author"), Is.True); Assert.That(content.Properties["author"].GetValue(), Is.EqualTo("John Doe")); }
public void Can_Change_ContentType_On_Content() { // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType); // Assert Assert.That(content.Properties.Contains("author"), Is.True); //Note: There was 4 properties, after changing ContentType 1 has been added (no properties are deleted) Assert.That(content.Properties.Count, Is.EqualTo(5)); }
public void PerformContentVersionCleanup_WithNoKeepPeriods_DeletesEverythingExceptActive() { // For reference currently has // 5000 Documents // With 200K Versions // With 11M Property data var contentTypeA = MockedContentTypes.CreateSimpleContentType("contentTypeA", "contentTypeA"); // Kill all historic contentTypeA.HistoryCleanup.PreventCleanup = false; contentTypeA.HistoryCleanup.KeepAllVersionsNewerThanDays = 0; contentTypeA.HistoryCleanup.KeepLatestVersionPerDayForDays = 0; ServiceContext.FileService.SaveTemplate(contentTypeA.DefaultTemplate); ServiceContext.ContentTypeService.Save(contentTypeA); var content = MockedContent.CreateSimpleContent(contentTypeA); ServiceContext.ContentService.SaveAndPublish(content, raiseEvents: false); for (var i = 0; i < 10; i++) { ServiceContext.ContentService.SaveAndPublish(content, raiseEvents: false); } var before = GetReport(); Debug.Assert(before.ContentVersions == 12); // 10 historic + current draft + current published Debug.Assert(before.PropertyData == 12 * 3); // CreateSimpleContentType = 3 props ((IContentVersionService)ServiceContext.ContentService).PerformContentVersionCleanup(DateTime.Now.AddHours(1)); var after = GetReport(); Assert.Multiple(() => { Assert.AreEqual(2, after.ContentVersions); // current draft, current published Assert.AreEqual(2, after.DocumentVersions); Assert.AreEqual(6, after.PropertyData); // CreateSimpleContentType = 3 props }); }
public void To_Display_Model_No_Tabs() { var contentType = MockedContentTypes.CreateSimpleContentType(); contentType.PropertyGroups.Clear(); var content = new Content("Home", -1, contentType) { Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0 }; var result = Mapper.Map <IContent, ContentItemDisplay>(content); AssertBasics(result, content); foreach (var p in content.Properties) { AssertDisplayProperty(result, p, ApplicationContext); } Assert.AreEqual(content.PropertyGroups.Count(), result.Tabs.Count()); }
public void TagList_Contains_NodeCount() { var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; var tagService = ServiceContext.TagService; var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType("test", DataTypeDatabaseType.Ntext, "tags") { DataTypeDefinitionId = 1041 }); contentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); content1.SetTags("tags", new[] { "cow", "pig", "goat" }, true); contentService.Publish(content1); var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); content2.SetTags("tags", new[] { "cow", "pig" }, true); contentService.Publish(content2); var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1); content3.SetTags("tags", new[] { "cow" }, true); contentService.Publish(content3); // Act var tags = tagService.GetAllContentTags() .OrderByDescending(x => x.NodeCount) .ToList(); // Assert Assert.AreEqual(3, tags.Count()); Assert.AreEqual("cow", tags[0].Text); Assert.AreEqual(3, tags[0].NodeCount); Assert.AreEqual("pig", tags[1].Text); Assert.AreEqual(2, tags[1].NodeCount); Assert.AreEqual("goat", tags[2].Text); Assert.AreEqual(1, tags[2].NodeCount); }
private IContentType GetMockedContentType() { var contentType = MockedContentTypes.CreateSimpleContentType(); //ensure things have ids var ids = 888; foreach (var g in contentType.CompositionPropertyGroups) { g.Id = ids; ids++; } foreach (var p in contentType.CompositionPropertyGroups) { p.Id = ids; ids++; } return(contentType); }
public void TagList_Contains_NodeCount() { var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; var tagService = ServiceContext.TagService; var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType(Constants.PropertyEditors.Aliases.Tags, ValueStorageType.Ntext, "tags") { DataTypeId = Constants.DataTypes.Tags }); contentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); content1.AssignTags("tags", new[] { "cow", "pig", "goat" }); contentService.SaveAndPublish(content1); var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); content2.AssignTags("tags", new[] { "cow", "pig" }); contentService.SaveAndPublish(content2); var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1); content3.AssignTags("tags", new[] { "cow" }); contentService.SaveAndPublish(content3); // Act var tags = tagService.GetAllContentTags() .OrderByDescending(x => x.NodeCount) .ToList(); // Assert Assert.AreEqual(3, tags.Count); Assert.AreEqual("cow", tags[0].Text); Assert.AreEqual(3, tags[0].NodeCount); Assert.AreEqual("pig", tags[1].Text); Assert.AreEqual(2, tags[1].NodeCount); Assert.AreEqual("goat", tags[2].Text); Assert.AreEqual(1, tags[2].NodeCount); }
public void Cascade_Deletes_Tag_Relations() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var contentRepository = CreateContentRepository(provider, out var contentTypeRepository); //create data to relate to var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! contentTypeRepository.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType); contentRepository.Save(content1); var repository = CreateRepository(provider); repository.Assign( content1.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" }, new Tag { Text = "tag4", Group = "test" } }, false); contentRepository.Delete(content1); Assert.AreEqual(0, scope.Database.ExecuteScalar <int>( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content1.Id, propTypeId = contentType.PropertyTypes.First().Id })); } }
public void SaveContent() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository); var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! IContent textpage = MockedContent.CreateSimpleContent(contentType); contentTypeRepository.Save(contentType); repository.Save(textpage); scope.Complete(); Assert.That(contentType.HasIdentity, Is.True); Assert.That(textpage.HasIdentity, Is.True); } }
public void Can_Perform_Add_On_ContentTypeRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = RepositoryResolver.Current.ResolveByType <IContentTypeRepository>(unitOfWork); // Act var contentType = MockedContentTypes.CreateSimpleContentType(); repository.AddOrUpdate(contentType); unitOfWork.Commit(); // Assert Assert.That(contentType.HasIdentity, Is.True); Assert.That(contentType.PropertyGroups.All(x => x.HasIdentity), Is.True); Assert.That(contentType.Path.Contains(","), Is.True); Assert.That(contentType.SortOrder, Is.GreaterThan(0)); }
public void PropertyDataAssignedCorrectly() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository, out DataTypeRepository _); var emptyContentType = MockedContentTypes.CreateBasicContentType(); var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage"); contentTypeRepository.Save(emptyContentType); contentTypeRepository.Save(hasPropertiesContentType); ServiceContext.FileService.SaveTemplate(hasPropertiesContentType.DefaultTemplate); // else, FK violation on contentType! var content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType); var content2 = MockedContent.CreateBasicContent(emptyContentType); var content3 = MockedContent.CreateSimpleContent(hasPropertiesContentType); repository.Save(content1); repository.Save(content2); repository.Save(content3); // this will cause the GetPropertyCollection to execute and we need to ensure that // all of the properties and property types are all correct var result = repository.GetMany(content1.Id, content2.Id, content3.Id).ToArray(); var n1 = result[0]; var n2 = result[1]; var n3 = result[2]; Assert.AreEqual(content1.Id, n1.Id); Assert.AreEqual(content2.Id, n2.Id); Assert.AreEqual(content3.Id, n3.Id); // compare everything including properties and their values // this ensures that they have been properly retrieved TestHelper.AssertPropertyValuesAreEqual(content1, n1); TestHelper.AssertPropertyValuesAreEqual(content2, n2); TestHelper.AssertPropertyValuesAreEqual(content3, n3); } }
public void Can_Verify_AllowedChildContentTypes_On_ContentType() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); using (var repository = CreateRepository(unitOfWork)) { var subpageContentType = MockedContentTypes.CreateSimpleContentType("umbSubpage", "Subpage"); var simpleSubpageContentType = MockedContentTypes.CreateSimpleContentType("umbSimpleSubpage", "Simple Subpage"); repository.AddOrUpdate(subpageContentType); repository.AddOrUpdate(simpleSubpageContentType); unitOfWork.Commit(); // Act var contentType = repository.Get(1045); contentType.AllowedContentTypes = new List <ContentTypeSort> { new ContentTypeSort { Alias = subpageContentType.Alias, Id = new Lazy <int>(() => subpageContentType.Id), SortOrder = 0 }, new ContentTypeSort { Alias = simpleSubpageContentType.Alias, Id = new Lazy <int>(() => simpleSubpageContentType.Id), SortOrder = 1 } }; repository.AddOrUpdate(contentType); unitOfWork.Commit(); //Assert var updated = repository.Get(1045); Assert.That(updated.AllowedContentTypes.Any(), Is.True); Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == subpageContentType.Alias), Is.True); Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == simpleSubpageContentType.Alias), Is.True); } }
public void Can_Perform_Delete_When_Assigned_To_Doc() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var templateRepository = CreateRepository(unitOfWork)) { var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax); var contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax, templateRepository); var contentRepo = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax, contentTypeRepository, templateRepository, tagRepository, Mock.Of <IContentSection>()); using (contentRepo) { var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage"); var textpage = MockedContent.CreateSimpleContent(contentType); contentTypeRepository.AddOrUpdate(contentType); contentRepo.AddOrUpdate(textpage); unitOfWork.Commit(); var template = new Template("test", "test") { Content = @"<%@ Master Language=""C#"" %>" }; templateRepository.AddOrUpdate(template); unitOfWork.Commit(); textpage.Template = template; contentRepo.AddOrUpdate(textpage); unitOfWork.Commit(); // Act var templates = templateRepository.Get("test"); templateRepository.Delete(templates); unitOfWork.Commit(); // Assert Assert.IsNull(templateRepository.Get("test")); } } }
public void Can_Change_ContentType_On_Content_And_Still_Get_Old_Properties() { // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); var simpleContentType = MockedContentTypes.CreateSimpleContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ChangeContentType(simpleContentType); // Assert Assert.That(content.Properties.Contains("author"), Is.True); Assert.That(content.Properties.Contains("keywords"), Is.True); Assert.That(content.Properties.Contains("description"), Is.True); Assert.That(content.Properties["keywords"].GetValue(), Is.EqualTo("text,page,meta")); Assert.That(content.Properties["description"].GetValue(), Is.EqualTo("This is the meta description for a textpage")); }
public void Can_Perform_Add_On_ContentRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var contentTypeRepository = RepositoryResolver.Current.ResolveByType <IContentTypeRepository>(unitOfWork); var repository = RepositoryResolver.Current.ResolveByType <IContentRepository>(unitOfWork); ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); Content textpage = MockedContent.CreateSimpleContent(contentType); // Act contentTypeRepository.AddOrUpdate(contentType); repository.AddOrUpdate(textpage); unitOfWork.Commit(); // Assert Assert.That(contentType.HasIdentity, Is.True); Assert.That(textpage.HasIdentity, Is.True); }
public void Can_Remove_Rule() { // Arrange var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); ServiceContext.FileService.SaveTemplate(ct.DefaultTemplate); contentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); contentService.Save(c); var publicAccessService = ServiceContext.PublicAccessService; var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() { RuleType = "TestType", RuleValue = "TestValue1" }, new PublicAccessRule() { RuleType = "TestType", RuleValue = "TestValue2" }, }); publicAccessService.Save(entry); // Act var removed = publicAccessService.RemoveRule(c, "TestType", "TestValue1"); //re-get entry = publicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(removed.Success); Assert.AreEqual(OperationResultType.Success, removed.Result.Result); Assert.AreEqual(1, entry.Rules.Count()); Assert.AreEqual("TestValue2", entry.Rules.ElementAt(0).RuleValue); }
public void GetDocumentVersionsEligibleForCleanup_Always_ExcludesPinnedVersions() { var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); ServiceContext.ContentTypeService.Save(contentType); var content = MockedContent.CreateSimpleContent(contentType); ServiceContext.ContentService.SaveAndPublish(content); // At this point content has 2 versions, a draft version and a published version. ServiceContext.ContentService.SaveAndPublish(content); ServiceContext.ContentService.SaveAndPublish(content); ServiceContext.ContentService.SaveAndPublish(content); // At this point content has 5 versions, 3 historic versions, a draft version and a published version. var allVersions = ServiceContext.ContentService.GetVersions(content.Id); Debug.Assert(allVersions.Count() == 5); // Sanity check var scopeProvider = TestObjects.GetScopeProvider(Logger); using (var scope = scopeProvider.CreateScope()) { scope.Database.Update <ContentVersionDto>("set preventCleanup = 1 where id in (1,3)"); var sut = new DocumentVersionRepository((IScopeAccessor)scopeProvider); var results = sut.GetDocumentVersionsEligibleForCleanup(); Assert.Multiple(() => { Assert.AreEqual(1, results.Count); // We pinned 1 & 3 // 4 is current // 5 is published // So all that is left is 2 Assert.AreEqual(2, results.First().VersionId); }); } }