<commit_before>﻿namespace AutoTest.ArgNullEx.Execution
{
    using System;
    using System.IO;
    using System.Reflection;
    using System.Threading.Tasks;
    using global::Xunit;
    using global::Xunit.Extensions;

    public class DefaultExecutionSetupShould
    {
        private static MethodData GetStaticMethodData(string methodName, IExecutionSetup sut)
        {
            Type type = typeof(DefaultExecutionSetupShould);
            MethodInfo methodUnderTest = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);

            return new MethodData(
                type,
                null,
                methodUnderTest,
                new object[] {},
                Guid.NewGuid().ToString(),
                0,
                sut);
        }

        private async Task AssertExecutionThrows<T>(MethodData methodData)
            where T : Exception
        {
            // Act
            Task executeAction = methodData.ExecuteAction();

            // Assert
            try
            {
                await executeAction;
            }
            catch (T)
            {
                return;
            }

            Assert.Throws<T>(() => { });
        }

        [Theory, AutoMock]
        public void ShouldInitializeWhenSetup(
            MethodData methodData,
            DefaultExecutionSetup sut)
        {
            // Act
            Func<Task> execute = ((IExecutionSetup)sut).Setup(methodData);

            // Assert
            Assert.NotNull(execute);
            Assert.Same(methodData.MethodUnderTest, sut.MethodUnderTest);
            Assert.Same(methodData.Parameters, sut.Parameters);
            Assert.Same(methodData.InstanceUnderTest, sut.Sut);
        }

        private static MethodData GetContructorMethodData(IExecutionSetup sut)
        {
            Type type = typeof(DefaultExecutionSetupShould);
            ConstructorInfo methodUnderTest = type.GetConstructor(Type.EmptyTypes);

            return new MethodData(
                type,
                new DefaultExecutionSetupShould(),
                methodUnderTest,
                new object[] { },
                Guid.NewGuid().ToString(),
                0,
                sut);
        }

        [Theory, AutoMock]
        public async Task ShouldExecuteContructor(DefaultExecutionSetup sut)
        {
            // Arrange
            MethodData methodData = GetContructorMethodData(sut);

            // Act
            await methodData.ExecuteAction();
        }

        private static void ThrowingSynchronousMethod()
        {
            throw new FileLoadException("Some random message " + Guid.NewGuid());
        }

        [Theory, AutoMock]
        public async Task ShouldExecuteThrowingSynchronousMethod(DefaultExecutionSetup sut)
        {
            // AAA
            await AssertExecutionThrows<FileLoadException>(GetStaticMethodData("ThrowingSynchronousMethod", sut));
        }

        private static async Task ThrowingAsynchronousMethod()
        {
            await Task.Yield();
            throw new FileNotFoundException("Some random message " + Guid.NewGuid());
        }

        [Theory, AutoMock]
        public async Task ExecuteAsynchronousThrowingMethod(DefaultExecutionSetup sut)
        {
            // AAA
            await AssertExecutionThrows<FileNotFoundException>(GetStaticMethodData("ThrowingAsynchronousMethod", sut));
        }

        private static Task ThrowingAsynchronousMethodThrowingSynchronously()
        {
            throw new FieldAccessException("Some random message " + Guid.NewGuid());
        }

        [Theory, AutoMock]
        public async Task ShouldExecuteAsynchronousMethodThatThrowsSynchronously(DefaultExecutionSetup sut)
        {
            // AAA
            await AssertExecutionThrows<FieldAccessException>(GetStaticMethodData("ThrowingAsynchronousMethodThrowingSynchronously", sut));
        }
    }
}<commit_msg>Cleaned up the DefaultExecutionSetup tests<commit_after>﻿namespace AutoTest.ArgNullEx.Execution
{
    using System;
    using System.IO;
    using System.Reflection;
    using System.Threading.Tasks;
    using global::Xunit;
    using global::Xunit.Extensions;

    public class DefaultExecutionSetupShould
    {
        private static MethodData GetMethodData(MethodBase methodUnderTest, IExecutionSetup sut, object instanceUnderTest = null)
        {
            return new MethodData(
                typeof(DefaultExecutionSetupShould),
                instanceUnderTest,
                methodUnderTest,
                new object[] {},
                Guid.NewGuid().ToString(),
                0,
                sut);
        }

        private async Task AssertExecutionThrows<T>(MethodData methodData)
            where T : Exception
        {
            // Act
            // This should never throw but always return a task, either completed or faulted.
            Task executeAction = methodData.ExecuteAction();

            // Assert
            try
            {
                await executeAction;
            }
            catch (T)
            {
                return;
            }

            Assert.Throws<T>(() => { });
        }

        [Theory, AutoMock]
        public void InitializeWhenSetup(
            MethodData methodData,
            DefaultExecutionSetup sut)
        {
            // Act
            Func<Task> execute = ((IExecutionSetup)sut).Setup(methodData);

            // Assert
            Assert.NotNull(execute);
            Assert.Same(methodData.MethodUnderTest, sut.MethodUnderTest);
            Assert.Same(methodData.Parameters, sut.Parameters);
            Assert.Same(methodData.InstanceUnderTest, sut.Sut);
        }

        [Theory, AutoMock]
        public async Task ExecuteContructor(DefaultExecutionSetup sut)
        {
            // Arrange
            MethodData methodData =
                GetMethodData(
                    typeof (DefaultExecutionSetupShould).GetConstructor(Type.EmptyTypes),
                    sut,
                    new DefaultExecutionSetupShould());

            // Act
            await methodData.ExecuteAction();
        }

        [Theory, AutoMock]
        public async Task ExecuteSynchronousMethod(DefaultExecutionSetup sut)
        {
            // Arrange
            Action action = () => { };
            MethodData methodData = GetMethodData(action.Method, sut);

            // Act
            await methodData.ExecuteAction();
        }

        [Theory, AutoMock]
        public async Task ExecuteThrowingSynchronousMethod(DefaultExecutionSetup sut)
        {
            // Arrange
            Action action = () => { throw new FileLoadException("Some random message " + Guid.NewGuid()); };

            // Act/Assert
            await AssertExecutionThrows<FileLoadException>(GetMethodData(action.Method, sut));
        }

        [Theory, AutoMock]
        public async Task ExecuteAsynchronousMethod(DefaultExecutionSetup sut)
        {
            // Arrange
            Func<Task> action = async () => { await Task.Yield(); };
            MethodData methodData = GetMethodData(action.Method, sut);

            // Act
            await methodData.ExecuteAction();
        }

        [Theory, AutoMock]
        public async Task ExecuteAsynchronousThrowingMethod(DefaultExecutionSetup sut)
        {
            // Arrange
            Func<Task> action = async () =>
                {
                    await Task.Yield();
                    throw new FileNotFoundException("Some random message " + Guid.NewGuid());
                };

            // AAA
            await AssertExecutionThrows<FileNotFoundException>(GetMethodData(action.Method, sut));
        }

        [Theory, AutoMock]
        public async Task ExecuteAsynchronousMethodThatThrowsSynchronously(DefaultExecutionSetup sut)
        {
            // Arrange
            Func<Task> action = () => { throw new FieldAccessException("Some random message " + Guid.NewGuid()); };

            // Act/Assert
            await AssertExecutionThrows<FieldAccessException>(GetMethodData(action.Method, sut));
        }
    }
}
{'fraction_non_alphanumeric': 0.08024993874050478, 'fraction_numerical': 0.00036755697133055625, 'mean_word_length': 1.7587022642784724, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 25, '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': '6545406', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1887, 'n_words': 402}