Example #1
0
        public void Can_Serialize_Without_Error()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            contentType.Id = 99;
            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
            int     i       = 200;

            foreach (IProperty property in content.Properties)
            {
                property.Id = ++i;
            }

            content.Id         = 10;
            content.CreateDate = DateTime.Now;
            content.CreatorId  = 22;
            content.Key        = Guid.NewGuid();
            content.Level      = 3;
            content.Path       = "-1,4,10";
            content.SortOrder  = 5;
            content.TemplateId = 88;
            content.Trashed    = false;
            content.UpdateDate = DateTime.Now;
            content.WriterId   = 23;

            string json = JsonConvert.SerializeObject(content);

            Debug.Print(json);
        }
Example #2
0
        public void After_Committing_Changes_Was_Dirty_Is_True_On_Changed_Property()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            contentType.ResetDirtyProperties(); // reset
            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "test", -1);

            content.ResetDirtyProperties();

            // Act
            content.SetValue("title", "new title");
            Assert.That(content.IsEntityDirty(), Is.False);
            Assert.That(content.IsDirty(), Is.True);
            Assert.That(content.IsPropertyDirty("title"), Is.True);
            Assert.That(content.IsAnyUserPropertyDirty(), Is.True);
            Assert.That(content.GetDirtyUserProperties().Count(), Is.EqualTo(1));
            Assert.That(content.Properties[0].IsDirty(), Is.True);
            Assert.That(content.Properties["title"].IsDirty(), Is.True);

            content.ResetDirtyProperties(); // this would be like committing the entity

            // Assert
            Assert.That(content.WasDirty(), Is.True);
            Assert.That(content.Properties[0].WasDirty(), Is.True);

            Assert.That(content.WasPropertyDirty("title"), Is.True);
            Assert.That(content.Properties["title"].IsDirty(), Is.False);
            Assert.That(content.Properties["title"].WasDirty(), Is.True);
        }
