Пример #1
0
        public void Write(string filePath, int entityCount)
        {
            using (TextWriter writer = new StreamWriter(filePath))
            {
                string insertLine = _generator.GetInsertLine();
                writer.WriteLine(insertLine);

                for (int i = 1; i <= entityCount; i++)
                {
                    if (i > 1)
                    {
                        writer.Write(",");
                    }

                    UserEntity user      = _generator.GenerateUser();
                    string     valueLine = _generator.GetValueLine(user);
                    writer.WriteLine(valueLine);
                }
            }
        }
Пример #2
0
        public void GenerateUser_GetValueLine()
        {
            UserEntity user = new UserEntity()
            {
                Name             = "Петр",
                Surname          = "Петров",
                Patronymic       = "Петрович",
                Email            = "*****@*****.**",
                Login            = "******",
                Password         = "******",
                RegistrationDate = new DateTime(2016, 1, 1)
            };
            const string EXPECTED_RESULT = @"VALUES('Петр','Петров','Петрович','*****@*****.**','petr','Петр','20160101')";
            string       result          = _generator.GetValueLine(user);

            Assert.That(result, Is.EqualTo(EXPECTED_RESULT));
        }
Пример #3
0
        static void Main(string[] args)
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <UserTextFileRepository>().As <IUserRepository>();
            builder.RegisterType <UserValueLineGenerator>().As <IValueLineGenerator <User> >();
            builder.RegisterType <ScriptGenerator <User> >().As <IScriptGenerator <User> >();
            builder.RegisterType <BusinessCardTextFileRepository>().As <IBusinessCardRepository>();
            builder.RegisterType <BusinessCardValueLineGenerator>().As <IValueLineGenerator <BusinessCard> >();
            builder.RegisterType <ScriptGenerator <BusinessCard> >().As <IScriptGenerator <BusinessCard> >();

            IContainer container = builder.Build();

            IScriptGenerator <User>         userScriptGen = container.Resolve <IScriptGenerator <User> >();
            IScriptGenerator <BusinessCard> cardScriptGen = container.Resolve <IScriptGenerator <BusinessCard> >();

            Console.WriteLine("Generated entity model and value line for User class: ");
            var user = userScriptGen.GetEntityModel();

            Console.WriteLine(userScriptGen.GetValueLine(user));

            Console.WriteLine("Generated script for User class: ");
            Console.WriteLine(userScriptGen.GenerateScript(20));

            Console.WriteLine("//////////////////////////////////////////////");
            Console.WriteLine("//////////////////////////////////////////////");
            Console.WriteLine("//////////////////////////////////////////////");

            Console.WriteLine("Generated entity model and value line for BusinessCard class: ");
            var card = cardScriptGen.GetEntityModel();

            Console.WriteLine(cardScriptGen.GetValueLine(card));

            Console.WriteLine("Generated script for User class: ");
            Console.WriteLine(cardScriptGen.GenerateScript(20));

            Console.ReadKey();
        }