Exemple #1
0
        /// <summary>
        /// Gets a service for the specified test's scope
        /// </summary>
        /// <param name="testMethod">The method info of the test method which is requesting a service</param>
        /// <param name="serviceType">The type of the service the method is requesting</param>
        /// <returns>The requested service instance or <see langword="null"/> if it was not found</returns>
        public static object GetService(IMethodInfo testMethod, Type serviceType)
        {
            var serviceProvider = GetServiceProvider(testMethod.TypeInfo.Assembly);

            var scope = FixtureScopes.GetOrAdd(testMethod.TypeInfo.Type.AssemblyQualifiedName, (_) => new FixtureScope(serviceProvider.CreateScope()));

            return(scope.GetServiceFor(testMethod.GetNunitName(), serviceType));
        }