public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { int count = 4; Type key = context.RequestType.GetGenericArguments()[0]; Type value = context.RequestType.GetGenericArguments()[1]; // If dictionary key is an enum with unique number of items less than the available count, use that number for the dictionary generation instead. if (key.GetTypeInfo().IsEnum) { int max = Enum.GetNames(context.RequestType.GetGenericArguments()[0]).Length; count = max < count ? max : count; } var keys = UniqueKeys(count, key, pipeline, new HashSet <object>()).ToList(); var values = Values(count, value, pipeline).ToList(); var dictionary = (IDictionary)Activator.CreateInstance(typeof(Dictionary <,>).MakeGenericType(key, value)); for (var i = 0; i <= count - 1; i++) { dictionary.Add(keys[i], values[i]); } return(dictionary); }
public override char Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var chars = "$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&"; var num = _random.Next(0, chars.Length); return(chars[num]); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var userName = Guid.NewGuid().ToString("N"); var domain = domains[random.Next(domains.Count - 1)]; return(userName + domain); }
private IEnumerable <object> Values(int count, Type closedType, ConstruktionPipeline pipeline) { for (var i = 0; i < count; i++) { yield return(pipeline.Construct(new ConstruktionContext(closedType))); } }
public override DateTime Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var start = DateTime.Today.AddYears(-2); var range = (DateTime.Today - start).Days; return(start.AddDays(_random.Next(range))); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var inject = new Foo(); pipeline.Inject(context.RequestType, inject); return(inject); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var closedType = context.RequestType.GenericTypeArguments[0]; var results = construct(closedType, pipeline); return(results); }
/// <summary> /// Construct a parameter using its attribute's value. /// </summary> /// <param name="context"></param> /// <param name="pipeline"></param> /// <returns></returns> public virtual object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var attribute = (T)context.ParameterInfo.GetCustomAttribute(typeof(T)); var value = _value(attribute); return(value); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var arrayType = context.RequestType.GetElementType(); var results = construct(arrayType, pipeline); return(results); }
public override string Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var prefix = context.PropertyInfo.IsNulloPropertyInfo() ? "String" : context.PropertyInfo.Name; var result = prefix + "-" + _random.Next(1, 10000); return(result); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var implementation = _typeMap[context.RequestType]; var result = pipeline.Send(new ConstruktionContext(implementation)); return(result); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var items = pipeline.Settings.EnumerableCount; var key = context.RequestType.GetGenericArguments()[0]; var valueType = context.RequestType.GetGenericArguments()[1]; if (key.GetTypeInfo().IsEnum) { items = Enum.GetNames(key).Length; } var keys = uniqueKeys(); var values = itemValues(valueType); var dictionary = (IDictionary)typeof(Dictionary <,>).NewGeneric(key, valueType); for (var i = 0; i <= items - 1; i++) { dictionary.Add(keys[i], values[i]); } return(dictionary); List <object> uniqueKeys() { var builtKeys = new HashSet <object>(); while (true) { var newItem = pipeline.Send(new ConstruktionContext(key)); if (newItem != null) { builtKeys.Add(newItem); } if (builtKeys.Count == items) { return(builtKeys.ToList()); } } } List <object> itemValues(Type closedType) { var results = new List <object>(); for (var i = 0; i < items; i++) { results.Add(pipeline.Send(new ConstruktionContext(closedType))); } return(results); } }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var closedType = context.RequestType.GetGenericArguments()[0]; var useNull = _random.Next(1, 5); return(useNull == 1 ? null : pipeline.Send(new ConstruktionContext(closedType))); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var implementation = _typeMap.ContainsKey(context.RequestType) ? _typeMap[context.RequestType] : context.RequestType; var ctor = BuildCtor(implementation, pipeline); var instance = construct(ctor, pipeline); return(instance); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var method = typeof(A) .GetMethod("Fake", Type.EmptyTypes) .MakeGenericMethod(context.ParameterInfo.ParameterType); var fake = method.Invoke(null, null); pipeline.Inject(context.RequestType, fake); return(fake); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { if (context.RequestType.GetTypeInfo().IsInterface) { throw new Exception($"Cannot construct the interface {context.RequestType.Name}. " + "You must register it or add a custom blueprint."); } throw new Exception($"No Blueprint could be found for {context.RequestType.FullName}. Please add " + $"a custom blueprint that can create it."); }
private HashSet <object> UniqueKeys(int count, Type key, ConstruktionPipeline pipeline, HashSet <object> items) { var newItem = pipeline.Construct(new ConstruktionContext(key)); if (newItem != null) { items.Add(newItem); } return(items.Count == count ? items : UniqueKeys(count, key, pipeline, items)); }
private IList construct(Type closedType, ConstruktionPipeline pipeline) { var count = 3; var items = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(closedType)); for (var i = 0; i < count; i++) { var result = pipeline.Construct(new ConstruktionContext(closedType)); items.Add(result); } return(items); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var closedType = context.RequestType.GenericTypeArguments[0]; var items = (IList)typeof(List <>).NewGeneric(closedType); for (var i = 0; i < pipeline.Settings.EnumerableCount; i++) { var result = pipeline.Send(new ConstruktionContext(closedType)); items.Add(result); } return(items); }
private Array construct(Type arrayType, ConstruktionPipeline pipeline) { var count = 3; var array = Array.CreateInstance(arrayType, count); for (var i = 0; i <= count - 1; i++) { var value = pipeline.Construct(new ConstruktionContext(arrayType)); array.SetValue(value, i); } return(array); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var arrayType = context.RequestType.GetElementType(); var array = Array.CreateInstance(arrayType, pipeline.Settings.EnumerableCount); for (var i = 0; i <= pipeline.Settings.EnumerableCount - 1; i++) { var value = pipeline.Send(new ConstruktionContext(arrayType)); array.SetValue(value, i); } return(array); }
private object construct(Func <object> ctor, ConstruktionPipeline pipeline) { var instance = ctor(); var properties = instance.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(x => x.CanWrite); foreach (var property in properties) { var result = pipeline.Construct(new ConstruktionContext(property)); property.SetValue(instance, result); } return(instance); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var instance = Activator.CreateInstance(context.RequestType); var properties = context.RequestType .GetTypeInfo() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(x => x.CanWrite); foreach (var property in properties) { var result = pipeline.Construct(new ConstruktionContext(property)); property.SetValue(instance, result); } return(instance); }
private Func <object> BuildCtor(Type type, ConstruktionPipeline pipeline) { var ctors = type.GetTypeInfo() .DeclaredConstructors .ToList(); var ctor = _ctorStrategy(ctors); var @params = new List <ConstantExpression>(); foreach (var parameter in ctor.GetParameters()) { var ctorArg = parameter.ParameterType; var value = pipeline.Construct(new ConstruktionContext(ctorArg)); @params.Add(Expression.Constant(value)); } return(Expression.Lambda <Func <object> >(Expression.New(ctor, @params)).Compile()); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var instance = newUp(); var properties = pipeline.Settings.PropertyStrategy(context.RequestType); foreach (var property in properties) { var result = pipeline.Send(new ConstruktionContext(property)); property.SetPropertyValue(instance, result); } return(instance); object newUp() { var ctors = context.RequestType.GetTypeInfo() .DeclaredConstructors .ToList(); var ctor = pipeline.Settings.CtorStrategy(ctors); var @params = new List <object>(); foreach (var parameter in ctor.GetParameters()) { var ctorArg = parameter.ParameterType; var value = pipeline.Send(new ConstruktionContext(ctorArg)); @params.Add(value); } return(context.RequestType.NewUp(@params.ToArray())); } }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { return("StringB"); }
public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { var result = context.PropertyContext.Name + "-" + _random.Next(1, 10000); return(result); }
/// <summary> /// Construct an object of T. /// </summary> /// <param name="context"></param> /// <param name="pipeline"></param> /// <returns></returns> public abstract T Construct(ConstruktionContext context, ConstruktionPipeline pipeline);
/// <inheritdoc /> object Blueprint.Construct(ConstruktionContext context, ConstruktionPipeline pipeline) => Construct(context, pipeline);
public override object Construct(ConstruktionContext context, ConstruktionPipeline pipeline) { return(GetAttribute(context).Value); }