コード例 #1
0
ファイル: ContentTests.cs プロジェクト: robertjf/Umbraco-CMS
    public void Can_Compose_Composite_ContentType_Collection()
    {
        // Arrange
        var simpleContentType = ContentTypeBuilder.CreateSimpleContentType();
        var propertyType      = new PropertyTypeBuilder()
                                .WithAlias("coauthor")
                                .WithName("Co-author")
                                .Build();
        var simple2ContentType = ContentTypeBuilder.CreateSimpleContentType(
            "anotherSimple",
            "Another Simple Page",
            propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
            propertyType
        }));

        // Act
        var added = simpleContentType.AddContentType(simple2ContentType);
        var compositionPropertyGroups = simpleContentType.CompositionPropertyGroups;
        var compositionPropertyTypes  = simpleContentType.CompositionPropertyTypes;

        // Assert
        Assert.That(added, Is.True);
        Assert.That(compositionPropertyGroups.Count(), Is.EqualTo(1));
        Assert.That(compositionPropertyTypes.Count(), Is.EqualTo(4));
    }
コード例 #2
0
        public void Can_Compose_Nested_Composite_ContentType_Collection()
        {
            // Arrange
            ContentType  metaContentType   = ContentTypeBuilder.CreateMetaContentType();
            ContentType  simpleContentType = ContentTypeBuilder.CreateSimpleContentType();
            PropertyType propertyType      = new PropertyTypeBuilder()
                                             .WithAlias("coauthor")
                                             .WithName("Co-author")
                                             .Build();
            ContentType simple2ContentType = ContentTypeBuilder.CreateSimpleContentType(
                "anotherSimple",
                "Another Simple Page",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType
            }));

            // Act
            bool addedMeta = simple2ContentType.AddContentType(metaContentType);
            bool added     = simpleContentType.AddContentType(simple2ContentType);
            IEnumerable <PropertyGroup> compositionPropertyGroups = simpleContentType.CompositionPropertyGroups;
            IEnumerable <IPropertyType> compositionPropertyTypes  = simpleContentType.CompositionPropertyTypes;

            // Assert
            Assert.That(addedMeta, Is.True);
            Assert.That(added, Is.True);
            Assert.That(compositionPropertyGroups.Count(), Is.EqualTo(2));
            Assert.That(compositionPropertyTypes.Count(), Is.EqualTo(6));
            Assert.That(simpleContentType.ContentTypeCompositionExists("meta"), Is.True);
        }
コード例 #3
0
    public void ValidationTests()
    {
        var propertyType = new PropertyTypeBuilder()
                           .WithAlias("prop")
                           .WithSupportsPublishing(true)
                           .Build();

        var prop = new Property(propertyType);

        prop.SetValue("a");
        Assert.AreEqual("a", prop.GetValue());
        Assert.IsNull(prop.GetValue(published: true));
        var propertyValidationService = GetPropertyValidationService();

        Assert.IsTrue(propertyValidationService.IsPropertyValid(prop));

        propertyType.Mandatory = true;
        Assert.IsTrue(propertyValidationService.IsPropertyValid(prop));

        prop.SetValue(null);
        Assert.IsFalse(propertyValidationService.IsPropertyValid(prop));

        // can publish, even though invalid
        prop.PublishValues();
    }
コード例 #4
0
        public void Get_Non_Grouped_Properties()
        {
            ContentType contentType = ContentTypeBuilder.CreateSimpleContentType();

            // Add non-grouped properties
            PropertyType pt1 = new PropertyTypeBuilder()
                               .WithAlias("nonGrouped1")
                               .WithName("Non Grouped 1")
                               .Build();
            PropertyType pt2 = new PropertyTypeBuilder()
                               .WithAlias("nonGrouped2")
                               .WithName("Non Grouped 2")
                               .Build();

            contentType.AddPropertyType(pt1);
            contentType.AddPropertyType(pt2);

            // Ensure that nothing is marked as dirty
            contentType.ResetDirtyProperties(false);
            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            Content content = ContentBuilder.CreateSimpleContent(contentType);

            IEnumerable <IProperty> nonGrouped = content.GetNonGroupedProperties();

            Assert.AreEqual(2, nonGrouped.Count());
            Assert.AreEqual(5, content.Properties.Count());
        }
