Пример #1
0
 /// <summary>
 /// Static constructor
 /// </summary>
 static Context()
 {
     QyfEntities = new QuestionYourFriendsEntities();
     QyfEntities.Users.MergeOption = MergeOption.AppendOnly;
     QyfEntities.Transacs.MergeOption = MergeOption.AppendOnly;
     QyfEntities.Questions.MergeOption = MergeOption.AppendOnly;
     _logger.Info("Context initialized.");
 }
Пример #2
0
        /// <summary>
        /// Main function, generates the database information
        /// </summary>
        public static void Main()
        {
            // log4net initialization.
            string targetFileName = Assembly.GetExecutingAssembly().Location;
            var fi = new FileInfo(string.Concat(targetFileName, ".config"));
            XmlConfigurator.ConfigureAndWatch(fi);

            _logger.InfoFormat(new CultureInfo("en-US"), "=== Launching Qyf DataGen v.{0:0.0}... ===", Version);
            Console.WriteLine(string.Format(new CultureInfo("en-US"), "  === Qyf DataGen v.{0:0.0} ===", Version));
            Console.WriteLine();
            _qyfe = new QuestionYourFriendsEntities();

            // Perform factory set up (once for entire test run)
            IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => c.UseDefaultConventions());

                // Impose question informations
                x.AddFromAssemblyContainingType<Question>();
                x.Include<Question>()
                    .Setup(q => q.date_pub).Use<DateOfBirthSource>()
                    .Setup(q => q.Owner).Use<RandomListSource<User>>(_qyfe.Users)
                    .Setup(q => q.Receiver).Use<RandomListSource<User>>(_qyfe.Users)
                    .Setup(q => q.private_price).Use<RandomIntegerSource>(200)
                    .Setup(q => q.anom_price).Use<RandomIntegerSource>(200)
                    .Setup(q => q.undesirable).Use<ValueSource<bool>>(false)
                    .Setup(q => q.deleted).Use<ValueSource<bool>>(false)
                    .Setup(q => q.text).Use<RandomListSource<string>>(Data.DataGen.Questions)
                    .Setup(q => q.answer).Use<RandomListSource<string>>(Data.DataGen.Answers);

                // Impose transaction informations
                x.AddFromAssemblyContainingType<Transac>();
                x.Include<Transac>()
                    .Setup(t => t.amount).Use<ValueSource<int>>(QyfData.EarningStartup)
                    .Setup(t => t.status).Use<ValueSource<int>>(TransacStatus.Ok)
                    .Setup(t => t.type).Use<ValueSource<int>>(TransacType.EarningStartup);
                //.Setup(t => t.amount).Use<RandomIntegerSource>(250)
                //.Setup(t => t.User).Use<RandomListSource<User>>(_qyfe.Users)
                //.Setup(t => t.Question).Use<RandomListSource<Question>>(_qyfe.Questions)
                //.Setup(t => t.status).Use<RandomEnumSource<TransacStatus>>()
                //.Setup(t => t.type).Use<RandomEnumSource<TransacType>>();

                // Impose user informations
                x.AddFromAssemblyContainingType<User>();
                x.Include<User>()
                    .Setup(u => u.activated).Use<ValueSource<bool>>(true);
            });

            // Generate one of these per test (factory will be a static variable most likely)
            _session = factory.CreateSession();

            _logger.InfoFormat("Cleaning database:");
            Console.WriteLine(@"    Cleaning database:");
            CleanDb();
            Console.WriteLine();

            _logger.InfoFormat("Generating data:");
            Console.WriteLine(@"    Generating data:");
            AddData();
            Console.WriteLine();

            _logger.InfoFormat("Generation done.");
            Console.Write(@"  Generation done, press enter to exit...");
            Console.ReadLine();
        }