Example #3
0
        public void Can_Add_New_Property_To_New_PropertyType_In_New_PropertyGroup()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            PropertyType propertyType = new PropertyTypeBuilder()
                                        .WithAlias("subtitle")
                                        .WithName("Subtitle")
                                        .Build();
            var propertyGroup = new PropertyGroup(true)
            {
                Alias     = "testGroup",
                Name      = "Test Group",
                SortOrder = 3
            };

            propertyGroup.PropertyTypes.Add(propertyType);
            contentType.PropertyGroups.Add(propertyGroup);
            var newProperty = new Property(propertyType);

            newProperty.SetValue("Subtitle Test");
            content.Properties.Add(newProperty);

            // Assert
            Assert.That(content.Properties.Count, Is.EqualTo(5));
            Assert.That(content.Properties["subtitle"].GetValue(), Is.EqualTo("Subtitle Test"));
            Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("Textpage textpage"));
        }
    public void DirtyProperty_OnlyIfActuallyChanged_User()
    {
        var contentTypeService = Mock.Of <IContentTypeService>();
        var contentType        = ContentTypeBuilder.CreateTextPageContentType();

        Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>()))
        .Returns(contentType);

        var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
        var prop    = content.Properties.First();

        // if you assign a user property with its value it is not dirty
        // if you assign it with another value then back, it is dirty
        prop.SetValue("A");
        content.ResetDirtyProperties(false);
        Assert.IsFalse(prop.IsDirty());
        prop.SetValue("B");
        Assert.IsTrue(prop.IsDirty());
        content.ResetDirtyProperties(false);
        Assert.IsFalse(prop.IsDirty());
        prop.SetValue("B");
        Assert.IsFalse(prop.IsDirty());
        prop.SetValue("A");
        prop.SetValue("B");
        Assert.IsTrue(prop.IsDirty());
    }
    public void DirtyProperty_UpdateDate()
    {
        var contentTypeService = Mock.Of <IContentTypeService>();
        var contentType        = ContentTypeBuilder.CreateTextPageContentType();

        Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>()))
        .Returns(contentType);

        var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
        var prop    = content.Properties.First();

        content.ResetDirtyProperties(false);
        var d = content.UpdateDate;

        prop.SetValue("A");
        Assert.IsTrue(content.IsAnyUserPropertyDirty());
        Assert.IsFalse(content.IsEntityDirty());
        Assert.AreEqual(d, content.UpdateDate);

        content.UpdateDate = DateTime.Now;
        Assert.IsTrue(content.IsEntityDirty());
        Assert.AreNotEqual(d, content.UpdateDate);

        // so... changing UpdateDate would count as a content property being changed
        // however in ContentRepository.PersistUpdatedItem, we change UpdateDate AFTER
        // we've tested for RequiresSaving & RequiresNewVersion so it's OK
    }
    public void DirtyProperty_WasDirty_ContentSortOrder()
    {
        var contentTypeService = Mock.Of <IContentTypeService>();
        var contentType        = ContentTypeBuilder.CreateTextPageContentType();

        Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>()))
        .Returns(contentType);

        var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

        content.ResetDirtyProperties(false);
        Assert.IsFalse(content.IsDirty());
        Assert.IsFalse(content.WasDirty());
        content.SortOrder = 0;
        content.SortOrder = 1;
        Assert.IsTrue(content.IsDirty());
        Assert.IsFalse(content.WasDirty());
        content.ResetDirtyProperties(false);
        Assert.IsFalse(content.IsDirty());
        Assert.IsFalse(content.WasDirty());
        content.SortOrder = 0;
        content.SortOrder = 1;
        content.ResetDirtyProperties(true); // what PersistUpdatedItem does
        Assert.IsFalse(content.IsDirty());
        Assert.IsTrue(content.WasDirty());
        content.SortOrder = 0;
        content.SortOrder = 1;
        content.ResetDirtyProperties(); // what PersistUpdatedItem does
        Assert.IsFalse(content.IsDirty());
        Assert.IsTrue(content.WasDirty());
    }
    public void DirtyProperty_WasDirty_UserProperty()
    {
        var contentTypeService = Mock.Of <IContentTypeService>();
        var contentType        = ContentTypeBuilder.CreateTextPageContentType();

        Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>()))
        .Returns(contentType);

        var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
        var prop    = content.Properties.First();

        content.ResetDirtyProperties(false);
        Assert.IsFalse(content.IsDirty());
        Assert.IsFalse(content.WasDirty());
        prop.SetValue("a");
        prop.SetValue("b");
        Assert.IsTrue(content.IsDirty());
        Assert.IsFalse(content.WasDirty());
        content.ResetDirtyProperties(false);
        Assert.IsFalse(content.IsDirty());
        Assert.IsFalse(content.WasDirty());
        prop.SetValue("a");
        prop.SetValue("b");
        content.ResetDirtyProperties(true); // what PersistUpdatedItem does
        Assert.IsFalse(content.IsDirty());
        //// Assert.IsFalse(content.WasDirty()); // not impacted by user properties
        Assert.IsTrue(content.WasDirty()); // now it is!
        prop.SetValue("a");
        prop.SetValue("b");
        content.ResetDirtyProperties(); // what PersistUpdatedItem does
        Assert.IsFalse(content.IsDirty());
        //// Assert.IsFalse(content.WasDirty()); // not impacted by user properties
        Assert.IsTrue(content.WasDirty()); // now it is!
    }
Example #8
0
        public void Can_Verify_Content_Is_Published()
        {
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties();
            content.PublishedState = PublishedState.Publishing;

            Assert.IsFalse(content.IsPropertyDirty("Published"));
            Assert.IsFalse(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Publishing, content.PublishedState);

            // the repo would do
            content.Published = true;

            // and then
            Assert.IsTrue(content.IsPropertyDirty("Published"));
            Assert.IsTrue(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Published, content.PublishedState);

            // and before returning,
            content.ResetDirtyProperties();

            // and then
            Assert.IsFalse(content.IsPropertyDirty("Published"));
            Assert.IsTrue(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Published, content.PublishedState);
        }