コード例 #5
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"));
        }
コード例 #6
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"));
        }
コード例 #7
0
    public void IsDirtyTests()
    {
        var propertyType = new PropertyTypeBuilder()
                           .WithAlias("prop")
                           .Build();
        var prop        = new Property(propertyType);
        var contentType = new ContentTypeBuilder()
                          .WithAlias("contentType")
                          .Build();

        contentType.AddPropertyType(propertyType);

        var content = CreateContent(contentType);

        prop.SetValue("a");
        Assert.AreEqual("a", prop.GetValue());
        Assert.IsNull(prop.GetValue(published: true));

        Assert.IsTrue(prop.IsDirty());

        content.SetValue("prop", "a");
        Assert.AreEqual("a", content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));

        Assert.IsTrue(content.IsDirty());
        Assert.IsTrue(content.IsAnyUserPropertyDirty());
        //// how can we tell which variation was dirty?
    }
コード例 #8
0
        public void Is_Built_Correctly()
        {
            // Arrange
            const int              testId  = 3;
            var                    testKey = Guid.NewGuid();
            const string           testPropertyEditorAlias = "TestPropertyEditor";
            const ValueStorageType testValueStorageType    = ValueStorageType.Nvarchar;
            const string           testAlias                   = "test";
            const string           testName                    = "Test";
            const int              testSortOrder               = 9;
            const int              testDataTypeId              = 5;
            DateTime               testCreateDate              = DateTime.Now.AddHours(-1);
            DateTime               testUpdateDate              = DateTime.Now;
            const string           testDescription             = "testing";
            const int              testPropertyGroupId         = 11;
            const bool             testMandatory               = true;
            const string           testMandatoryMessage        = "Field is required";
            const string           testValidationRegExp        = "xxxx";
            const string           testValidationRegExpMessage = "Field must match pattern";

            var builder = new PropertyTypeBuilder();

            // Act
            PropertyType propertyType = builder
                                        .WithId(testId)
                                        .WithPropertyEditorAlias(testPropertyEditorAlias)
                                        .WithValueStorageType(testValueStorageType)
                                        .WithAlias(testAlias)
                                        .WithName(testName)
                                        .WithSortOrder(testSortOrder)
                                        .WithDataTypeId(testDataTypeId)
                                        .WithCreateDate(testCreateDate)
                                        .WithUpdateDate(testUpdateDate)
                                        .WithDescription(testDescription)
                                        .WithKey(testKey)
                                        .WithPropertyGroupId(testPropertyGroupId)
                                        .WithMandatory(testMandatory, testMandatoryMessage)
                                        .WithValidationRegExp(testValidationRegExp, testValidationRegExpMessage)
                                        .Build();

            // Assert
            Assert.AreEqual(testId, propertyType.Id);
            Assert.AreEqual(testPropertyEditorAlias, propertyType.PropertyEditorAlias);
            Assert.AreEqual(testValueStorageType, propertyType.ValueStorageType);
            Assert.AreEqual(testAlias, propertyType.Alias);
            Assert.AreEqual(testName, propertyType.Name);
            Assert.AreEqual(testSortOrder, propertyType.SortOrder);
            Assert.AreEqual(testDataTypeId, propertyType.DataTypeId);
            Assert.AreEqual(testCreateDate, propertyType.CreateDate);
            Assert.AreEqual(testUpdateDate, propertyType.UpdateDate);
            Assert.AreEqual(testDescription, propertyType.Description);
            Assert.AreEqual(testKey, propertyType.Key);
            Assert.AreEqual(testPropertyGroupId, propertyType.PropertyGroupId.Value);
            Assert.AreEqual(testMandatory, propertyType.Mandatory);
            Assert.AreEqual(testMandatoryMessage, propertyType.MandatoryMessage);
            Assert.AreEqual(testValidationRegExp, propertyType.ValidationRegExp);
            Assert.AreEqual(testValidationRegExpMessage, propertyType.ValidationRegExpMessage);
        }
