예제 #1
0
        private IDictionary <Type, Func <object> > InitializeMappings()
        {
            var mappings = new Dictionary <Type, Func <object> >
            {
                { typeof(string), () => DataGenerator.GenerateString() },
                { typeof(Uri), () => DataGenerator.GenerateUri() },
                { typeof(Int32), () => DataGenerator.GenerateInteger() },
                { typeof(int?), () => DataGenerator.GenerateBoolean()
                                             ? DataGenerator.GenerateInteger()
                                             : (object)null },
                { typeof(long), () => DataGenerator.GenerateLong() },
                { typeof(long?), () => DataGenerator.GenerateBoolean()
                        ? DataGenerator.GenerateLong()
                        : (object)null },
                { typeof(double), () => DataGenerator.GenerateDouble() },
                { typeof(double?), () => DataGenerator.GenerateBoolean()
                        ? DataGenerator.GenerateDouble()
                        : (object)null },
                { typeof(float), () => DataGenerator.GenerateFloat() },
                { typeof(float?), () => DataGenerator.GenerateBoolean()
                        ? DataGenerator.GenerateFloat()
                        : (object)null },
                { typeof(DateTime), () => DataGenerator.GenerateDateTime() },
                { typeof(DateTime?), () => DataGenerator.GenerateBoolean()
                        ? DataGenerator.GenerateDateTime()
                        : (object)null },
                { typeof(Guid), () => Guid.NewGuid() }
            };

            return(mappings);
        }
예제 #2
0
        public IEnumerable <object> InitializeParameters(IList <ParameterInfo> parameters)
        {
            var instances = new List <object>();

            for (var index = 0; index < parameters.Count; index++)
            {
                if (index == _nullIndex)
                {
                    instances.Add(null);
                }
                else
                {
                    var type = parameters[index].ParameterType;

                    if (type == typeof(string))
                    {
                        instances.Add(_dataGenerator.GenerateString());
                    }
                    else
                    {
                        var mockType = typeof(Mock <>).MakeGenericType(parameters[index].ParameterType);

                        var mock = Convert.ChangeType(Activator.CreateInstance(mockType,
                                                                               null), mockType);

                        instances.Add(GetObjectFromMock(mock, parameters[index].ParameterType));
                    }
                }
            }

            return(instances);
        }
예제 #3
0
        public void AddInstance(IList <ParameterInfo> parameters, IList <Object> instances, int index)
        {
            var type = parameters[index].ParameterType;

            if (type == typeof(string))
            {
                instances.Add(_dataGenerator.GenerateString());
            }
            else
            {
                var mockType = typeof(Mock <>).MakeGenericType(parameters[index].ParameterType);

                var mock = Convert.ChangeType(Activator.CreateInstance(mockType,
                                                                       null), mockType);

                instances.Add(GetObjectFromMock(mock, parameters[index].ParameterType));
            }
        }