private static Type GetInjectionFactoryTypeFromAttribute()
        {
            var injectionFactoryAttribute = AppDomain.CurrentDomain.GetAssemblies()
                                            .SelectMany(a => a.GetCustomAttributes(typeof(NUnitTypeInjectionFactoryAttribute), false))
                                            .OfType <NUnitTypeInjectionFactoryAttribute>()
                                            .FirstOrDefault();

            if (injectionFactoryAttribute == null)
            {
                throw new InvalidOperationException(
                          $"{nameof(DependencyInjectingTestFixtureAttribute)} requires an injection plugin be loaded. Please ensure " +
                          $"that one is present or create one using the {typeof(IInjectionFactory).FullName} interface " +
                          $"and register it using the {typeof(NUnitTypeInjectionFactoryAttribute).FullName} attribute.");
            }
            InjectionFactoryTypeValidator.AssertIsValidFactoryType(injectionFactoryAttribute.InjectionFactoryType);
            Trace.TraceInformation(
                $"Found {nameof(NUnitTypeInjectionFactoryAttribute)} in assembly " +
                $"{injectionFactoryAttribute.GetType().Assembly.FullName}. Will use the {injectionFactoryAttribute.InjectionFactoryType} type " +
                "to create dependencies.");
            return(injectionFactoryAttribute.InjectionFactoryType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of the constructor declaring that the
        /// <see cref="NUnit.Extension.DependencyInjection.Abstractions.IInjectionFactory"/> will be of type
        /// <paramref name="factoryType"/>.
        /// </summary>
        /// <param name="factoryType">The type of the factory to use.</param>
        public NUnitTypeInjectionFactoryAttribute(Type factoryType)
        {
            InjectionFactoryTypeValidator.AssertIsValidFactoryType(factoryType);

            InjectionFactoryType = factoryType;
        }