Пример #1
0
        public static _TestCaseDiscovered TestCaseDiscovered <TClass>(
            string testMethod,
            string?testCaseDisplayName = null)
        {
            var typeInfo   = typeof(TClass);
            var methodInfo = Guard.NotNull($"Could not find method '{testMethod}' in type '{typeInfo.FullName}'", typeInfo.GetMethod(testMethod));
            var skipReason = methodInfo.GetCustomAttribute <FactAttribute>()?.Skip;
            var traits     = GetTraits(methodInfo);

            var testClassUniqueID  = UniqueIDGenerator.ForTestClass(DefaultTestCollectionUniqueID, typeInfo.FullName);
            var testMethodUniqueID = UniqueIDGenerator.ForTestMethod(testClassUniqueID, testMethod);
            var testCaseUniqueID   = UniqueIDGenerator.ForTestCase(testMethodUniqueID, null, null);

            return(TestCaseDiscovered(
                       DefaultAssemblyUniqueID,
                       DefaultTestCaseSerialization,
                       skipReason,
                       sourceFilePath: null,
                       sourceLineNumber: null,
                       testCaseDisplayName ?? $"{typeInfo.FullName}.{testMethod}",
                       testCaseUniqueID,
                       typeInfo.Name,
                       testClassUniqueID,
                       typeInfo.FullName,
                       DefaultTestCollectionUniqueID,
                       testMethod,
                       testMethodUniqueID,
                       typeInfo.Namespace,
                       traits
                       ));
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestMethodTestCase"/> class.
        /// </summary>
        /// <param name="defaultMethodDisplay">Default method display to use (when not customized).</param>
        /// <param name="defaultMethodDisplayOptions">Default method display options to use (when not customized).</param>
        /// <param name="testMethod">The test method this test case belongs to.</param>
        /// <param name="testMethodArguments">The optional arguments for the test method.</param>
        /// <param name="skipReason">The optional reason for skipping the test.</param>
        /// <param name="traits">The optional traits list.</param>
        /// <param name="uniqueID">The optional unique ID for the test case; if not provided, will be calculated.</param>
        protected TestMethodTestCase(
            TestMethodDisplay defaultMethodDisplay,
            TestMethodDisplayOptions defaultMethodDisplayOptions,
            _ITestMethod testMethod,
            object?[]?testMethodArguments = null,
            string?skipReason             = null,
            Dictionary <string, List <string> >?traits = null,
            string?uniqueID = null)
        {
            DefaultMethodDisplay        = defaultMethodDisplay;
            DefaultMethodDisplayOptions = defaultMethodDisplayOptions;
            SkipReason          = skipReason;
            TestMethod          = Guard.ArgumentNotNull(nameof(testMethod), testMethod);
            TestMethodArguments = testMethodArguments;

            if (traits != null)
            {
                Traits = new Dictionary <string, List <string> >(traits, StringComparer.OrdinalIgnoreCase);
            }
            else
            {
                Traits = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase);
            }

            formatter = new DisplayNameFormatter(defaultMethodDisplay, defaultMethodDisplayOptions);

            var initResults = Initialize(BaseDisplayName, testMethod, TestMethodArguments);

            displayName             = initResults.displayName;
            InitializationException = initResults.initException;
            Method             = initResults.method;
            MethodGenericTypes = initResults.methodGenericTypes;
            this.uniqueID      = uniqueID ?? UniqueIDGenerator.ForTestCase(TestMethod.UniqueID, MethodGenericTypes, TestMethodArguments);

            disposalTracker.AddRange(TestMethodArguments);
        }