Exemplo n.º 1
0
        public void TestGetLinkedEntitiesWithEmptyValue()
        {
            // arrange
            var gridConfigMock = new Mock <IGridConfig>();

            var parser = new GridParser(gridConfigMock.Object);

            // act
            var result = parser.GetLinkedEntities(null);

            // verify
            Assert.IsNotNull(result);
            var entities = result.ToList();

            Assert.AreEqual(0, entities.Count());
        }
Exemplo n.º 2
0
        public void TestGetLinkedEntitiesWithValue()
        {
            // arrange
            var mediaEditorAlias          = "media_text_right";
            var mediaGridEditorConfigMock = new Mock <IGridEditorConfig>();

            mediaGridEditorConfigMock.SetupGet(x => x.Alias).Returns(mediaEditorAlias);
            mediaGridEditorConfigMock.SetupGet(x => x.View).Returns("media");

            var richTextEditorAlias       = "rte";
            var richtTextEditorConfigMock = new Mock <IGridEditorConfig>();

            richtTextEditorConfigMock.SetupGet(x => x.Alias).Returns(richTextEditorAlias);
            richtTextEditorConfigMock.SetupGet(x => x.View).Returns("rte");

            var gridEditorsConfigMock = new Mock <IGridEditorsConfig>();

            gridEditorsConfigMock.SetupGet(x => x.Editors)
            .Returns(
                new List <IGridEditorConfig> {
                mediaGridEditorConfigMock.Object, richtTextEditorConfigMock.Object
            });

            var gridConfigMock = new Mock <IGridConfig>();

            gridConfigMock.SetupGet(x => x.EditorsConfig).Returns(gridEditorsConfigMock.Object);

            var parser = new GridParser(gridConfigMock.Object);

            var mediaId   = 1086;
            var contentId = 1068;

            var value = $@"{{
  ""name"": ""1 column layout"",
  ""sections"": [
    {{
      ""grid"": 12,
      ""rows"": [        
        {{
          ""name"": ""Article"",
          ""areas"": [
            {{
              ""grid"": 4,
              ""controls"": [
                {{
                  ""value"": {{
                    ""focalPoint"": {{
                      ""left"": 0.5,
                      ""top"": 0.5
                    }},
                    ""id"": {mediaId},
                    ""image"": ""/media/1050/costa-rican-frog.jpg""
                  }},
                  ""editor"": {{
                    ""alias"": ""{mediaEditorAlias}""
                  }}
                }}
              ]
            }},
            {{
              ""grid"": 8,
              ""controls"": [
                {{
                  ""value"": ""<p>Test rich text editor with <a data-id=\""{contentId}\"" href=\""/{{localLink:{contentId}}}\"" title=\""Explore\"">links</a></p>\n<p> </p>"",
                  ""editor"": {{
                    ""alias"": ""{richTextEditorAlias}""
                  }}
                }}
              ]
            }}
          ],
          ""id"": ""1c03d717-41ff-a495-5abb-4cd6abf71d7c""
        }}
      ]
    }}
  ]
}}";

            // act
            var result = parser.GetLinkedEntities(value);

            // verify
            Assert.IsNotNull(result);
            var entities = result.ToList();

            Assert.AreEqual(2, entities.Count());

            Assert.IsTrue(entities.Any(x => x.Id == mediaId && x.LinkedEntityType == LinkedEntityType.Media));
            Assert.IsTrue(entities.Any(x => x.Id == contentId && x.LinkedEntityType == LinkedEntityType.Document));
        }