Example #9
0
        public void Serialize_ForContentTypeWithHistoryCleanupPolicy_OutputsSerializedHistoryCleanupPolicy()
        {
            // Arrange
            var template = TemplateBuilder.CreateTextPageTemplate();

            FileService.SaveTemplate(template); // else, FK violation on contentType!

            var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id);

            contentType.HistoryCleanup = new HistoryCleanup
            {
                PreventCleanup = true,
                KeepAllVersionsNewerThanDays   = 1,
                KeepLatestVersionPerDayForDays = 2
            };

            ContentTypeService.Save(contentType);

            // Act
            var element = Serializer.Serialize(contentType);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(element.Element("HistoryCleanupPolicy") !.Attribute("preventCleanup") !.Value, Is.EqualTo("true"));
                Assert.That(element.Element("HistoryCleanupPolicy") !.Attribute("keepAllVersionsNewerThanDays") !.Value, Is.EqualTo("1"));
                Assert.That(element.Element("HistoryCleanupPolicy") !.Attribute("keepLatestVersionPerDayForDays") !.Value, Is.EqualTo("2"));
            });
        }
Example #10
0
        public void Can_Add_New_Property_To_New_PropertyType()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            PropertyType propertyType = new PropertyTypeBuilder()
                                        .WithAlias("subtitle")
                                        .WithName("Subtitle")
                                        .Build();

            contentType.PropertyGroups["content"].PropertyTypes.Add(propertyType);
            var newProperty = new Property(propertyType);

            newProperty.SetValue("This is a subtitle Test");
            content.Properties.Add(newProperty);

            // Assert
            Assert.That(content.Properties.Contains("subtitle"), Is.True);
            Assert.That(content.Properties["subtitle"].GetValue(), Is.EqualTo("This is a subtitle Test"));
        }
Example #11
0
    public void PropertyGroups_Collection_FirstOrDefault_Returns_Null()
    {
        var contentType = ContentTypeBuilder.CreateTextPageContentType();

        Assert.That(contentType.PropertyGroups, Is.Not.Null);
        Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Content")) == null, Is.False);
        Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Test")) == null, Is.True);
        Assert.That(contentType.PropertyGroups.Any(x => x.Name.InvariantEquals("Test")), Is.False);
    }
