<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Sdk;

namespace Grean.Exude
{
    public class FirstClassTestsAttribute : FactAttribute
    {
        protected override IEnumerable<ITestCommand> EnumerateTestCommands(
            IMethodInfo method)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            if (!typeof(IEnumerable<FirstClassCommand>).IsAssignableFrom(method.MethodInfo.ReturnType))
                throw new ArgumentException(
                    invalidReturnTypeErrorMessage,
                    "method");

            var testClassInstance = method.CreateInstance();
            var returnValue = method.MethodInfo.Invoke(testClassInstance, null);
            return from fcc in (IEnumerable<FirstClassCommand>)returnValue
                   select fcc as ITestCommand;
        }

        private const string invalidReturnTypeErrorMessage = @"The supplied method does not return IEnumerable<FirstClassCommand>. When using the [FirstClassTests] attribute, the method it adorns must return IEnumerable<FirstClassCommand>; for example:

[FirstClassTests]
public static IEnumerable<FirstClassCommand> MyTestMethod()
{
    // Return FirstClassCommands here
}
";
    }
}<commit_msg>Extracted conditional to a named helper method,<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Sdk;

namespace Grean.Exude
{
    public class FirstClassTestsAttribute : FactAttribute
    {
        protected override IEnumerable<ITestCommand> EnumerateTestCommands(
            IMethodInfo method)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            if (IsReturnTypeInvalid(method))
                throw new ArgumentException(
                    invalidReturnTypeErrorMessage,
                    "method");

            var testClassInstance = method.CreateInstance();
            var returnValue = method.MethodInfo.Invoke(testClassInstance, null);
            return from fcc in (IEnumerable<FirstClassCommand>)returnValue
                   select fcc as ITestCommand;
        }

        private static bool IsReturnTypeInvalid(IMethodInfo method)
        {
            return !typeof(IEnumerable<FirstClassCommand>).IsAssignableFrom(
                method.MethodInfo.ReturnType);
        }

        private const string invalidReturnTypeErrorMessage = @"The supplied method does not return IEnumerable<FirstClassCommand>. When using the [FirstClassTests] attribute, the method it adorns must return IEnumerable<FirstClassCommand>; for example:

[FirstClassTests]
public static IEnumerable<FirstClassCommand> MyTestMethod()
{
    // Return FirstClassCommands here
}
";
    }
}
{'fraction_non_alphanumeric': 0.0700280112044818, 'fraction_numerical': 0.0, 'mean_word_length': 2.9030054644808745, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2999414', 'n_tokens_mistral': 694, 'n_tokens_neox': 671, 'n_words': 186}