コード例 #9
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);
        }
コード例 #10
0
    public void ContentPublishValuesWithMixedPropertyTypeVariations()
    {
        var          propertyValidationService = GetPropertyValidationService();
        const string langFr = "fr-FR";

        // content type varies by Culture
        // prop1 varies by Culture
        // prop2 is invariant
        var contentType = new ContentTypeBuilder()
                          .WithAlias("contentType")
                          .Build();

        contentType.Variations |= ContentVariation.Culture;

        var variantPropType = new PropertyTypeBuilder()
                              .WithAlias("prop1")
                              .WithVariations(ContentVariation.Culture)
                              .WithMandatory(true)
                              .Build();
        var invariantPropType = new PropertyTypeBuilder()
                                .WithAlias("prop2")
                                .WithVariations(ContentVariation.Nothing)
                                .WithMandatory(true)
                                .Build();

        contentType.AddPropertyType(variantPropType);
        contentType.AddPropertyType(invariantPropType);

        var content = CreateContent(contentType);

        content.SetCultureName("hello", langFr);

        // for this test we'll make the french culture the default one - this is needed for publishing invariant property values
        var langFrImpact = CultureImpact.Explicit(langFr, true);

        Assert.IsTrue(
            content.PublishCulture(langFrImpact));                                        // succeeds because names are ok (not validating properties here)
        Assert.IsFalse(
            propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); // fails because prop1 is mandatory

        content.SetValue("prop1", "a", langFr);
        Assert.IsTrue(
            content.PublishCulture(langFrImpact)); // succeeds because names are ok (not validating properties here)

        // Fails because prop2 is mandatory and invariant and the item isn't published.
        // Invariant is validated against the default language except when there isn't a published version, in that case it's always validated.
        Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact));
        content.SetValue("prop2", "x");
        Assert.IsTrue(content.PublishCulture(langFrImpact));                                        // still ok...
        Assert.IsTrue(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); // now it's ok

        Assert.AreEqual("a", content.GetValue("prop1", langFr, published: true));
        Assert.AreEqual("x", content.GetValue("prop2", published: true));
    }
コード例 #11
0
        public void Cannot_Add_Duplicate_Property_Aliases()
        {
            ContentType contentType = BuildContentType();

            var          propertyTypeBuilder    = new PropertyTypeBuilder();
            PropertyType additionalPropertyType = propertyTypeBuilder
                                                  .WithAlias("title")
                                                  .Build();

            Assert.Throws <InvalidOperationException>(() =>
                                                      contentType.PropertyTypeCollection.Add(additionalPropertyType));
        }
コード例 #12
0
        private PropertyType CreateAndAddTagsPropertyType(ContentType contentType, ContentVariation variations = ContentVariation.Nothing)
        {
            PropertyType propertyType = new PropertyTypeBuilder()
                                        .WithPropertyEditorAlias("test")
                                        .WithAlias("tags")
                                        .WithDataTypeId(1041)
                                        .WithVariations(variations)
                                        .Build();

            contentType.PropertyGroups.First().PropertyTypes.Add(propertyType);
            contentType.Variations = variations;
            return(propertyType);
        }
コード例 #13
0
        public void Cannot_Update_Duplicate_Property_Aliases()
        {
            ContentType contentType = BuildContentType();

            var          propertyTypeBuilder    = new PropertyTypeBuilder();
            PropertyType additionalPropertyType = propertyTypeBuilder
                                                  .WithAlias("title")
                                                  .Build();

            contentType.PropertyTypeCollection.Add(additionalPropertyType);

            IPropertyType toUpdate = contentType.PropertyTypeCollection["myPropertyType2"];

            Assert.Throws <InvalidOperationException>(() => toUpdate.Alias = "myPropertyType");
        }
