public T Create()
        {
            var   genericMethodInvoker = new GenericMethodInvokerUtil();
            Array array = Activator.CreateInstance(typeof(T), new object[] { RandomUtil.Instance.Next(1, 100) }) as Array;

            for (int i = 0; i < array.Length; i++)
            {
                Type arrayElementType = typeof(T).GetElementType();
                array.SetValue(genericMethodInvoker.InvokeMockObject <T>(arrayElementType), i);
            }

            return((T)Convert.ChangeType(array, typeof(T)));
        }
        public T Create()
        {
            GenericMethodInvokerUtil methodInvoker = new GenericMethodInvokerUtil();
            IDictionary dictionary       = (IDictionary)Activator.CreateInstance(typeof(T));
            int         numberOfElements = RandomUtil.Instance.Next(1, 100);

            Type[] arguments = dictionary.GetType().GetGenericArguments();
            Type   keyType   = arguments[0];
            Type   valueType = arguments[1];

            for (int i = 0; i < numberOfElements; i++)
            {
                object key   = methodInvoker.InvokeMockObject <object>(keyType);
                object value = methodInvoker.InvokeMockObject <object>(valueType);

                if (!dictionary.Contains(key))
                {
                    dictionary.Add(key, value);
                }
            }

            return((T)dictionary);
        }
        public T Create()
        {
            GenericMethodInvokerUtil methodInvoker = new GenericMethodInvokerUtil();
            IList list = (IList)Activator.CreateInstance(typeof(T));

            int  numberOfElements = RandomUtil.Instance.Next(1, 100);
            Type valueType        = list.GetType().GetGenericArguments()[0];

            for (int i = 0; i < numberOfElements; i++)
            {
                object value = methodInvoker.InvokeMockObject <object>(valueType);
                list.Add(value);
            }

            return((T)list);
        }
Exemple #4
0
        public T Create()
        {
            T mockObject = (T)Activator.CreateInstance(typeof(T));
            IEnumerable <PropertyInfo> properties = typeof(T).GetProperties().Where(p => p.CanWrite);

            GenericMethodInvokerUtil method = new GenericMethodInvokerUtil();

            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType == typeof(T))
                {
                    throw new Exception("Circular properties are not supported!");
                }

                method.InvokeMockObject <T>(property.PropertyType, property, mockObject);
            }

            return(mockObject);
        }