Exemplo n.º 1
0
        public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random)
        {
            var constructor = random.Choice(type.GetConstructors());

            var arguments = constructor.GetParameters()
                            .Select(p => profile.Generate(p.ParameterType, random));

            return(constructor.Invoke(arguments.ToArray()));
        }
Exemplo n.º 2
0
        public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random)
        {
            // Only find direct subclasses. Indirect subclasses can be found recursively
            var candidateClasses = DirectSubclassesOf(type)
                                   .ToList();

            var generatedType = random.Choice(candidateClasses);

            return(profile.Generate(generatedType, random));
        }
Exemplo n.º 3
0
        public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random)
        {
            var constructor = type.GetConstructor(Array.Empty <Type>()) !;
            var instance    = constructor.Invoke(Array.Empty <object?>());

            foreach (var property in type.GetDataProperties())
            {
                if (!property.CanWrite)
                {
                    continue;
                }

                var value = profile.Generate(property.PropertyType, random);
                property.SetValue(instance, value);
            }

            return(instance);
        }