Skip to content
RandomPOCOGenerator is a simple reflection-based .NET library designed for generating and populating objects with random values
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Build/Net45 Build Net45 May 11, 2017
RandomPOCOGeneratorTest Add project files. May 10, 2017
RandomPocoGenerator Add project files. May 10, 2017
.gitattributes
.gitignore Add .gitignore and .gitattributes. May 10, 2017
License.txt Add project files. May 10, 2017
README.md Update README.md May 18, 2017
RandomPOCOGenerator.sln Add readme to solution May 11, 2017

README.md

RandomPOCOGenerator

RandomPOCOGenerator is a simple reflection-based tool designed for generating and populating objects with random values

Features/Purpose

  • performance tuning with large amounts of data
  • generating test data for use when developing or testing an application
  • built-in RandomValueGenerator allows you to set the range of values and collections
  • allows to set recursion level for complex types
  • Extensibility: allows creation of custom implementation of IValueGenerator for generating primitive values and strings

Supported types:

  • classes and generic classes with parameterless constructor, structs
  • assigning values to private and public properties(fields are not supported) to reference types and structs
  • collection types that implements IDictionary, IList, ArrayList, Array[]
  • primitive types, enums, strings, nullable types

Using RandomPOCOGenerator

        [TestMethod]
        public void GenericGenerateTest()
        {
            RPGenerator gen = new RPGenerator();
            int maxRecursionLevel = 4;
            
            var stringArrayRes = gen.Generate<string[]>(maxRecursionLevel);
            var charArrayRes = gen.Generate<char[]>(maxRecursionLevel);
            var pocoRes = gen.Generate<SamplePocoClass>(maxRecursionLevel);
            var structRes = gen.Generate<SampleStruct>(maxRecursionLevel);
            var intRes = gen.Generate<int>(maxRecursionLevel);
            var arrayListRes = gen.Generate<ArrayList>(maxRecursionLevel);
            var pocoArray = gen.Generate<SamplePocoClass[]>(maxRecursionLevel);
            var listRes = gen.Generate<List<SamplePocoClass>>(maxRecursionLevel);
            var dictRes = gen.Generate<Dictionary<string, List<List<SamplePocoClass>>>>(maxRecursionLevel);
            var parameterlessList = gen.Generate<List<Tuple<string, int>>>(maxRecursionLevel);

            // No parameterless constructor defined 
            var typpleRes = gen.Generate<Tuple<int, int>>(maxRecursionLevel);

            Trace.WriteLine("-------------- GenericGenerateTest Results ------------------------");
            Trace.WriteLine(string.Format("CountOfGeneratedValues       {0}", gen.CountOfGeneratedValues));
            Trace.WriteLine(string.Format("CountOfGeneratedCollections  {0}", gen.CountOfGeneratedCollections));
            Trace.WriteLine(string.Format("CountOfGeneratedObjects      {0}", gen.CountOfGeneratedObjects));
            Trace.WriteLine(string.Format("TotalCountOfGeneratedObjects {0}", gen.TotalCountOfGeneratedObjects));
            Trace.WriteLine(string.Format("Generating errors            {0}", gen.Errors.Count));
        }        
        [TestMethod]
        public void NonGenericGenerateTest()
        {
            RPGenerator gen = new RPGenerator();
            int maxRecursionLevel = 4;
            
            var stringArrayRes = gen.Generate(typeof(string[]), maxRecursionLevel);
            var pocoRes = gen.Generate(typeof(SamplePocoClass), maxRecursionLevel);
            var structRes = gen.Generate(typeof(SampleStruct), maxRecursionLevel);


            Trace.WriteLine("-------------- NonGenericGenerateTest Results ------------------------");
            Trace.WriteLine(string.Format("TotalCountOfGeneratedObjects {0}", gen.TotalCountOfGeneratedObjects));
            Trace.WriteLine(string.Format("Generating errors            {0}", gen.Errors.Count));
        }
        [TestMethod]
        public void GeneratePositiveNumbersTest()
        {
            RPGenerator gen = new RPGenerator(new RandomValueGenerator(0, 100, 1, 20, false));
            int maxRecursionLevel = 4;
            
            var sbyteValues = gen.Generate<sbyte[]>(maxRecursionLevel);
            var shortValues = gen.Generate<short[]>(maxRecursionLevel);
            var intResult = gen.Generate<int[]>(maxRecursionLevel);
            var floatValues = gen.Generate<float[]>(maxRecursionLevel);
            var doubleValues = gen.Generate<double[]>(maxRecursionLevel);
            var decimalValues = gen.Generate<Decimal[]>(maxRecursionLevel);

            Trace.WriteLine("-------------- GeneratePositiveNumbersTest Results ------------------------");
            Trace.WriteLine(string.Format("TotalCountOfGeneratedObjects {0}", gen.TotalCountOfGeneratedObjects));
            Trace.WriteLine(string.Format("Generating errors            {0}", gen.Errors.Count));
        }
        [TestMethod]
        public void GenerateLargeCollectionTest()
        {
            RPGenerator gen = new RPGenerator(new RandomValueGenerator(-1000, 1000, 100000, 100000, false));
            int maxRecursionLevel = 4;
            
            var structRes = gen.Generate<List<SampleStruct>>(maxRecursionLevel);

            Trace.WriteLine("-------------- GenerateLargeCollectionTest Results ------------------------");
            Trace.WriteLine(string.Format("TotalCountOfGeneratedObjects {0}", gen.TotalCountOfGeneratedObjects));
            Trace.WriteLine(string.Format("Generating errors            {0}", gen.Errors.Count));
        }        
You can’t perform that action at this time.