public void CreateDynamic_WithTypes() { var paramList = ParamList.CreateDynamic(new Type[] { typeof(int) }, new object[] { 1 }); Assert.That(paramList.GetParameterTypes(), Is.EqualTo(new[] { typeof(int) })); Assert.That(paramList.GetParameterValues(), Is.EqualTo(new object[] { 1 })); }
/// <summary> /// Creates an instance of the type returned by <see cref="GetConcreteMixedType"/> for the given <paramref name="type"/>. /// </summary> /// <param name="type">The type for whose concrete type to create an instance.</param> /// <param name="args">The arguments to be passed to the constructor.</param> /// <returns>An instance of the type returned by <see cref="GetConcreteMixedType"/> for <paramref name="type"/> created via a constructor taking the /// specified <paramref name="args"/>.</returns> /// <remarks> /// This is just a wrapper around /// <see cref="ObjectFactory.Create(bool,System.Type,Remotion.TypePipe.ParamList,object[])"/> /// with a Reflection-like interface. /// </remarks> public static object CreateInstance(Type type, params object[] args) { ArgumentUtility.CheckNotNull("type", type); ArgumentUtility.CheckNotNull("args", args); return(ObjectFactory.Create(false, type, ParamList.CreateDynamic(args))); }
public void Create_Arbitrary_WithoutTypes_AndNulls() { var paramList = ParamList.CreateDynamic(1, 2, 3, 4, null, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28); Assert.That(paramList.GetParameterTypes(), Is.EqualTo(new[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(object), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) })); Assert.That(paramList.GetParameterValues(), Is.EqualTo(new object[] { 1, 2, 3, 4, null, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 })); }
/// <summary> /// Creates a mixin with a mocked target object. /// </summary> /// <typeparam name="TMixin">The type of mixin to create.</typeparam> /// <typeparam name="TTarget">The TTarget parameter of the mixin.</typeparam> /// <param name="targetMock">The mock object to use for the mixin's <see cref="Mixin{TTarget}.Target"/> property.</param> /// <param name="args">The constructor arguments to be used when instantiating the mixin.</param> /// <returns>A mixin instance with the given mock objects as its <see cref="Mixin{TTarget}.Target"/> and <see cref="Mixin{TTarget,TNext}.Next"/> /// parameters.</returns> /// <remarks> /// <para> /// This method indirectly invokes the <see cref="Mixin{TTarget}.OnInitialized"/> method. /// </para> /// <para> /// This method cannot mock mixins with abstract methods, but it can mock subclasses of those mixins if they implement the abstract methods. If /// you already have a mixin instance to be mocked, use the <see cref="MockMixinTarget{TTarget,TNext}"/> method instead. /// </para> /// </remarks> public static TMixin CreateMixinWithMockedTarget <TMixin, TTarget> (TTarget targetMock, params object[] args) where TTarget : class where TMixin : Mixin <TTarget> { ArgumentUtility.CheckNotNull("targetMock", targetMock); ArgumentUtility.CheckNotNull("args", args); var mixin = ObjectFactory.Create <TMixin> (true, ParamList.CreateDynamic(args)); MockMixinTarget(mixin, targetMock); return(mixin); }
public static DomainObjectWithSpecialConstructor NewObject(object o) { return(NewObject <DomainObjectWithSpecialConstructor> (ParamList.CreateDynamic(o))); }