namespace FakeItEasy.Sdk { using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using FakeItEasy.Creation; /// /// Provides methods for generating fake objects. /// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "A", Justification = "Is spelled correctly.")] public static class Create { private static IFakeCreatorFacade FakeCreator { get { return ServiceLocator.Current.Resolve(); } } /// /// Creates a fake object of the specified type. /// /// The type of fake object to create. /// A fake object. public static object Fake(Type typeOfFake) { return FakeCreator.CreateFake(typeOfFake, x => { }); } /// /// Creates a fake object of the specified type. /// /// The type of fake object to create. /// A lambda where options for the built fake object can be specified. /// A fake object. public static object Fake(Type typeOfFake, Action optionsBuilder) { return FakeCreator.CreateFake(typeOfFake, optionsBuilder); } /// /// Creates a collection of fakes of the specified type. /// /// The type of fakes to create. /// The number of fakes in the collection. /// A collection of fake objects of the specified type. public static IList CollectionOfFake(Type typeOfFake, int numberOfFakes) { return Enumerable.Range(0, numberOfFakes).Select(_ => Fake(typeOfFake)).ToList(); } /// /// Creates a collection of fakes of the specified type. /// /// The type of fakes to create. /// The number of fakes in the collection. /// A lambda where options for the built fake object can be specified. /// A collection of fake objects of the specified type. public static IList CollectionOfFake(Type typeOfFake, int numberOfFakes, Action optionsBuilder) { return Enumerable.Range(0, numberOfFakes).Select(_ => Fake(typeOfFake, optionsBuilder)).ToList(); } /// /// Gets a dummy object of the specified type. The value of a dummy object /// should be irrelevant. Dummy objects should not be configured. /// /// The type of dummy to return. /// A dummy object of the specified type. /// Dummies of the specified type can not be created. [EditorBrowsable(EditorBrowsableState.Advanced)] public static object Dummy(Type typeOfDummy) { return FakeCreator.CreateDummy(typeOfDummy); } /// /// Creates a collection of dummies of the specified type. /// /// The type of dummy to return. /// The number of dummies in the collection. /// A collection of dummy objects of the specified type. /// Dummies of the specified type can not be created. [EditorBrowsable(EditorBrowsableState.Advanced)] public static IList CollectionOfDummy(Type typeOfDummy, int numberOfDummies) { return Enumerable.Range(0, numberOfDummies).Select(_ => Dummy(typeOfDummy)).ToList(); } } }