コード例 #14
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));
        }
コード例 #15
0
        public void Adding_PropertyType_To_PropertyGroup_On_ContentType_Results_In_Dirty_Entity()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

            contentType.ResetDirtyProperties();

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

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

            // Assert
            Assert.That(contentType.PropertyGroups["content"].IsDirty(), Is.True);
            Assert.That(contentType.PropertyGroups["content"].IsPropertyDirty("PropertyTypes"), Is.True);
            Assert.That(contentType.PropertyGroups.Any(x => x.IsDirty()), Is.True);
        }
コード例 #16
0
        public void Can_Set_Is_Member_Specific_Property_Type_Options(bool isSensitive, bool canView, bool canEdit)
        {
            var        propertyTypeAlias = "testType";
            MemberType memberType        = BuildMemberType();
            var        propertyType      = new PropertyTypeBuilder()
                                           .WithAlias("testType")
                                           .Build();

            memberType.AddPropertyType(propertyType);

            memberType.SetIsSensitiveProperty(propertyTypeAlias, isSensitive);
            memberType.SetMemberCanViewProperty(propertyTypeAlias, canView);
            memberType.SetMemberCanEditProperty(propertyTypeAlias, canEdit);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(isSensitive, memberType.IsSensitiveProperty(propertyTypeAlias));
                Assert.AreEqual(canView, memberType.MemberCanViewProperty(propertyTypeAlias));
                Assert.AreEqual(canEdit, memberType.MemberCanEditProperty(propertyTypeAlias));
            });
        }
コード例 #17
0
        public void Can_Update_PropertyType_Through_Content_Properties()
        {
            // 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 - note that the PropertyType's properties like SortOrder is not updated through the Content object
            PropertyType propertyType = new PropertyTypeBuilder()
                                        .WithAlias("title")
                                        .WithName("Title")
                                        .Build();

            content.Properties.Add(new Property(propertyType));

            // Assert
            Assert.That(content.Properties.Count, Is.EqualTo(4));
            Assert.That(contentType.PropertyTypes.First(x => x.Alias == "title").SortOrder, Is.EqualTo(1));
            Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("Textpage textpage"));
        }
コード例 #18
0
 public void SetUp() => _builder = new PropertyTypeBuilder();
コード例 #19
0
    public void ContentPublishVariations()
    {
        const string langFr = "fr-FR";
        const string langUk = "en-UK";
        const string langEs = "es-ES";

        var propertyType = new PropertyTypeBuilder()
                           .WithAlias("prop")
                           .Build();
        var contentType = new ContentTypeBuilder()
                          .WithAlias("contentType")
                          .Build();

        contentType.AddPropertyType(propertyType);

        var content = CreateContent(contentType);

        // change - now we vary by culture
        contentType.Variations  |= ContentVariation.Culture;
        propertyType.Variations |= ContentVariation.Culture;

        content.ChangeContentType(contentType);

        Assert.Throws <NotSupportedException>(() => content.SetValue("prop", "a")); // invariant = no
        content.SetValue("prop", "a-fr", langFr);
        content.SetValue("prop", "a-uk", langUk);
        content.SetValue("prop", "a-es", langEs);

        // cannot publish without a name
        Assert.IsFalse(content.PublishCulture(CultureImpact.Explicit(langFr, false)));

        // works with a name
        // and then FR is available, and published
        content.SetCultureName("name-fr", langFr);
        Assert.IsTrue(content.PublishCulture(CultureImpact.Explicit(langFr, false)));

        // now UK is available too
        content.SetCultureName("name-uk", langUk);

        // test available, published
        Assert.IsTrue(content.IsCultureAvailable(langFr));
        Assert.IsTrue(content.IsCulturePublished(langFr));
        Assert.AreEqual("name-fr", content.GetPublishName(langFr));
        Assert.AreNotEqual(DateTime.MinValue, content.GetPublishDate(langFr));
        Assert.IsFalse(content.IsCultureEdited(langFr)); // once published, edited is *wrong* until saved

        Assert.IsTrue(content.IsCultureAvailable(langUk));
        Assert.IsFalse(content.IsCulturePublished(langUk));
        Assert.IsNull(content.GetPublishName(langUk));
        Assert.IsNull(content.GetPublishDate(langUk)); // not published

        Assert.IsFalse(content.IsCultureAvailable(langEs));
        Assert.IsFalse(content.IsCultureEdited(langEs)); // not avail, so... not edited
        Assert.IsFalse(content.IsCulturePublished(langEs));

        // not published!
        Assert.IsNull(content.GetPublishName(langEs));
        Assert.IsNull(content.GetPublishDate(langEs));

        // cannot test IsCultureEdited here - as that requires the content service and repository
        // see: ContentServiceTests.Can_SaveRead_Variations
    }
