public static async ValueTask NoTypes()
            {
                var discoverer = TestableTestFrameworkDiscoverer.Create();

                await discoverer.Find();

                Assert.Empty(discoverer.FindTestsForType_TestClasses);
            }
            public static async ValueTask RequestsPublicTypesFromAssembly()
            {
                var framework = TestableTestFrameworkDiscoverer.Create();

                await framework.Find();

                framework.AssemblyInfo.Received(1).GetTypes(includePrivateTypes: false);
            }
        public static async ValueTask GuardClauses()
        {
            var framework = TestableTestFrameworkDiscoverer.Create();

            await Assert.ThrowsAsync <ArgumentNullException>("callback", () => framework.Find(callback: null !, discoveryOptions: _TestFrameworkOptions.ForDiscovery()));

            await Assert.ThrowsAsync <ArgumentNullException>("discoveryOptions", () => framework.Find(callback: _ => new(true), discoveryOptions: null !));
        }
            public static async ValueTask ExcludesAbstractTypes()
            {
                var discoverer = TestableTestFrameworkDiscoverer.Create();

                await discoverer.Find(types : new[] { typeof(AbstractClass) });

                Assert.Empty(discoverer.FindTestsForType_TestClasses);
            }
            public static async ValueTask ExcludesAbstractTypes()
            {
                var abstractClassTypeInfo = Reflector.Wrap(typeof(AbstractClass));
                var discoverer            = TestableTestFrameworkDiscoverer.Create(abstractClassTypeInfo);

                await discoverer.Find();

                Assert.Empty(discoverer.FindTestsForType_TestClasses);
            }
            public static async ValueTask IncludesNonAbstractTypes()
            {
                var discoverer = TestableTestFrameworkDiscoverer.Create();

                await discoverer.Find(types : new[] { typeof(object) });

                var testClass = Assert.Single(discoverer.FindTestsForType_TestClasses);

                Assert.Equal(typeof(object).FullName, testClass.Class.Name);
            }
            public async ValueTask CustomCultureViaDiscoveryOptions()
            {
                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
                var discoverer       = TestableTestFrameworkDiscoverer.Create(mockType);
                var discoveryOptions = _TestFrameworkOptions.ForDiscovery(culture: "en-GB");

                await discoverer.Find(discoveryOptions);

                Assert.NotNull(discoverer.FindTestsForType_CurrentCulture);
                Assert.Equal("en-GB", discoverer.FindTestsForType_CurrentCulture.Name);
            }
            public async ValueTask EmptyStringIsInvariantCulture()
            {
                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
                var discoverer       = TestableTestFrameworkDiscoverer.Create(mockType);
                var discoveryOptions = _TestFrameworkOptions.ForDiscovery(culture: string.Empty);

                await discoverer.Find(discoveryOptions);

                Assert.NotNull(discoverer.FindTestsForType_CurrentCulture);
                Assert.Equal(string.Empty, discoverer.FindTestsForType_CurrentCulture.Name);
            }
        public async void TestContextVisibility()
        {
            var mockType   = Mocks.TypeInfo("MockType");
            var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);

            await discoverer.Find();

            var context = discoverer.FindTestsForType_Context;

            Assert.NotNull(context);
            Assert.Equal(TestEngineStatus.Discovering, context.TestAssemblyStatus);
            Assert.Equal(TestPipelineStage.Discovery, context.PipelineStage);
        }
            public static async ValueTask IncludesNonAbstractTypes()
            {
                var objectTypeInfo = Reflector.Wrap(typeof(object));
                var intTypeInfo    = Reflector.Wrap(typeof(int));
                var discoverer     = TestableTestFrameworkDiscoverer.Create(objectTypeInfo, intTypeInfo);

                await discoverer.Find();

                Assert.Collection(
                    discoverer.FindTestsForType_TestClasses.Select(c => c.Class.Name).OrderBy(x => x),
                    typeName => Assert.Equal(typeof(int).FullName, typeName),                        // System.Int32
                    typeName => Assert.Equal(typeof(object).FullName, typeName)                      // System.Object
                    );
            }
        public async ValueTask ExceptionDuringFindTestsForType_ReportsExceptionAsDiagnosticMessage()
        {
            var spy = SpyMessageSink.Capture();

            TestContext.Current !.DiagnosticMessageSink = spy;

            var mockType   = Mocks.TypeInfo("MockType");
            var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);

            discoverer.FindTestsForType_Exception = new DivideByZeroException();

            await discoverer.Find();

            var message = Assert.Single(spy.Messages.OfType <_DiagnosticMessage>());

            Assert.StartsWith($"Exception during discovery:{Environment.NewLine}System.DivideByZeroException: Attempted to divide by zero.", message.Message);
        }