Example #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
                       ));
        }
Example #2
0
    static Xunit2MessageAdapterTests()
    {
        try
        {
            throw new DivideByZeroException();
        }
        catch (Exception ex)
        {
            ThrownException = ex;
        }

        Traits = new Dictionary <string, List <string> >
        {
            { "key1", new List <string> {
                  "value1a", "value1b"
              } },
            { "key2", new List <string> {
                  "value2"
              } },
            { "key3", new List <string>() }
        };

        TestAssembly         = Xunit2Mocks.TestAssembly("testAssembly.dll", "xunit.runner.json");
        TestAssemblyUniqueID = UniqueIDGenerator.ForAssembly(
            TestAssembly.Assembly.Name,
            TestAssembly.Assembly.AssemblyPath,
            TestAssembly.ConfigFileName
            );

        TestCollectionDefinition = Xunit2Mocks.TypeInfo();
        TestCollection           = Xunit2Mocks.TestCollection(TestAssembly, TestCollectionDefinition, "test-collection-display-name");
        TestCollectionUniqueID   = UniqueIDGenerator.ForTestCollection(
            TestAssemblyUniqueID,
            TestCollection.DisplayName,
            TestCollectionDefinition.Name
            );

        TestClassType     = Xunit2Mocks.TypeInfo();
        TestClass         = Xunit2Mocks.TestClass(TestCollection, TestClassType);
        TestClassUniqueID = UniqueIDGenerator.ForTestClass(
            TestCollectionUniqueID,
            TestClass.Class.Name
            );

        TestMethod         = Xunit2Mocks.TestMethod(TestClass, "MyTestMethod");
        TestMethodUniqueID = UniqueIDGenerator.ForTestMethod(
            TestClassUniqueID,
            TestMethod.Method.Name
            );

        TestCase         = Xunit2Mocks.TestCase(TestMethod, "test-case-display-name", "skip-reason", "source-file", 2112, Traits, "test-case-id");
        TestCaseUniqueID = TestCase.UniqueID;

        Test         = Xunit2Mocks.Test(TestCase, "test-display-name");
        TestUniqueID = UniqueIDGenerator.ForTest(TestCaseUniqueID, 0);
    }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestMethod"/> class.
        /// </summary>
        /// <param name="testClass">The test class</param>
        /// <param name="method">The test method</param>
        /// <param name="uniqueID">The unique ID for the test method (only used to override default behavior in testing scenarios)</param>
        public TestMethod(
            _ITestClass testClass,
            _IMethodInfo method,
            string?uniqueID = null)
        {
            this.testClass = Guard.ArgumentNotNull(nameof(testClass), testClass);
            this.method    = Guard.ArgumentNotNull(nameof(method), method);

            this.uniqueID = uniqueID ?? UniqueIDGenerator.ForTestMethod(testClass.UniqueID, this.method.Name);
        }
 string?UniqueIDForTestMethod(
     string?classUniqueID,
     ITestMethod testMethod) =>
 UniqueIDGenerator.ForTestMethod(classUniqueID, testMethod.Method.Name);