コード例 #20
0
        public void Can_Deep_Clone_Content_Type()
        {
            // Arrange
            ContentType contentType = BuildContentType();

            // Act
            var clone = (ContentType)contentType.DeepClone();

            // Assert
            Assert.AreNotSame(clone, contentType);
            Assert.AreEqual(clone, contentType);
            Assert.AreEqual(clone.Id, contentType.Id);
            Assert.AreEqual(clone.AllowedTemplates.Count(), contentType.AllowedTemplates.Count());
            for (var index = 0; index < contentType.AllowedTemplates.Count(); index++)
            {
                Assert.AreNotSame(clone.AllowedTemplates.ElementAt(index), contentType.AllowedTemplates.ElementAt(index));
                Assert.AreEqual(clone.AllowedTemplates.ElementAt(index), contentType.AllowedTemplates.ElementAt(index));
            }

            Assert.AreNotSame(clone.PropertyGroups, contentType.PropertyGroups);
            Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
            for (var index = 0; index < contentType.PropertyGroups.Count; index++)
            {
                Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
                Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
            }

            Assert.AreNotSame(clone.PropertyTypes, contentType.PropertyTypes);
            Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
            Assert.AreEqual(0, clone.NoGroupPropertyTypes.Count());
            for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
            {
                Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
                Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
            }

            Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
            Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
            Assert.AreEqual(clone.Key, contentType.Key);
            Assert.AreEqual(clone.Level, contentType.Level);
            Assert.AreEqual(clone.Path, contentType.Path);
            Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
            Assert.AreNotSame(clone.DefaultTemplate, contentType.DefaultTemplate);
            Assert.AreEqual(clone.DefaultTemplate, contentType.DefaultTemplate);
            Assert.AreEqual(clone.DefaultTemplateId, contentType.DefaultTemplateId);
            Assert.AreEqual(clone.Trashed, contentType.Trashed);
            Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
            Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
            Assert.AreEqual(clone.Icon, contentType.Icon);
            Assert.AreEqual(clone.IsContainer, contentType.IsContainer);

            // This double verifies by reflection
            PropertyInfo[] allProps = clone.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in allProps)
            {
                Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
            }

            // Need to ensure the event handlers are wired
            var asDirty = (ICanBeDirty)clone;

            Assert.IsFalse(asDirty.IsPropertyDirty("PropertyTypes"));

            var          propertyTypeBuilder    = new PropertyTypeBuilder();
            PropertyType additionalPropertyType = propertyTypeBuilder
                                                  .WithAlias("blah")
                                                  .Build();

            clone.AddPropertyType(additionalPropertyType);
            Assert.IsTrue(asDirty.IsPropertyDirty("PropertyTypes"));
            Assert.IsFalse(asDirty.IsPropertyDirty("PropertyGroups"));
            clone.AddPropertyGroup("hello", "hello");
            Assert.IsTrue(asDirty.IsPropertyDirty("PropertyGroups"));
        }
