Exemplo n.º 1
0
    public void ManyNestedTest()
    {
        var(_, contentType2) = CreateContentTypes();

        // nested many converter returns the proper value clr type IEnumerable<TestModel>, and cache level
        Assert.AreEqual(typeof(IEnumerable <TestElementModel>), contentType2.GetPropertyType("property2").ClrType);
        Assert.AreEqual(PropertyCacheLevel.Element, contentType2.GetPropertyType("property2").CacheLevel);

        var key     = Guid.NewGuid();
        var keyA    = Guid.NewGuid();
        var keyB    = Guid.NewGuid();
        var content = new InternalPublishedContent(contentType2)
        {
            Key        = key,
            Properties = new[]
            {
                new TestPublishedProperty(contentType2.GetPropertyType("property2"), $@"[
                    {{ ""key"": ""{keyA}"", ""propertyN1"": ""foo"", ""ncContentTypeAlias"": ""contentN1"" }},
                    {{ ""key"": ""{keyB}"", ""propertyN1"": ""bar"", ""ncContentTypeAlias"": ""contentN1"" }}
                ]"),
            },
        };
        var value = content.Value(Mock.Of <IPublishedValueFallback>(), "property2");

        // nested many converter returns proper IEnumerable<TestModel> value
        Assert.IsInstanceOf <IEnumerable <IPublishedElement> >(value);
        Assert.IsInstanceOf <IEnumerable <TestElementModel> >(value);
        var valueM = ((IEnumerable <TestElementModel>)value).ToArray();

        Assert.AreEqual("foo", valueM[0].PropValue);
        Assert.AreEqual(keyA, valueM[0].Key);
        Assert.AreEqual("bar", valueM[1].PropValue);
        Assert.AreEqual(keyB, valueM[1].Key);
    }
Exemplo n.º 2
0
    public void SingleNestedTest()
    {
        var(contentType1, _) = CreateContentTypes();

        // nested single converter returns the proper value clr type TestModel, and cache level
        Assert.AreEqual(typeof(TestElementModel), contentType1.GetPropertyType("property1").ClrType);
        Assert.AreEqual(PropertyCacheLevel.Element, contentType1.GetPropertyType("property1").CacheLevel);

        var key     = Guid.NewGuid();
        var keyA    = Guid.NewGuid();
        var content = new InternalPublishedContent(contentType1)
        {
            Key        = key,
            Properties = new[]
            {
                new TestPublishedProperty(
                    contentType1.GetPropertyType("property1"), $@"[
                    {{ ""key"": ""{keyA}"", ""propertyN1"": ""foo"", ""ncContentTypeAlias"": ""contentN1"" }}
                ]"),
            },
        };
        var value = content.Value(Mock.Of <IPublishedValueFallback>(), "property1");

        // nested single converter returns proper TestModel value
        Assert.IsInstanceOf <TestElementModel>(value);
        var valueM = (TestElementModel)value;

        Assert.AreEqual("foo", valueM.PropValue);
        Assert.AreEqual(keyA, valueM.Key);
    }