/// <summary>
        /// Initializes a new instance of the <see cref="OverridingTargetContainer"/> class.
        /// </summary>
        /// <param name="parent">Required. The parent target container.</param>
        /// <param name="config">Optional.  The configuration to apply to this target container.  If null, then
        /// the <see cref="TargetContainer.DefaultConfig"/> is used.
        /// </param>
        public OverridingTargetContainer(ITargetContainer parent, ITargetContainerConfig config = null)
            : base()
        {
            Parent = parent ?? throw new ArgumentNullException(nameof(parent));

            (config ?? DefaultConfig).Configure(this);
        }
예제 #2
0
        /// <summary>
        /// Constructs a new instance of the <see cref="TargetContainer"/> class.
        /// </summary>
        /// <param name="config">Optional.  The configuration to apply to this target container.  If null, then
        /// the <see cref="DefaultConfig"/> is used.
        /// </param>
        /// <remarks>Note to inheritors: this constructor will throw an <see cref="InvalidOperationException"/> if called by derived
        /// classes.  You must instead use the <see cref="TargetContainer.TargetContainer()"/> constructor and apply configuration in your
        /// constructor.</remarks>
        public TargetContainer(ITargetContainerConfig config = null)
            : this()
        {
            if (GetType() != typeof(TargetContainer))
            {
                throw new InvalidOperationException("Derived types must not use this constructor because it triggers virtual method calls via the configuration callbacks.  Please use the protected parameterless constructor instead");
            }

            (config ?? DefaultConfig).Configure(this);
        }
 private static ITargetContainer CreateTargets(ITargetContainerConfig configOverride = null)
 {
     return(new TargetContainer(configOverride ?? Configuration.InjectEnumerables.Instance));
 }
예제 #4
0
 /// <summary>
 /// Creates the target container for the test.
 /// </summary>
 /// <param name="configOverride">An explicit <see cref="ITargetContainerConfig"/> to use to configure the
 /// <see cref="ITargetContainer"/>.  If not provided, then the config returned by <see cref="GetDefaultTargetContainerConfig(string)"/>
 /// is used, which is always a clone of the <see cref="TargetContainer.DefaultConfig"/>.</param>
 /// <param name="testName">Name of the test.</param>
 protected virtual IRootTargetContainer CreateTargetContainer(ITargetContainerConfig configOverride = null, [CallerMemberName] string testName = null)
 {
     return(new TargetContainer(configOverride ?? GetDefaultTargetContainerConfig(testName)));
 }