Esempio n. 1
0
        protected Context TestDataGeneratorContext(int recursionDepth = 2, bool catchExceptions = false)
        {
            Arrangement <Dummy, Dummy, Dummy, Dummy> withExceptions = x =>
            {
                try
                {
                    TestDataGenerator = TestDataGeneratorFactory.Create(TestDataDomainConfiguration);
                }
                catch (Exception e)
                {
                    CreationException = e;
                    TestDataGenerator = null;
                }
            };

            Arrangement <Dummy, Dummy, Dummy, Dummy> withoutException = x =>
                                                                        TestDataGenerator = TestDataGeneratorFactory.Create(TestDataDomainConfiguration);

            ;

            return
                (c =>
                 c.Given("using MaxRecursionDepth of " + recursionDepth, x => MaxRecursionDepth = recursionDepth)
                 .Given("create test data generator", catchExceptions ? withExceptions : withoutException));
        }
Esempio n. 2
0
 Context BaseContext(int seed)
 {
     return
         (c => c
          .Given("Empty domain with attribute based value provider", x =>
                 TestDataDomainConfiguration = (context => context
                                                .UseDefaults(false)
                                                .UseRandom(new DefaultRandom(seed))
                                                .For <ClassWithMultipleAttributes>().AddProvider(new DefaultInstanceValueProvider <ClassWithMultipleAttributes>())
                                                .For <ClassWithMultipleAttributes>().Select(cwma => cwma.Country).AddProvider(new CountryCityProvider())))
          .Given("TestDataGenerator", x => TestDataGenerator = TestDataGeneratorFactory.Create(TestDataDomainConfiguration)));
 }
Esempio n. 3
0
 Context BaseContext(int seed)
 {
     return
         (c => c
          .Given("Empty domain with date range value provider", x =>
                 TestDataDomainConfiguration = (context => context
                                                .UseDefaults(false)
                                                .UseRandom(new DefaultRandom(seed))
                                                .For <ClassWithDateRange>().AddProvider(new DefaultInstanceValueProvider <ClassWithDateRange>())
                                                .For <ClassWithDateRange>().Select(cwdr => cwdr.BirthDate).AddProvider(new DateGenerator())))
          .Given("TestDataGenerator", x => TestDataGenerator = TestDataGeneratorFactory.Create(TestDataDomainConfiguration)));
 }
 Context BaseContext()
 {
     return
         (c => c
          .Given("{0,2,1}", x => InputList = new List <int> {
         0, 2, 1
     })
          .Given("Empty domain with value provider", x =>
                 TestDataDomainConfiguration = (context => context
                                                .UseDefaults(false)
                                                .UseRandom(Random)
                                                .For <string> ().AddProvider(new ChooseSingleItemValueProvider <int, string> (InputList, item => item.ToString()))))
          .Given("TestDataGenerator", x => TestDataGenerator = TestDataGeneratorFactory.Create(TestDataDomainConfiguration)));
 }
Esempio n. 5
0
        /// <summary>
        /// Creates an evolutionary data generator for the given domain
        /// </summary>
        /// <param name="testDataDomainConfiguration">the domain, containing all relevant imformation for the test data generation</param>
        /// <param name="evolutionaryDomainConfiguration">the domain, containing all relevant information for the evolutionary generation</param>
        /// <returns>the final test data generator that can be used for data generation</returns>
        public static RuleBasedDataGenerator Create(TestDataDomainConfiguration testDataDomainConfiguration, [CanBeNull] EvolutionaryDomainConfiguration evolutionaryDomainConfiguration)
        {
            var testDataGenerator = TestDataGeneratorFactory.Create(testDataDomainConfiguration);

            var evolutionaryDomainConfigurator = new RuleBasedDataGeneratorConfigurator();

            if (evolutionaryDomainConfiguration != null)
            {
                evolutionaryDomainConfigurator = (RuleBasedDataGeneratorConfigurator)evolutionaryDomainConfiguration(evolutionaryDomainConfigurator);
            }

            var ruleSet = evolutionaryDomainConfigurator.Build();

            return(new RuleBasedDataGenerator(testDataGenerator, ruleSet));
        }
Esempio n. 6
0
        private static void Main()
        {
            const int count = 1000000; //1 million

            var start           = DateTime.Now;
            var listOfUniverses =
                Parallelization.DistributeParallel(chunkCount => TestDataGeneratorFactory.Create().CreateMany <Universe> (chunkCount), count).ToList();

            Console.WriteLine(
                "Took {0}s to generate {1} universes",
                (DateTime.Now - start).TotalSeconds,
                listOfUniverses.Count);

            Console.Read();
        }
 Context BaseContext()
 {
     return
         (c =>
          c
          .Given("{0,1,2,3}", x => InputList = new List <int> {
         0, 1, 2, 3
     })
          .Given("min: 2", x => MinItems = 2)
          .Given("max: 4", x => MaxItems = 4)
          .Given("Empty domain with value provider",
                 x =>
                 TestDataDomainConfiguration =
                     (context =>
                      context.UseDefaults(false)
                      .UseRandom(Random)
                      .For <IList <string> > ()
                      .AddProvider(new ChooseMultipleDistinctItemsValueProvider <int, string> (InputList, MinItems, MaxItems,
                                                                                               conversionFunc: item => item.ToString()))))
          .Given("TestDataGenerator", x => TestDataGenerator = TestDataGeneratorFactory.Create(TestDataDomainConfiguration)));
 }
Esempio n. 8
0
        public void Extend(ITestController testController, object suite)
        {
            var suiteType           = suite.GetType();
            var fieldsWithAttribute = suiteType.GetFieldsWithAttribute <AutoDataAttribute>()
                                      .OrderBy(x => x.Item1.Name).ToList();

            if (fieldsWithAttribute.Count == 0)
            {
                return;
            }

            var seed          = GetSeed(suiteType);
            var random        = new DefaultRandom(seed);
            var configuration = GetAutoDataConfiguration(suiteType);

            var generator = TestDataGeneratorFactory.Create(x => configuration(x).UseRandom(random));

            // TODO: add seed to data
            testController.AddAction <SetupExtension>(
                $"<Create_AutoData><{seed}>",
                x => fieldsWithAttribute.ForEach(t => CreateAndAssignAuto(suite, generator, t.Item2, t.Item1)));
        }