コード例 #21
0
    public void ContentPublishValues()
    {
        const string langFr = "fr-FR";

        var propertyType = new PropertyTypeBuilder()
                           .WithAlias("prop")
                           .Build();
        var contentType = new ContentTypeBuilder()
                          .WithAlias("contentType")
                          .Build();

        contentType.AddPropertyType(propertyType);

        var content = CreateContent(contentType);

        // can set value
        // and get edited value, published is null
        // because publishing
        content.SetValue("prop", "a");
        Assert.AreEqual("a", content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));

        // cannot set non-supported variation value
        Assert.Throws <NotSupportedException>(() => content.SetValue("prop", "x", langFr));
        Assert.IsNull(content.GetValue("prop", langFr));

        // can publish value
        // and get edited and published values
        Assert.IsTrue(content.PublishCulture(CultureImpact.All));
        Assert.AreEqual("a", content.GetValue("prop"));
        Assert.AreEqual("a", content.GetValue("prop", published: true));

        // can set value
        // and get edited and published values
        content.SetValue("prop", "b");
        Assert.AreEqual("b", content.GetValue("prop"));
        Assert.AreEqual("a", content.GetValue("prop", published: true));

        // can clear value
        content.UnpublishCulture();
        Assert.AreEqual("b", content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));

        // change - now we vary by culture
        contentType.Variations  |= ContentVariation.Culture;
        propertyType.Variations |= ContentVariation.Culture;
        content.ChangeContentType(contentType);

        // can set value
        // and get values
        content.SetValue("prop", "c", langFr);
        Assert.IsNull(content.GetValue("prop")); // there is no invariant value anymore
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.IsNull(content.GetValue("prop", langFr, published: true));

        // can publish value
        // and get edited and published values
        Assert.IsFalse(content.PublishCulture(CultureImpact.Explicit(langFr, false))); // no name
        content.SetCultureName("name-fr", langFr);
        Assert.IsTrue(content.PublishCulture(CultureImpact.Explicit(langFr, false)));
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.AreEqual("c", content.GetValue("prop", langFr, published: true));

        // can clear all
        content.UnpublishCulture();
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.IsNull(content.GetValue("prop", langFr, published: true));

        // can publish all
        Assert.IsTrue(content.PublishCulture(CultureImpact.All));
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.AreEqual("c", content.GetValue("prop", langFr, published: true));

        // same for culture
        content.UnpublishCulture(langFr);
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.IsNull(content.GetValue("prop", langFr, published: true));
        Assert.IsTrue(content.PublishCulture(CultureImpact.Explicit(langFr, false)));
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.AreEqual("c", content.GetValue("prop", langFr, published: true));

        content.UnpublishCulture(); // clears invariant props if any
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.IsTrue(content.PublishCulture(CultureImpact.All)); // publishes invariant props if any
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));

        var other = CreateContent(contentType, 2, "other");

        Assert.Throws <NotSupportedException>(() => other.SetValue("prop", "o")); // don't even try
        other.SetValue("prop", "o1", langFr);

        // can copy other's edited value
        content.CopyFrom(other);
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.AreEqual("o1", content.GetValue("prop", langFr));
        Assert.AreEqual("c", content.GetValue("prop", langFr, published: true));

        // can copy self's published value
        content.CopyFrom(content);
        Assert.IsNull(content.GetValue("prop"));
        Assert.IsNull(content.GetValue("prop", published: true));
        Assert.AreEqual("c", content.GetValue("prop", langFr));
        Assert.AreEqual("c", content.GetValue("prop", langFr, published: true));
    }