Example #12
0
        public void Can_Avoid_Circular_Dependencies_In_Composition()
        {
            ContentType  textPage      = ContentTypeBuilder.CreateTextPageContentType();
            ContentType  parent        = ContentTypeBuilder.CreateSimpleContentType("parent", "Parent", null, randomizeAliases: true);
            ContentType  meta          = ContentTypeBuilder.CreateMetaContentType();
            PropertyType propertyType1 = new PropertyTypeBuilder()
                                         .WithAlias("coauthor")
                                         .WithName("Co-author")
                                         .Build();
            ContentType mixin1 = ContentTypeBuilder.CreateSimpleContentType(
                "mixin1",
                "Mixin1",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType1
            }));
            PropertyType propertyType2 = new PropertyTypeBuilder()
                                         .WithAlias("author")
                                         .WithName("Author")
                                         .Build();
            ContentType mixin2 = ContentTypeBuilder.CreateSimpleContentType(
                "mixin2",
                "Mixin2",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType2
            }));

            // Act
            bool addedMetaMixin2 = mixin2.AddContentType(meta);
            bool addedMixin2     = mixin1.AddContentType(mixin2);
            bool addedMeta       = parent.AddContentType(meta);

            bool addedMixin1 = parent.AddContentType(mixin1);

            bool addedMixin1Textpage = textPage.AddContentType(mixin1);
            bool addedTextpageParent = parent.AddContentType(textPage);

            IEnumerable <string>        aliases        = textPage.CompositionAliases();
            IEnumerable <IPropertyType> propertyTypes  = textPage.CompositionPropertyTypes;
            IEnumerable <PropertyGroup> propertyGroups = textPage.CompositionPropertyGroups;

            // Assert
            Assert.That(mixin2.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(mixin1.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(parent.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(textPage.ContentTypeCompositionExists("meta"), Is.True);

            Assert.That(aliases.Count(), Is.EqualTo(3));
            Assert.That(propertyTypes.Count(), Is.EqualTo(8));
            Assert.That(propertyGroups.Count(), Is.EqualTo(2));

            Assert.That(addedMeta, Is.True);
            Assert.That(addedMetaMixin2, Is.True);
            Assert.That(addedMixin2, Is.True);
            Assert.That(addedMixin1, Is.False);
            Assert.That(addedMixin1Textpage, Is.True);
            Assert.That(addedTextpageParent, Is.False);
        }
    private void CreateTestData()
    {
        var template = TemplateBuilder.CreateTextPageTemplate();

        FileService.SaveTemplate(template); // else, FK violation on contentType!

        _contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id);
        ContentTypeService.Save(_contentType);
    }
    public void IContentType_To_ContentTypeDisplay()
    {
        // Arrange
        //// _dataTypeService.Setup(x => x.GetDataType(It.IsAny<int>()))
        ////     .Returns(new DataType(new VoidEditor(Mock.Of<ILogger>(), Mock.Of<IDataTypeService>(), Mock.Of<ILocalizationService>(),Mock.Of<ILocalizedTextService>(), Mock.Of<IShortStringHelper>())));
        //
        // setup the mocks to return the data we want to test against...
        var contentType = ContentTypeBuilder.CreateTextPageContentType();

        ContentTypeBuilder.EnsureAllIds(contentType, 8888);

        // Act
        var result = _sut.Map <DocumentTypeDisplay>(contentType);

        // Assert
        Assert.AreEqual(contentType.Alias, result.Alias);
        Assert.AreEqual(contentType.Description, result.Description);
        Assert.AreEqual(contentType.Icon, result.Icon);
        Assert.AreEqual(contentType.Id, result.Id);
        Assert.AreEqual(contentType.Name, result.Name);
        Assert.AreEqual(contentType.ParentId, result.ParentId);
        Assert.AreEqual(contentType.Path, result.Path);
        Assert.AreEqual(contentType.Thumbnail, result.Thumbnail);
        Assert.AreEqual(contentType.IsContainer, result.IsContainer);
        Assert.AreEqual(contentType.CreateDate, result.CreateDate);
        Assert.AreEqual(contentType.UpdateDate, result.UpdateDate);
        Assert.AreEqual(contentType.DefaultTemplate.Alias, result.DefaultTemplate.Alias);

        Assert.AreEqual(contentType.PropertyGroups.Count, result.Groups.Count());
        for (var i = 0; i < contentType.PropertyGroups.Count; i++)
        {
            Assert.AreEqual(contentType.PropertyGroups[i].Id, result.Groups.ElementAt(i).Id);
            Assert.AreEqual(contentType.PropertyGroups[i].Name, result.Groups.ElementAt(i).Name);
            var propTypes = contentType.PropertyGroups[i].PropertyTypes;

            Assert.AreEqual(propTypes.Count, result.Groups.ElementAt(i).Properties.Count());
            for (var j = 0; j < propTypes.Count; j++)
            {
                Assert.AreEqual(propTypes[j].Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id);
                Assert.AreEqual(propTypes[j].DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId);
                Assert.AreEqual(propTypes[j].LabelOnTop, result.Groups.ElementAt(i).Properties.ElementAt(j).LabelOnTop);
            }
        }

        Assert.AreEqual(contentType.AllowedTemplates.Count(), result.AllowedTemplates.Count());
        for (var i = 0; i < contentType.AllowedTemplates.Count(); i++)
        {
            Assert.AreEqual(contentType.AllowedTemplates.ElementAt(i).Id, result.AllowedTemplates.ElementAt(i).Id);
        }

        Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count());
        for (var i = 0; i < contentType.AllowedContentTypes.Count(); i++)
        {
            Assert.AreEqual(contentType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i));
        }
    }
Example #15
0
        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);
        }
Example #16
0
        public void CreateTestData()
        {
            // Create and Save ContentType "umbTextpage" -> (_simpleContentType.Id)
            _simpleContentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: 0);

            ContentTypeService.Save(_simpleContentType);

            // Create and Save ContentType "textPage" -> (_textpageContentType.Id)
            _textpageContentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: 0);
            ContentTypeService.Save(_textpageContentType);
        }
