<commit_before>﻿using BigBook.Tests.BaseClasses;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Xunit;

namespace BigBook.Tests.ExtensionMethods
{
    public interface ITestInterface
    {
        int Value { get; set; }

        int Value2 { get; set; }
    }

    public class ReflectionExtensionsTests : TestingDirectoryFixture
    {
        [Fact]
        public void CallMethodTest()
        {
            int Value = 10;
            Assert.Equal("10", Value.Call<string>("ToString"));
        }

        [Fact]
        public void CreateInstanceTest()
        {
            Assert.NotNull(typeof(TestClass).Create());
            Assert.IsType<TestClass>(typeof(TestClass).Create<ITestInterface>());
        }

        [Fact]
        public void DumpPropertiesTest()
        {
            var TestObject = new List<int>();
            for (int x = 0; x < 10; ++x)
                TestObject.Add(x);
            Assert.Equal("<table><thead><tr><th>Property Name</th><th>Property Value</th></tr></thead><tbody><tr><td>Capacity</td><td>16</td></tr><tr><td>Count</td><td>10</td></tr><tr><td>Item</td><td></td></tr></tbody></table>", TestObject.ToString(true));
        }

        [Fact]
        public void DumpPropertiesWithNoHtmlTest()
        {
            var TestObject = new List<int>();
            for (int x = 0; x < 10; ++x)
                TestObject.Add(x);

            string Output = "Property Name\t\t\t\tProperty Value" + Environment.NewLine +
                            "Capacity\t\t\t\t16" + Environment.NewLine +
                            "Count\t\t\t\t10" + Environment.NewLine +
                            "Item\t\t\t\t";

            Assert.Equal(Output, TestObject.ToString(false));
        }

        [Fact]
        public void GetAttribute()
        {
            var TestObject = typeof(TestClass).GetTypeInfo().Attribute<TestingAttribute>();
            Assert.NotNull(TestObject);
        }

        [Fact]
        public void GetAttributes()
        {
            Assert.Equal(1, typeof(TestClass).GetTypeInfo().Attributes<TestingAttribute>().Length);
        }

        [Fact]
        public void GetNameTest()
        {
            Assert.Equal("BigBook.Tests.ExtensionMethods.TestClass", typeof(TestClass).GetName());
            Assert.Equal("BigBook.Tests.ExtensionMethods.TestClass2", typeof(TestClass2).GetName());
            Assert.Equal("BigBook.Tests.ExtensionMethods.TestClass3<System.Int32>", typeof(TestClass3<int>).GetName());
        }

        [Fact]
        public void GetPropertyGetterTest()
        {
            var TestObject = typeof(TestClass).GetProperty("Value").PropertyGetter<TestClass, int>();
            var TestObject2 = new TestClass
            {
                Value = 10
            };
            Assert.Equal(10, TestObject.Compile()(TestObject2));
        }

        [Fact]
        public void GetPropertyNameTest()
        {
            Expression<Func<TestClass, int>> TestObject = x => x.Value;
            Assert.Equal("Value", TestObject.PropertyName());
            Expression<Func<TestClass, int>> TestObject2 = x => x.Value2;
            Assert.Equal("Value2", TestObject2.PropertyName());
        }

        [Fact]
        public void GetPropertySetterTest()
        {
            Expression<Func<TestClass, int>> TestObject = x => x.Value;
            var TestObject2 = TestObject.PropertySetter<TestClass, int>();
            var TestObject3 = new TestClass();
            TestObject2.Compile()(TestObject3, 10);
            Assert.Equal(10, TestObject3.Value);
        }

        [Fact]
        public void GetPropertySetterTest2()
        {
            Expression<Func<TestClass4, int>> TestObject = x => x.Temp.Value;
            var TestObject2 = TestObject.PropertySetter<TestClass4, int>();
            var TestObject3 = new TestClass4();
            TestObject2.Compile()(TestObject3, 10);
            Assert.Equal(10, TestObject3.Temp.Value);
        }

