Example #1
0
        public void DefaultServiceProvider_Should_Create_AutoRegisteringGraphTypes()
        {
            var provider = new DefaultServiceProvider();

            provider.GetService(typeof(AutoRegisteringObjectGraphType <Dummy>)).ShouldNotBeNull();
            provider.GetService(typeof(AutoRegisteringInputObjectGraphType <Dummy>)).ShouldNotBeNull();
        }
        public void ReturnInstancesFromParentScopeIfInstantiatedThere()
        {
            using var outerProvider = new DefaultServiceProvider();
            var outerInstance = outerProvider.GetService(typeof(PublicParameterlessConstructor));

            var scopeFactory = (IServiceScopeFactory)outerProvider.GetService(typeof(IServiceScopeFactory));

            using var scope = scopeFactory.CreateScope();
            var innerInstance = scope.ServiceProvider.GetService(typeof(PublicParameterlessConstructor));

            Assert.AreSame(outerInstance, innerInstance);
        }
        public void AutomaticallyProvideATestLogAccessor()
        {
            using var provider = new DefaultServiceProvider();
            var instance = provider.GetService(typeof(ITestLogAccessor));

            Assert.IsInstanceOfType(instance, typeof(TestLogAccessor));
        }
        public void AutomaticallyProvideItselfAsAServiceProvider()
        {
            using var provider = new DefaultServiceProvider();
            var instance = provider.GetService(typeof(IServiceProvider));

            Assert.AreSame(provider, instance);
        }
        public void AutomaticallyProvideAScopeFactory()
        {
            using var provider = new DefaultServiceProvider();
            var instance = provider.GetService(typeof(IServiceScopeFactory));

            Assert.IsInstanceOfType(instance, typeof(DefaultServiceProviderScopeFactory));
        }
        public void InstantiateClassesWithPublicConstructorsWithParameters()
        {
            using var provider = new DefaultServiceProvider();
            var instance = provider.GetService(typeof(PublicConstructorWithParameters));

            Assert.IsInstanceOfType(instance, typeof(PublicConstructorWithParameters));
        }
 public void NotInstantiateClassesWithNonPublicParameterlessConstructors()
 {
     using (var provider = new DefaultServiceProvider())
     {
         Assert.ThrowsException <MissingMethodException>(
             () => provider.GetService(typeof(ProtectedParameterlessConstructor)));
     }
 }
Example #8
0
        private async Task RunTestCases(IEnumerable <TestCase> mappedTests, IFrameworkHandle frameworkHandle)
        {
            using var defaultServiceProvider = new DefaultServiceProvider();
            var testRunContext = defaultServiceProvider.GetService <TestRunContext>();

            var testCaseExecutor = new TestCaseExecutor(
                testRunContext,
                stepsBinder => new StepsExecutor(stepsBinder));

            await testCaseExecutor
            .RunTestCases(mappedTests, frameworkHandle, cancellationTokenSource.Token)
            .ConfigureAwait(false);
        }
Example #9
0
        private void RunMappedTests(IEnumerable <TestCase> mappedTests, IFrameworkHandle frameworkHandle)
        {
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Running tests");

            using (var defaultServiceProvider = new DefaultServiceProvider())
            {
                var testRunContext = (TestRunContext)defaultServiceProvider.GetService(
                    typeof(TestRunContext));

                var runHooks = new RunHooks(
                    testRunContext,
                    mappedTests
                    .Select(
                        test => test
                        .DiscoveredData()
                        .Assembly)
                    .Distinct());

                runHooks.ExecuteBeforeRun().Wait();

                var stepBinder = new StepBinder();

                var tasks = new List <Task>();

                foreach (var testCase in mappedTests)
                {
                    if (isCancelling)
                    {
                        frameworkHandle.SendMessage(TestMessageLevel.Informational, "Test run cancelled");
                        break;
                    }

                    if (testCase.DiscoveredData().IsIgnored)
                    {
                        testCase.MarkAsSkipped(frameworkHandle);
                        continue;
                    }

                    tasks.Add(
                        RunMappedTest(testCase, testCase.DiscoveredData(), testRunContext, stepBinder, frameworkHandle));
                }

                Task.WhenAll(tasks).Wait();
                runHooks.ExecuteAfterRun().Wait();
            }
        }