コード例 #22
0
        public void Can_Deep_Clone()
        {
            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateTextPageContentType();

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

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

            content.SetCultureName("Hello", "en-US");
            content.SetCultureName("World", "es-ES");
            content.PublishCulture(CultureImpact.All);

            // should not try to clone something that's not Published or Unpublished
            // (and in fact it will not work)
            // but we cannot directly set the state to Published - hence this trick
            // content.ChangePublishedState(PublishedState.Publishing);
            content.ResetDirtyProperties(false); // => .Published

            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;

            // Act
            var clone = (Content)content.DeepClone();

            // Assert
            Assert.AreNotSame(clone, content);
            Assert.AreEqual(clone, content);
            Assert.AreEqual(clone.Id, content.Id);
            Assert.AreEqual(clone.VersionId, content.VersionId);
            Assert.AreEqual(clone.ContentType, content.ContentType);
            Assert.AreEqual(clone.ContentTypeId, content.ContentTypeId);
            Assert.AreEqual(clone.CreateDate, content.CreateDate);
            Assert.AreEqual(clone.CreatorId, content.CreatorId);
            Assert.AreEqual(clone.Key, content.Key);
            Assert.AreEqual(clone.Level, content.Level);
            Assert.AreEqual(clone.Path, content.Path);
            Assert.AreEqual(clone.Published, content.Published);
            Assert.AreEqual(clone.PublishedState, content.PublishedState);
            Assert.AreEqual(clone.SortOrder, content.SortOrder);
            Assert.AreEqual(clone.PublishedState, content.PublishedState);
            Assert.AreNotSame(clone.TemplateId, content.TemplateId);
            Assert.AreEqual(clone.TemplateId, content.TemplateId);
            Assert.AreEqual(clone.Trashed, content.Trashed);
            Assert.AreEqual(clone.UpdateDate, content.UpdateDate);
            Assert.AreEqual(clone.VersionId, content.VersionId);
            Assert.AreEqual(clone.WriterId, content.WriterId);
            Assert.AreNotSame(clone.Properties, content.Properties);
            Assert.AreEqual(clone.Properties.Count(), content.Properties.Count());
            for (int index = 0; index < content.Properties.Count; index++)
            {
                Assert.AreNotSame(clone.Properties[index], content.Properties[index]);
                Assert.AreEqual(clone.Properties[index], content.Properties[index]);
            }

            Assert.AreNotSame(clone.PublishCultureInfos, content.PublishCultureInfos);
            Assert.AreEqual(clone.PublishCultureInfos.Count, content.PublishCultureInfos.Count);
            foreach (string key in content.PublishCultureInfos.Keys)
            {
                Assert.AreNotSame(clone.PublishCultureInfos[key], content.PublishCultureInfos[key]);
                Assert.AreEqual(clone.PublishCultureInfos[key], content.PublishCultureInfos[key]);
            }

            Assert.AreNotSame(clone.CultureInfos, content.CultureInfos);
            Assert.AreEqual(clone.CultureInfos.Count, content.CultureInfos.Count);
            foreach (string key in content.CultureInfos.Keys)
            {
                Assert.AreNotSame(clone.CultureInfos[key], content.CultureInfos[key]);
                Assert.AreEqual(clone.CultureInfos[key], content.CultureInfos[key]);
            }

            // This double verifies by reflection
            System.Reflection.PropertyInfo[] allProps = clone.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo propertyInfo in allProps)
            {
                Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(content, null));
            }

            // Need to ensure the event handlers are wired
            var asDirty = (ICanBeDirty)clone;

            Assert.IsFalse(asDirty.IsPropertyDirty("Properties"));
            PropertyType propertyType = new PropertyTypeBuilder()
                                        .WithAlias("blah")
                                        .Build();
            IProperty newProperty = new PropertyBuilder()
                                    .WithId(1)
                                    .WithPropertyType(propertyType)
                                    .Build();

            newProperty.SetValue("blah");
            clone.Properties.Add(newProperty);

            Assert.IsTrue(asDirty.IsPropertyDirty("Properties"));
        }