        [Fact]
        public void GetPropertyTest()
        {
            Assert.Equal(1, new TestClass().Property("Value"));
            Assert.Equal(2, new TestClass().Property("Value2"));
        }

        [Fact]
        public void GetPropertyTypeTest()
        {
            Assert.Equal(typeof(int), new TestClass().PropertyType("Value"));
            Assert.Equal(typeof(int), new TestClass().PropertyType("Value2"));
        }

        [Fact]
        public void GetTypesTest()
        {
            Assert.Equal(3, typeof(ReflectionExtensionsTests)
                                        .GetTypeInfo()
                                        .Assembly
                                        .Types<ITestInterface>()
                                        .Count());
        }

        [Fact]
        public void HasDefaultConstructor()
        {
            Assert.True(typeof(TestClass).HasDefaultConstructor());
        }

        [Fact]
        public void IsDebug()
        {
            Assert.True(GetType().GetTypeInfo().Assembly.IsDebug());
        }

        [Fact]
        public void IsIEnumerableTest()
        {
            var TestObject = new List<int>();
            Assert.True(TestObject.GetType().Is(typeof(IEnumerable)));
        }

        [Fact]
        public void IsJitOptimized()
        {
            Assert.False(GetType().GetTypeInfo().Assembly.IsJitOptimized());
        }

        [Fact]
        public void IsOfTypeTest()
        {
            var TestObject = new List<int>();
            Assert.True(TestObject.Is(typeof(List<int>)));
        }

