Ejemplo n.º 1
0
 public ODataModelTypeCreator()
 {
     _valueToken = new Token(new CharactorSet().Append('a', 'z').Append('A', 'Z').Append('0', '9').ToString());
     _zeroNullProbability = new CreatorSettings() { NullValueProbability = 0.0 };
 }
Ejemplo n.º 2
0
        private object GenerateClientStructureRandomData(Type clientType, Type serverType, Random rndGen, int? depth = null)
        {
            if (depth == null)
            {
                depth = 0;
            }
            else if (depth > 2)
            {
                return null;
            }

            depth++;

            var clientProps = clientType.GetProperties();
            var serverProps = serverType.GetProperties();
            if (clientProps.Length != serverProps.Length)
            {
                throw new InvalidOperationException("Client properties length must be same as server type");
            }

            object result = Activator.CreateInstance(clientType);
            for (int i = 0; i < clientProps.Length; i++)
            {
                if (clientProps[i].Name == "ID" && clientProps[i].PropertyType == typeof(string))
                {
                    var id = new Token(new CharsToUseBuilder().Append('a', 'z').Append('A', 'Z').Append('0', '9').ToString()).Generate(rndGen, new CreatorSettings() 
                    { 
                        NullValueProbability = 0.0 
                    });
                    clientProps[i].SetValue(result, id, null);
                    continue;
                }

                object value;
                if (GenerateClientRandomData(clientProps[i].PropertyType, serverProps[i].PropertyType, rndGen, out value, depth))
                {
                    clientProps[i].SetValue(result, value, null);
                }
            }

            return result;
        }