<commit_before>﻿using NUnit.Framework;
using OnlineShop.Libs.Models.Contracts;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace OnlineShop.Libs.Models.Tests.ContractsTests.INameableTests
{
    [TestFixture]
    public class Name_Should
    {
        /// <summary>
        /// Fail mean class that implement INameable dont have validation attributes
        /// </summary>
        [Test]
        public void Have_Validation_Attributes()
        {
            var propertyName = "Name";

            var types = AppDomain
                            .CurrentDomain
                            .GetAssemblies()
                            .SelectMany(x => x.GetTypes())
                            .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Contains(typeof(INameable)));

            foreach (Type type in types)
            {
                var result = type
                                .GetProperty(propertyName)
                                .GetCustomAttributes(false)
                                .Select(x => x.GetType());
             
                CollectionAssert.Contains(result, typeof(RequiredAttribute), message: $"{type.Name} does not have Required attribute");
                CollectionAssert.Contains(result, typeof(MinLengthAttribute), message: $"{type.Name} does not have MinLength attribute");
                CollectionAssert.Contains(result, typeof(MaxLengthAttribute), message: $"{type.Name} does not have MaxLength attribute");
                CollectionAssert.Contains(result, typeof(RegularExpressionAttribute), message: $"{type.Name} does not have RegularExpression attribute");
            }
        }

        [TestCase("")]
        [TestCase("123")]
        [TestCase("dfs,kjcfl.jdscl;fsd")]
        [TestCase("not a string")]
        [TestCase("@#@##$><$#@><!@#<!>")]
        public void GetAndSet_Should_Work(string randomString)
        {
            var types = AppDomain
                .CurrentDomain
                .GetAssemblies()
                .SelectMany(x => x.GetTypes())
                .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Contains(typeof(INameable)));

            foreach (Type type in types)
            {
                var obj = (INameable)Activator.CreateInstance(type);

                obj.Name = randomString;

                Assert.AreEqual(randomString, obj.Name);
            }
        }
    }
}<commit_msg>added message to Name get/set check message to INamaable classes<commit_after>﻿using NUnit.Framework;
using OnlineShop.Libs.Models.Contracts;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace OnlineShop.Libs.Models.Tests.ContractsTests.INameableTests
{
    [TestFixture]
    public class Name_Should
    {
        /// <summary>
        /// Fail mean class that implement INameable dont have validation attributes
        /// </summary>
        [Test]
        public void Have_Validation_Attributes()
        {
            var propertyName = "Name";

            var types = AppDomain
                            .CurrentDomain
                            .GetAssemblies()
                            .SelectMany(x => x.GetTypes())
                            .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Contains(typeof(INameable)));

            foreach (Type type in types)
            {
                var result = type
                                .GetProperty(propertyName)
                                .GetCustomAttributes(false)
                                .Select(x => x.GetType());
             
                CollectionAssert.Contains(result, typeof(RequiredAttribute), message: $"{type.Name} does not have Required attribute");
                CollectionAssert.Contains(result, typeof(MinLengthAttribute), message: $"{type.Name} does not have MinLength attribute");
                CollectionAssert.Contains(result, typeof(MaxLengthAttribute), message: $"{type.Name} does not have MaxLength attribute");
                CollectionAssert.Contains(result, typeof(RegularExpressionAttribute), message: $"{type.Name} does not have RegularExpression attribute");
            }
        }

        [TestCase("")]
        [TestCase("123")]
        [TestCase("dfs,kjcfl.jdscl;fsd")]
        [TestCase("not a string")]
        [TestCase("@#@##$><$#@><!@#<!>")]
        public void GetAndSet_Should_Work(string randomString)
        {
            var types = AppDomain
                .CurrentDomain
                .GetAssemblies()
                .SelectMany(x => x.GetTypes())
                .Where(x => x.IsClass && !x.IsAbstract && x.GetInterfaces().Contains(typeof(INameable)));

            foreach (Type type in types)
            {
                var obj = (INameable)Activator.CreateInstance(type);

                obj.Name = randomString;

                Assert.AreEqual(randomString, obj.Name, message: $"{type.Name} get/set do not work properly!");
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11170848267622462, 'fraction_numerical': 0.0011947431302270011, 'mean_word_length': 1.8250843644544432, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2410496', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1239, 'n_words': 272}