AgainstArgumentNull() public static method

Throws an ArgumentNullException in case the argument specified via argument is null.
public static AgainstArgumentNull ( object argument, string argumentName ) : void
argument object Specifies the argument
argumentName string Specifies the arguments name.
return void
Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="Fabric"/> class.
        /// </summary>
        /// <param name="mockingEngine">The mock factory.</param>
        /// <param name="builders">A collection of all known builders.</param>
        /// <param name="configurationRules">A set of rules for configuration of the produced instances.</param>
        public Fabric(IMockingEngine mockingEngine, IEnumerable <IBuilder> builders, IEnumerable <IConfigurationRule> configurationRules)
        {
            Guard.AgainstArgumentNull(mockingEngine, "mockingEngine");
            Guard.AgainstArgumentNull(builders, "builders");
            Guard.AgainstArgumentNull(configurationRules, "configurationRules");

            _mockingEngine      = mockingEngine;
            _builders           = builders;
            _configurationRules = configurationRules;
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new instance of the <see cref="FabricContext"/> class.
        /// </summary>
        /// <param name="typeToBuild">
        /// Specifies the type to build.
        /// </param>
        /// <param name="mockingEngine">
        /// Specifies the mock factory.
        /// </param>
        /// <param name="container">
        /// Specifies the container.
        /// </param>
        /// <param name="fabric">
        /// Specifies the fabric.
        /// </param>
        public FabricContext(Type typeToBuild, IMockingEngine mockingEngine, IContainer container, Fabric fabric)
        {
            Guard.AgainstArgumentNull(typeToBuild, "typeToBuild");
            Guard.AgainstArgumentNull(mockingEngine, "mockingEngine");
            Guard.AgainstArgumentNull(container, "container");

            TypeToBuild    = typeToBuild;
            _mockingEngine = mockingEngine;
            _container     = container;
            _fabric        = fabric;
        }
Beispiel #3
0
        /// <summary>
        /// Executes the action specified by <paramref name="action"/> on each element of the specified
        /// collection.
        /// </summary>
        /// <typeparam name="T">
        /// Specifies the collections item type.
        /// </typeparam>
        /// <param name="enumerable">
        /// Specifies the collection.
        /// </param>
        /// <param name="action">
        /// Specifies the operation to perform on each element.
        /// </param>
        public static void Each <T>(this IEnumerable <T> enumerable, Action <T> action)
        {
            Guard.AgainstArgumentNull(action, "action");

            if (enumerable != null)
            {
                foreach (var item in enumerable)
                {
                    action(item);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Builds a dependency.
        /// </summary>
        /// <param name="typeToBuild">
        /// Specifies the type to be build.
        /// </param>
        /// <param name="container">
        /// Specifies the automocking container.
        /// </param>
        /// <returns>
        /// The created instance.
        /// </returns>
        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);
        }
        /// <summary>
        /// Creates a stub.
        /// </summary>
        /// <typeparam name="T">
        /// Specifies the type of the stub. This needs to be an interface.
        /// </typeparam>
        /// <returns>
        /// The created stub instance.
        /// </returns>
        public static T Stub <T>(this IMockingEngine mockingEngine) where T : class
        {
            Guard.AgainstArgumentNull(mockingEngine, "mockingEngine");

            return((T)mockingEngine.Stub(typeof(T)));
        }
        /// <summary>
        /// Creates list filled with 3 stubs of the type specified via <typeparamref name="TInterfaceType"/>.
        /// </summary>
        /// <typeparam name="TInterfaceType">
        /// Specifies the interface type.
        /// </typeparam>
        /// <param name="mockingEngine">
        /// Specifies the factory for creating stub implementations on-the-fly.
        /// </param>
        /// <returns>
        /// A collection containing three stubs of the specified type.
        /// </returns>
        public static IList <TInterfaceType> CreateStubCollectionOf <TInterfaceType>(this IMockingEngine mockingEngine) where TInterfaceType : class
        {
            Guard.AgainstArgumentNull(mockingEngine, "mockingEngine");

            return(Enumerable.Range(0, 3).Select(x => mockingEngine.Stub <TInterfaceType>()).ToList());
        }