/// <inheritdoc/> public Fake <T> Mock <T>(params Type[] interfaces) { IFaked provider = Subclasser.Create(typeof(T), interfaces); provider.FakeMeta.Valuer = _valuer; return(new Fake <T>(provider)); }
/// <inheritdoc/> public Fake Mock(Type parent, params Type[] interfaces) { IFaked provider = Subclasser.Create(parent, interfaces); provider.FakeMeta.Valuer = _valuer; return(new Fake(provider)); }
/// <summary>Creates a new instance of <paramref name="type"/>.</summary> /// <param name="type">Type to generate.</param> /// <param name="randomizer">Handles callback behavior for child values.</param> /// <param name="smartData">Predefined random data.</param> /// <returns>The created instance.</returns> private static object CreateNew(Type type, RandomizerChainer randomizer, DataRandom smartData) { /* * Order of preference: * 1) Default constructor. * 2) Public constructor. * 3) Public factory. * 4) Internal factory. * 5) Internal constructor. * 6) Stub. */ ConstructorInfo defaultConstructor = type.GetConstructor(Type.EmptyTypes); if (type == typeof(object)) { IFaked fake = randomizer.Stub <IFaked>().Dummy; fake.FakeMeta.Identifier = randomizer.Create <int>(); return(fake); } else if (defaultConstructor != null) { return(defaultConstructor.Invoke(null)); } else if (FindConstructors(type, BindingFlags.Public, randomizer).Any()) { return(CreateFrom(randomizer, smartData, (c, d) => c.Invoke(d), FindConstructors(type, BindingFlags.Public, randomizer))); } else if (FindFactories(type, BindingFlags.Public, randomizer).Any()) { return(CreateFrom(randomizer, smartData, (c, d) => c.Invoke(null, d), FindFactories(type, BindingFlags.Public, randomizer))); } else if (FindFactories(type, BindingFlags.NonPublic, randomizer).Any()) { return(CreateFrom(randomizer, smartData, (c, d) => c.Invoke(null, d), FindFactories(type, BindingFlags.NonPublic, randomizer))); } else if (FindConstructors(type, BindingFlags.NonPublic, randomizer).Any()) { return(CreateFrom(randomizer, smartData, (c, d) => c.Invoke(d), FindConstructors(type, BindingFlags.NonPublic, randomizer))); } else if (!type.IsSealed) { return(randomizer.Stub(type).Dummy); } else { return(null); } }
/// <summary>Initializes a new instance of the <see cref="Fake{T}"/> class.</summary> /// <param name="fake">Faked implementation.</param> public Fake(IFaked fake) : base(fake) { }