Example #17
0
        public void If_Not_Committed_Was_Dirty_Is_False()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            // Act
            contentType.Alias = "newAlias";

            // Assert
            Assert.That(contentType.IsDirty(), Is.True);
            Assert.That(contentType.WasDirty(), Is.False);
        }
Example #18
0
        public void Detect_That_A_Property_Is_Removed()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Assert.That(contentType.WasPropertyDirty("HasPropertyTypeBeenRemoved"), Is.False);

            // Act
            contentType.RemovePropertyType("title");

            // Assert
            Assert.That(contentType.IsPropertyDirty("HasPropertyTypeBeenRemoved"), Is.True);
        }
Example #19
0
    public void Can_Generate_Xml_Representation_Of_Content()
    {
        // Arrange
        var template = TemplateBuilder.CreateTextPageTemplate();

        FileService.SaveTemplate(template); // else, FK violation on contentType!
        var contentType = ContentTypeBuilder.CreateTextPageContentType(
            defaultTemplateId: template.Id);

        ContentTypeService.Save(contentType);

        var content = ContentBuilder.CreateTextpageContent(contentType, "Root Home", -1);

        ContentService.Save(content, Constants.Security.SuperUserId);

        var nodeName = content.ContentType.Alias.ToSafeAlias(ShortStringHelper);
        var urlName  =
            content.GetUrlSegment(ShortStringHelper, new[] { new DefaultUrlSegmentProvider(ShortStringHelper) });

        // Act
        var element = content.ToXml(Serializer);

        // Assert
        Assert.That(element, Is.Not.Null);
        Assert.That(element.Name.LocalName, Is.EqualTo(nodeName));
        Assert.AreEqual(content.Id.ToString(), (string)element.Attribute("id"));
        Assert.AreEqual(content.ParentId.ToString(), (string)element.Attribute("parentID"));
        Assert.AreEqual(content.Level.ToString(), (string)element.Attribute("level"));
        Assert.AreEqual(content.CreatorId.ToString(), (string)element.Attribute("creatorID"));
        Assert.AreEqual(content.SortOrder.ToString(), (string)element.Attribute("sortOrder"));
        Assert.AreEqual(content.CreateDate.ToString("s"), (string)element.Attribute("createDate"));
        Assert.AreEqual(content.UpdateDate.ToString("s"), (string)element.Attribute("updateDate"));
        Assert.AreEqual(content.Name, (string)element.Attribute("nodeName"));
        Assert.AreEqual(urlName, (string)element.Attribute("urlName"));
        Assert.AreEqual(content.Path, (string)element.Attribute("path"));
        Assert.AreEqual("", (string)element.Attribute("isDoc"));
        Assert.AreEqual(content.ContentType.Id.ToString(), (string)element.Attribute("nodeType"));
        Assert.AreEqual(content.GetCreatorProfile(UserService).Name, (string)element.Attribute("creatorName"));
        Assert.AreEqual(content.GetWriterProfile(UserService).Name, (string)element.Attribute("writerName"));
        Assert.AreEqual(content.WriterId.ToString(), (string)element.Attribute("writerID"));
        Assert.AreEqual(content.TemplateId.ToString(), (string)element.Attribute("template"));

        Assert.AreEqual(content.Properties["title"].GetValue().ToString(), element.Elements("title").Single().Value);
        Assert.AreEqual(content.Properties["bodyText"].GetValue().ToString(),
                        element.Elements("bodyText").Single().Value);
        Assert.AreEqual(content.Properties["keywords"].GetValue().ToString(),
                        element.Elements("keywords").Single().Value);
        Assert.AreEqual(content.Properties["description"].GetValue().ToString(),
                        element.Elements("description").Single().Value);
    }
Example #20
0
        public void Can_Remove_PropertyGroup_From_ContentType()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            contentType.ResetDirtyProperties();

            // Act
            contentType.PropertyGroups.Remove("content");

            // Assert
            Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(1));
            //// Assert.That(contentType.IsPropertyDirty("PropertyGroups"), Is.True);
        }
Example #21
0
        public void Can_Verify_Mocked_Content()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            // Act

            // Assert
            Assert.That(content, Is.Not.Null);
        }
