예제 #1
0
        public static void GenerateDaoCodeForTypes()
        {
            GenerationInfo genInfo       = GetDaoGenerationInfo();
            Assembly       typeAssembly  = genInfo.Assembly;
            string         schemaName    = genInfo.SchemaName;
            string         fromNameSpace = genInfo.FromNameSpace;
            string         toNameSpace   = genInfo.ToNameSpace;
            string         defaultPath   = $".\\{schemaName}_Generated";
            DirectoryInfo  defaultDir    = new DirectoryInfo(defaultPath);

            defaultPath = defaultDir.FullName;
            string        writeTo    = GetArgument("writeSrc", $"Please enter the path to write code to (default ({defaultPath}))").Or(defaultPath);
            DirectoryInfo writeToDir = new DirectoryInfo(writeTo);

            if (writeToDir.Exists)
            {
                Directory.Move(writeToDir.FullName, $"{writeToDir.FullName}_{DateTime.Now.ToJulianDate()}");
            }
            ConsoleLogger logger = new ConsoleLogger();

            logger.StartLoggingThread();
            TypeDaoGenerator generator = new TypeDaoGenerator(typeAssembly, fromNameSpace, logger)
            {
                WarningsAsErrors = true
            };

            generator.ThrowWarningsIfWarningsAsErrors();
            generator.BaseNamespace = toNameSpace;
            generator.GenerateSource(writeTo);
            logger.BlockUntilEventQueueIsEmpty(1000);
        }
예제 #2
0
        public void ShouldBeAbleToGenerateSchema()
        {
            TypeDaoGenerator generator = new TypeDaoGenerator();

            generator.AddType(typeof(TestContainer));
            SchemaDefinition schema = generator.CreateSchemaDefinition().SchemaDefinition;

            OutLineFormat("Schema {0} created successfully", ConsoleColor.Green, schema.Name);
        }
예제 #3
0
        public void GetDaoAssemblyShouldGetTheSameOneEachTime()
        {
            TypeDaoGenerator generator = new TypeDaoGenerator();

            generator.AddType(typeof(TestContainer));
            Assembly first    = generator.GetDaoAssembly();
            Assembly again    = generator.GetDaoAssembly();
            Assembly andAgain = generator.GetDaoAssembly();
            Assembly oneMoreForGoodMeasure = generator.GetDaoAssembly();

            Expect.AreSame(first, again);
            Expect.AreSame(first, andAgain);
            Expect.AreSame(first, oneMoreForGoodMeasure);
        }
예제 #4
0
        public void GenerateDaoForDtosShouldSucceedWithoutErrors()
        {
            ConsoleLogger logger = new ConsoleLogger();

            logger.StartLoggingThread();
            TypeDaoGenerator generator = new TypeDaoGenerator();

            generator.AddType(typeof(TestContainer));
            generator.Subscribe(logger);

            CompilerResults result = generator.GenerateAndCompile("TestAssemblyName", ".\\{0}"._Format(MethodBase.GetCurrentMethod().Name));

            if (result.Errors.Count > 0)
            {
                foreach (CompilerError err in result.Errors)
                {
                    OutLineFormat("File: {0}, ErrorNumber: {1}, Line: {2}, Column: {3}, Text: {4}", ConsoleColor.Red, err.FileName, err.ErrorNumber, err.Line, err.Column, err.ErrorText);
                }
            }
            Expect.IsTrue(result.Errors.Count == 0, "There were errors in compilation");
            FileInfo assembly = new FileInfo(result.PathToAssembly);

            OutLineFormat("Assembly is at : {0}", assembly.FullName);
        }