Xunit.Internal.Fabric.Build C# (CSharp) Method

Build() public method

Builds a dependency.
public Build ( Type typeToBuild, IContainer container ) : object
typeToBuild System.Type /// Specifies the type to be build. ///
container IContainer /// Specifies the automocking container. ///
return object
        public object Build(Type typeToBuild, IContainer container)
        {
            Guard.AgainstArgumentNull(typeToBuild, "typeToBuild");
            Guard.AgainstArgumentNull(container, "container");

            var buildContext = new FabricContext(typeToBuild, _mockingEngine, container, this);

            var responsibleBuilder = _builders.FirstOrDefault(x => x.KnowsHowToBuild(buildContext.TypeToBuild));

            if (responsibleBuilder == null)
            {
                throw new InvalidOperationException(
                    string.Format("Unable to build ctor dependency of type {0}." + Environment.NewLine +
                                 "Make sure to use only interfaces or abstract base classes in the constructor!", typeToBuild.FullName));
            }

            var stub = responsibleBuilder.BuildFrom(buildContext);

            Guard.AgainstArgumentNull(stub, "stub");

            _configurationRules.Each(x => x.Configure(stub, buildContext));

            return stub;
        }

Usage Example

Esempio n. 1
0
 /// <summary>
 /// Resolves the type specified by <paramref name="type"/>
 /// with the root level fabric.
 /// </summary>
 /// <param name="type">
 /// Specifies the type to resolve.
 /// </param>
 /// <returns>
 /// The resolved instance.
 /// </returns>
 public object ResolveByFabric(Type type)
 {
     return(_fabric.Build(type, _container));
 }