<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CRP.Tests.Core.Helpers
{
    public static class AttributeAndFieldValidation
    {
        /// <summary>
        /// Validates the fields and attributes.
        /// </summary>
        /// <param name="expectedFields">The expected fields.</param>
        /// <param name="entityType">Type of the entity.</param>
        public static void ValidateFieldsAndAttributes(List<NameAndType> expectedFields, Type entityType)
        {
            #region Act
            // get all public static properties of MyClass type
            var propertyInfos = entityType.GetProperties();

            // sort properties by name
            Array.Sort(propertyInfos, (propertyInfo1, propertyInfo2) => propertyInfo1.Name.CompareTo(propertyInfo2.Name));
            #endregion Act

            #region Assert
            Assert.AreEqual(propertyInfos.Count(), expectedFields.Count);
            for (int i = 0; i < propertyInfos.Count(); i++)
            {
                Assert.AreEqual(propertyInfos[i].Name, expectedFields[i].Name);
                Assert.AreEqual(propertyInfos[i].PropertyType.ToString(), expectedFields[i].Property);
                var foundAttributes = CustomAttributeData.GetCustomAttributes(propertyInfos[i]);
                Assert.AreEqual(expectedFields[i].Attributes.Count, foundAttributes.Count);
                if (foundAttributes.Count > 0)
                {
                    for (int j = 0; j < foundAttributes.Count; j++)<commit_msg>Sort the attributes before I compare them so they are not order dependant from the reflection. (Updated by TFS to TFS Connector, server: http://1x:8080/, id 6222. )<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CRP.Tests.Core.Helpers
{
    public static class AttributeAndFieldValidation
    {
        /// <summary>
        /// Validates the fields and attributes.
        /// </summary>
        /// <param name="expectedFields">The expected fields.</param>
        /// <param name="entityType">Type of the entity.</param>
        public static void ValidateFieldsAndAttributes(List<NameAndType> expectedFields, Type entityType)
        {
            #region Act
            // get all public static properties of MyClass type
            var propertyInfos = entityType.GetProperties();

            // sort properties by name
            Array.Sort(propertyInfos, (propertyInfo1, propertyInfo2) => propertyInfo1.Name.CompareTo(propertyInfo2.Name));
            #endregion Act

            #region Assert
            Assert.AreEqual(propertyInfos.Count(), expectedFields.Count);
            for (int i = 0; i < propertyInfos.Count(); i++)
            {
                Assert.AreEqual(propertyInfos[i].Name, expectedFields[i].Name);
                Assert.AreEqual(propertyInfos[i].PropertyType.ToString(), expectedFields[i].Property);
                var foundAttributes = CustomAttributeData.GetCustomAttributes(propertyInfos[i])
                    .AsQueryable().OrderBy(a => a.NamedArguments.ToString()).ToList();
                Assert.AreEqual(expectedFields[i].Attributes.Count, foundAttributes.Count());
                if (foundAttributes.Count() > 0)
                {
                    //Array.Sort(foundAttributes, (attribute1, attribute2)=> attribute1.NamedArguments.ToString().CompareTo(attribute2.NamedArguments.ToString()));
                    for (int j = 0; j < foundAttributes.Count(); j++)
{'fraction_non_alphanumeric': 0.10804911323328786, 'fraction_numerical': 0.007366984993178717, 'mean_word_length': 2.5386100386100385, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '5901024', 'n_tokens_mistral': 923, 'n_tokens_neox': 894, 'n_words': 215}