Example #1
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));
    }
Example #2
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?
    }
Example #3
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
    }
Example #4
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));
    }