public void Can_Perform_Get_By_Missing_Guid_On_ContentTypeRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act IContentType result = repository.Get(Guid.NewGuid()); // Assert Assert.That(result, Is.Null); } }
public void Can_Verify_PropertyTypes_On_Textpage() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act IContentType contentType = repository.Get(_textpageContentType.Id); // Assert Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(4)); Assert.That(contentType.PropertyGroups.Count(), Is.EqualTo(2)); } }
public void Can_Perform_Get_On_ContentTypeRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act IContentType contentType = repository.Get(_textpageContentType.Id); // Assert Assert.That(contentType, Is.Not.Null); Assert.That(contentType.Id, Is.EqualTo(_textpageContentType.Id)); } }
public async Task UpdateAsync(IContent content, string container) { if (content.Id == null) { throw new InvalidOperationException($"This content cannot be updated as it doesn't seem to exist (Id is null). Did you mean to use IContentCreator?"); } var contentType = ContentTypeRepository.Get(content.ContentTypeId); if (contentType == null) { throw new InvalidOperationException($"This content has no content type (or rather its base class has no [ContentType] attribute)"); } var document = ContentSerializer.Serialize(content, contentType); await DocumentUpdater.UpdateAsync(container, content.Id, document); }
public async Task InsertAsync(IContent content) { if (content.Id == null) { throw new InvalidOperationException($"This content has no Id. Inserting (sorry for the confusing terminology) is for forcing newly created content to have a set Id. Did you mean to use IContentCreator?"); } var contentType = ContentTypeRepository.Get(content.GetType()); if (contentType == null) { throw new InvalidOperationException($"This content has no content type (or rather its Type ({content.GetType()}) has no [ContentType] attribute)"); } content.ContentTypeId = contentType.Id; await DocumentCreator.Create(ContainerConstants.Content, ContentSerializer.Serialize(content, contentType)); }
public async Task CreateAsync(IContent content, string container) { if (content.Id != null) { throw new InvalidOperationException($"This content seems to already exist as it has a non-null Id ({content.Id}). Did you mean to use IContentUpdater?"); } var contentType = ContentTypeRepository.Get(content.GetType()); if (contentType == null) { throw new InvalidOperationException($"This content has no content type (or rather its Type ({content.GetType()}) has no [ContentType] attribute)"); } content.Id = IdGenerator.Generate(); content.ContentTypeId = contentType.Id; await DocumentCreator.Create(container, ContentSerializer.Serialize(content, contentType)); }
public void Can_Verify_That_A_Combination_Of_Adding_And_Deleting_PropertyTypes_Doesnt_Cause_Issues_For_Content_And_ContentType() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; IContentType contentType = repository.Get(_textpageContentType.Id); Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id); DocumentRepository.Save(subpage); // Remove PropertyType contentType.RemovePropertyType("keywords"); // Add PropertyType PropertyGroup propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta"); propertyGroup.PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "metaAuthor") { Name = "Meta Author", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); repository.Save(contentType); // Act IContent content = DocumentRepository.Get(subpage.Id); content.SetValue("metaAuthor", "John Doe"); DocumentRepository.Save(content); // Assert IContent updated = DocumentRepository.Get(subpage.Id); Assert.That(updated.GetValue("metaAuthor").ToString(), Is.EqualTo("John Doe")); Assert.That(updated.Properties.First(x => x.Alias == "description").GetValue(), Is.EqualTo("This is the meta description for a textpage")); Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(4)); Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True); Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "keywords"), Is.False); } }
public void Can_Perform_Delete_On_ContentTypeRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act ContentType contentType = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: 0); repository.Save(contentType); IContentType contentType2 = repository.Get(contentType.Id); repository.Delete(contentType2); bool exists = repository.Exists(contentType.Id); // Assert Assert.That(exists, Is.False); } }
public async Task <T> GetAsync <T>(string id, string language, string container) where T : class { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (language == null) { language = DocumentLanguageConstants.Global; } var document = await DocumentGetter.GetAsync(container, id); if (document == null) { return(null); } var contentType = ContentTypeRepository.Get(document.GlobalFacet.Interfaces["IContent"].Properties["ContentTypeId"] as string); return((T)ContentDeserializer.Deserialize(document, contentType, language)); }
public async Task UpdateAsync(IContent content) { if (content.Id == null) { throw new InvalidOperationException($"This content cannot be updated as it doesn't seem to exist (Id is null). Did you mean to use IContentCreator?"); } var contentType = ContentTypeRepository.Get(content.ContentTypeId); if (contentType == null) { throw new TypeNotRegisteredContentTypeException(content.GetType()); } foreach (var saveListener in SaveListenerProvider.GetFor(content)) { saveListener.BeforeSave(content); } var document = ContentSerializer.Serialize(content, contentType); await DocumentUpdater.UpdateAsync(contentType.Container, content.Id, document); }
public void Can_Verify_Removal_Of_Used_PropertyType_From_ContentType() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; IContentType contentType = repository.Get(_textpageContentType.Id); Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id); DocumentRepository.Save(subpage); // Act contentType.RemovePropertyType("keywords"); repository.Save(contentType); // Assert Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(3)); Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "keywords"), Is.False); Assert.That(subpage.Properties.First(x => x.Alias == "description").GetValue(), Is.EqualTo("This is the meta description for a textpage")); } }
public async Task CreateAsync(IContent content) { if (content.Id != null) { throw new InvalidOperationException($"This content seems to already exist as it has a non-null Id ({content.Id}). Did you mean to use IContentUpdater?"); } var contentType = ContentTypeRepository.Get(content.GetType()); if (contentType == null) { throw new TypeNotRegisteredContentTypeException(content.GetType()); } content.Id = IdGenerator.Generate(); content.ContentTypeId = contentType.Id; foreach (var saveListener in SaveListenerProvider.GetFor(content)) { saveListener.BeforeSave(content); } await DocumentCreator.Create(contentType.Container, ContentSerializer.Serialize(content, contentType)); }
public void Can_Perform_Update_On_ContentTypeRepository_After_Model_Mapping() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act IContentType contentType = repository.Get(_textpageContentType.Id); // there is NO mapping from display to contentType, but only from save // to contentType, so if we want to test, let's to it properly! DocumentTypeDisplay display = Mapper.Map <DocumentTypeDisplay>(contentType); DocumentTypeSave save = MapToContentTypeSave(display); // modify... save.Thumbnail = "Doc2.png"; PropertyGroupBasic <PropertyTypeBasic> contentGroup = save.Groups.Single(x => x.Name == "Content"); contentGroup.Properties = contentGroup.Properties.Concat(new[] { new PropertyTypeBasic { Alias = "subtitle", Label = "Subtitle", Description = "Optional Subtitle", Validation = new PropertyTypeValidation { Mandatory = false, Pattern = string.Empty }, SortOrder = 1, DataTypeId = -88, LabelOnTop = true } }); IContentType mapped = Mapper.Map(save, contentType); // just making sure Assert.AreEqual(mapped.Thumbnail, "Doc2.png"); Assert.IsTrue(mapped.PropertyTypes.Any(x => x.Alias == "subtitle")); Assert.IsTrue(mapped.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop); repository.Save(mapped); bool dirty = mapped.IsDirty(); // re-get contentType = repository.Get(_textpageContentType.Id); // Assert Assert.That(contentType.HasIdentity, Is.True); Assert.That(dirty, Is.False); Assert.That(contentType.Thumbnail, Is.EqualTo("Doc2.png")); Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True); Assert.That(contentType.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop, Is.True); foreach (IPropertyType propertyType in contentType.PropertyTypes) { Assert.IsTrue(propertyType.HasIdentity); Assert.Greater(propertyType.Id, 0); } } }