Example #22
0
        public void Can_Deep_Clone_Perf_Test()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            contentType.Id = 99;
            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
            int     i       = 200;

            foreach (IProperty property in content.Properties)
            {
                property.Id = ++i;
            }

            content.Id         = 10;
            content.CreateDate = DateTime.Now;
            content.CreatorId  = 22;
            content.Key        = Guid.NewGuid();
            content.Level      = 3;
            content.Path       = "-1,4,10";
            content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1));
            //// content.ChangePublishedState(PublishedState.Published);
            content.SortOrder  = 5;
            content.TemplateId = 88;
            content.Trashed    = false;
            content.UpdateDate = DateTime.Now;
            content.WriterId   = 23;

            var runtimeCache = new ObjectCacheAppCache();

            runtimeCache.Insert(content.Id.ToString(CultureInfo.InvariantCulture), () => content);

            IProfilingLogger proflog = GetTestProfilingLogger();

            using (proflog.DebugDuration <ContentTests>("STARTING PERF TEST WITH RUNTIME CACHE"))
            {
                for (int j = 0; j < 1000; j++)
                {
                    object clone = runtimeCache.Get(content.Id.ToString(CultureInfo.InvariantCulture));
                }
            }

            using (proflog.DebugDuration <ContentTests>("STARTING PERF TEST WITHOUT RUNTIME CACHE"))
            {
                for (int j = 0; j < 1000; j++)
                {
                    var clone = (ContentType)contentType.DeepClone();
                }
            }
        }
Example #23
0
    public void Can_Add_PropertyGroup_On_ContentType()
    {
        // Arrange
        var contentType = ContentTypeBuilder.CreateTextPageContentType();

        // Act
        contentType.PropertyGroups.Add(
            new PropertyGroup(true)
        {
            Alias = "testGroup", Name = "Test Group", SortOrder = 3
        });

        // Assert
        Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(3));
    }
        public void DirtyProperty_Reset_Clears_SavedPublishedState()
        {
            IContentTypeService contentTypeService = Mock.Of <IContentTypeService>();
            ContentType         contentType        = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            content.PublishedState = PublishedState.Publishing;
            Assert.IsFalse(content.Published);
            content.ResetDirtyProperties(false); // resets
            Assert.AreEqual(PublishedState.Unpublished, content.PublishedState);
            Assert.IsFalse(content.Published);
        }
Example #25
0
        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);
        }
Example #26
0
        public void All_Dirty_Properties_Get_Reset()
        {
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties(false);

            Assert.IsFalse(content.IsDirty());
            foreach (IProperty prop in content.Properties)
            {
                Assert.IsFalse(prop.IsDirty());
            }
        }
Example #27
0
        public void After_Committing_Changes_Was_Dirty_Is_True()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            contentType.ResetDirtyProperties(); // reset

            // Act
            contentType.Alias = "newAlias";
            contentType.ResetDirtyProperties(); // this would be like committing the entity

            // Assert
            Assert.That(contentType.IsDirty(), Is.False);
            Assert.That(contentType.WasDirty(), Is.True);
            Assert.That(contentType.WasPropertyDirty("Alias"), Is.True);
        }
Example #28
0
        public void Can_Add_PropertyType_To_Group_On_ContentType()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            // Act
            PropertyType propertyType = new PropertyTypeBuilder()
                                        .WithAlias("subtitle")
                                        .WithName("Subtitle")
                                        .Build();

            contentType.PropertyGroups["content"].PropertyTypes.Add(propertyType);

            // Assert
            Assert.That(contentType.PropertyGroups["content"].PropertyTypes.Count, Is.EqualTo(3));
        }
Example #29
0
        public void Can_Set_Property_Value_As_String()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            content.SetValue("title", "This is the new title");

            // Assert
            Assert.That(content.Properties.Any(), Is.True);
            Assert.That(content.Properties["title"], Is.Not.Null);
            Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("This is the new title"));
        }
Example #30
0
        public void Can_Verify_Dirty_Property_On_Content()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            content.ResetDirtyProperties();
            content.Name = "New Home";

            // Assert
            Assert.That(content.Name, Is.EqualTo("New Home"));
            Assert.That(content.IsPropertyDirty("Name"), Is.True);
        }