        [Fact]
        public void MakeShallowCopyTest()
        {
            var TestObject1 = new TestClass
            {
                Value = 3,
                Value3 = "This is a test"
            };<commit_msg>Fixing it if run in release mode.<commit_after>﻿using BigBook.Tests.BaseClasses;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Xunit;

namespace BigBook.Tests.ExtensionMethods
{
    public interface ITestInterface
    {
        int Value { get; set; }

        int Value2 { get; set; }
    }

    public class ReflectionExtensionsTests : TestingDirectoryFixture
    {
        [Fact]
        public void CallMethodTest()
        {
            int Value = 10;
            Assert.Equal("10", Value.Call<string>("ToString"));
        }

        [Fact]
        public void CreateInstanceTest()
        {
            Assert.NotNull(typeof(TestClass).Create());
            Assert.IsType<TestClass>(typeof(TestClass).Create<ITestInterface>());
        }

        [Fact]
        public void DumpPropertiesTest()
        {
            var TestObject = new List<int>();
            for (int x = 0; x < 10; ++x)
                TestObject.Add(x);
            Assert.Equal("<table><thead><tr><th>Property Name</th><th>Property Value</th></tr></thead><tbody><tr><td>Capacity</td><td>16</td></tr><tr><td>Count</td><td>10</td></tr><tr><td>Item</td><td></td></tr></tbody></table>", TestObject.ToString(true));
        }

        [Fact]
        public void DumpPropertiesWithNoHtmlTest()
        {
            var TestObject = new List<int>();
            for (int x = 0; x < 10; ++x)
                TestObject.Add(x);

            string Output = "Property Name\t\t\t\tProperty Value" + Environment.NewLine +
                            "Capacity\t\t\t\t16" + Environment.NewLine +
                            "Count\t\t\t\t10" + Environment.NewLine +
                            "Item\t\t\t\t";

            Assert.Equal(Output, TestObject.ToString(false));
        }

        [Fact]
        public void GetAttribute()
        {
            var TestObject = typeof(TestClass).GetTypeInfo().Attribute<TestingAttribute>();
            Assert.NotNull(TestObject);
        }

        [Fact]
        public void GetAttributes()
        {
            Assert.Equal(1, typeof(TestClass).GetTypeInfo().Attributes<TestingAttribute>().Length);
        }

        [Fact]
        public void GetNameTest()
        {
            Assert.Equal("BigBook.Tests.ExtensionMethods.TestClass", typeof(TestClass).GetName());
            Assert.Equal("BigBook.Tests.ExtensionMethods.TestClass2", typeof(TestClass2).GetName());
            Assert.Equal("BigBook.Tests.ExtensionMethods.TestClass3<System.Int32>", typeof(TestClass3<int>).GetName());
        }

        [Fact]
        public void GetPropertyGetterTest()
        {
            var TestObject = typeof(TestClass).GetProperty("Value").PropertyGetter<TestClass, int>();
            var TestObject2 = new TestClass
            {
                Value = 10
            };
            Assert.Equal(10, TestObject.Compile()(TestObject2));
        }

        [Fact]
        public void GetPropertyNameTest()
        {
            Expression<Func<TestClass, int>> TestObject = x => x.Value;
            Assert.Equal("Value", TestObject.PropertyName());
            Expression<Func<TestClass, int>> TestObject2 = x => x.Value2;
            Assert.Equal("Value2", TestObject2.PropertyName());
        }

        [Fact]
        public void GetPropertySetterTest()
        {
            Expression<Func<TestClass, int>> TestObject = x => x.Value;
            var TestObject2 = TestObject.PropertySetter<TestClass, int>();
            var TestObject3 = new TestClass();
            TestObject2.Compile()(TestObject3, 10);
            Assert.Equal(10, TestObject3.Value);
        }

        [Fact]
        public void GetPropertySetterTest2()
        {
            Expression<Func<TestClass4, int>> TestObject = x => x.Temp.Value;
            var TestObject2 = TestObject.PropertySetter<TestClass4, int>();
            var TestObject3 = new TestClass4();
            TestObject2.Compile()(TestObject3, 10);
            Assert.Equal(10, TestObject3.Temp.Value);
        }

        [Fact]
        public void GetPropertyTest()
        {
            Assert.Equal(1, new TestClass().Property("Value"));
            Assert.Equal(2, new TestClass().Property("Value2"));
        }

        [Fact]
        public void GetPropertyTypeTest()
        {
            Assert.Equal(typeof(int), new TestClass().PropertyType("Value"));
            Assert.Equal(typeof(int), new TestClass().PropertyType("Value2"));
        }

        [Fact]
        public void GetTypesTest()
        {
            Assert.Equal(3, typeof(ReflectionExtensionsTests)
                                        .GetTypeInfo()
                                        .Assembly
                                        .Types<ITestInterface>()
                                        .Count());
        }

        [Fact]
        public void HasDefaultConstructor()
        {
            Assert.True(typeof(TestClass).HasDefaultConstructor());
        }

        [Fact]
        public void IsDebug()
        {
#if DEBUG
            Assert.True(GetType().GetTypeInfo().Assembly.IsDebug());
#else
            Assert.False(GetType().GetTypeInfo().Assembly.IsDebug());
#endif
        }

        [Fact]
        public void IsIEnumerableTest()
        {
            var TestObject = new List<int>();
            Assert.True(TestObject.GetType().Is(typeof(IEnumerable)));
        }

        [Fact]
        public void IsJitOptimized()
        {
#if DEBUG
            Assert.True(GetType().GetTypeInfo().Assembly.IsJitOptimized());
#else
            Assert.False(GetType().GetTypeInfo().Assembly.IsJitOptimized());
#endif
        }

        [Fact]
        public void IsOfTypeTest()
        {
            var TestObject = new List<int>();
            Assert.True(TestObject.Is(typeof(List<int>)));
        }

        [Fact]
        public void MakeShallowCopyTest()
        {
            var TestObject1 = new TestClass
            {
                Value = 3,
                Value3 = "This is a test"
            };
{'fraction_non_alphanumeric': 0.1250418200066912, 'fraction_numerical': 0.011040481766477083, 'mean_word_length': 1.7884794776119404, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5561511', 'n_tokens_mistral': 3228, 'n_tokens_neox': 3123, 'n_words': 566}