<commit_before>﻿namespace Our.Umbraco.Nexu.Parsers.Tests.PropertyParsers.Core
{
    using global::Umbraco.Core.Models;

    using NUnit.Framework;

    using Our.Umbraco.Nexu.Parsers.PropertyParsers.Core;

    /// <summary>
    /// The grid parser tests.
    /// </summary>
    [TestFixture]
    public class GridParserTests : BaseParserTest
    {
        /// <summary>
        /// The test is parser for valid data type.
        /// </summary>
        [Test]
        [Category("PropertyParsers")]
        [Category("CorePropertyParsers")]
        public void TestIsParserForValidDataType()
        {
            // arrange
            var dataTypeDefinition = new DataTypeDefinition(global::Umbraco.Core.Constants.PropertyEditors.GridAlias);

            var parser = new GridParser();

            // act
            var result = parser.IsParserFor(dataTypeDefinition);

            // verify
            Assert.IsTrue(result);
        }

        /// <summary>
        /// The test is parser for in valid data type.
        /// </summary>
        [Test]
        [Category("PropertyParsers")]
        [Category("CorePropertyParsers")]
        public void TestIsParserForInValidDataType()
        {
            // arrange
            var dataTypeDefinition = new DataTypeDefinition("foo");

            var parser = new GridParser();

            // act
            var result = parser.IsParserFor(dataTypeDefinition);

            // verify
            Assert.IsFalse(result);
        }
    }
}<commit_msg>Added unit test for GetLinkedEntities of GridParser<commit_after>﻿namespace Our.Umbraco.Nexu.Parsers.Tests.PropertyParsers.Core
{
    using System.Linq;

    using global::Umbraco.Core.Models;

    using NUnit.Framework;

    using Our.Umbraco.Nexu.Core.Enums;
    using Our.Umbraco.Nexu.Parsers.PropertyParsers.Core;

    /// <summary>
    /// The grid parser tests.
    /// </summary>
    [TestFixture]
    public class GridParserTests : BaseParserTest
    {
        /// <summary>
        /// The test is parser for valid data type.
        /// </summary>
        [Test]
        [Category("PropertyParsers")]
        [Category("CorePropertyParsers")]
        public void TestIsParserForValidDataType()
        {
            // arrange
            var dataTypeDefinition = new DataTypeDefinition(global::Umbraco.Core.Constants.PropertyEditors.GridAlias);

            var parser = new GridParser();

            // act
            var result = parser.IsParserFor(dataTypeDefinition);

            // verify
            Assert.IsTrue(result);
        }

        /// <summary>
        /// The test is parser for in valid data type.
        /// </summary>
        [Test]
        [Category("PropertyParsers")]
        [Category("CorePropertyParsers")]
        public void TestIsParserForInValidDataType()
        {
            // arrange
            var dataTypeDefinition = new DataTypeDefinition("foo");

            var parser = new GridParser();

            // act
            var result = parser.IsParserFor(dataTypeDefinition);

            // verify
            Assert.IsFalse(result);
        }

        /// <summary>
        /// Test getting linked entities with a value
        /// </summary>
        [Test]
        [Category("PropertyParsers")]
        [Category("CorePropertyParsers")]
        public void TestGetLinkedEntitiesWithValue()
        {
            // arrange
            var parser = new GridParser();

            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"": ""media_text_right""
                  }}
                }}
              ]
            }},
            {{
              ""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"": ""rte""
                  }}
                }}
              ]
            }}
          ],
          ""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));
        }

        /// <summary>
        /// Test getting linked entities with a empty value
        /// </summary>
        [Test]
        [Category("PropertyParsers")]
        [Category("CorePropertyParsers")]
        public void TestGetLinkedEntitiesWithEmptyValue()
        {
            // arrange
            var parser = new GridParser();
            
            // act
            var result = parser.GetLinkedEntities(null);

            // verify
            Assert.IsNotNull(result);
            var entities = result.ToList();
            Assert.AreEqual(0, entities.Count());
        }
    }
}
{'fraction_non_alphanumeric': 0.13332189430336308, 'fraction_numerical': 0.0068634179821551134, 'mean_word_length': 1.4574198988195615, 'pattern_counts': {'":': 22, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1893394', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1516, 'n_words': 301}