コード例 #1
0
ファイル: Program.cs プロジェクト: vernou/TextDataGenerator
 public static void Main(string[] args)
 {
     try
     {
         InitializeInvariantCuluture();
         var options = CommandLineOptions.CreateAndParse(args);
         if (LoadSettingFromArguments(options))
         {
             var textFile = TextFileHelper.ReadAllTextFileWithDefaultEncoding(options.Path);
             var builder  = TemplateBuilderParser.CreateBuilderText(textFile);
             Console.WriteLine(builder.CreateDataGenerator().GetData());
         }
         else
         {
             // Display the default usage information
             Console.WriteLine(options.GetUsage());
         }
     }
     catch (BuilderParserException bex)
     {
         Console.Error.WriteLine(ExceptionHelper.ToStringFull(bex));
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine("An error has occurred!");
         Console.Error.WriteLine(ExceptionHelper.ToStringFull(ex));
     }
 }
コード例 #2
0
        public void CreateBuilderTextTest1()
        {
            const string text     = @"@{Integer} + @{Double}";
            var          template = (TemplateData)TemplateBuilderParser.CreateBuilderText(text).CreateDataGenerator();

            Assert.AreEqual(3, template.Datas.Count);
            Assert.IsInstanceOfType(template.Datas[0], typeof(IntegerGenerator));
            Assert.AreEqual(" + ", template.Datas[1].GetData());
            Assert.IsInstanceOfType(template.Datas[2], typeof(DoubleGenerator));
        }
コード例 #3
0
        public void RunExamples()
        {
            var pathFiles = Directory.GetFiles(@"rsc\Example");

            foreach (var pathFile in pathFiles)
            {
                var text = File.ReadAllText(pathFile);
                TemplateBuilderParser.CreateBuilderText(text).CreateDataGenerator().GetData();
            }
        }
コード例 #4
0
        public void CreateBuilderTextTest5()
        {
            const string text     = @"@{Integer Id=MyInteger Min=1} = @{MyInteger}";
            var          template = (TemplateData)TemplateBuilderParser.CreateBuilderText(text).CreateDataGenerator();

            Assert.AreEqual(3, template.Datas.Count);
            Assert.IsInstanceOfType(template.Datas[0], typeof(IdDataDecorator));
            Assert.AreEqual(" = ", template.Datas[1].GetData());
            Assert.IsInstanceOfType(template.Datas[2], typeof(IdValueData));
            Assert.AreEqual("1 = 1", template.GetData());
        }
コード例 #5
0
        public void CreateBuilderTextTest4()
        {
            const string text     = @"@{Repeat Min=""10"" Max=""30""} ""Test""=> @{Integer} @{EndRepeat}";
            var          template = (TemplateData)TemplateBuilderParser.CreateBuilderText(text).CreateDataGenerator();

            Assert.AreEqual(1, template.Datas.Count);
            Assert.IsInstanceOfType(template.Datas[0], typeof(RepeatData));

            var repeat = (RepeatData)template.Datas[0];

            Assert.AreEqual(10, repeat.Min);
            Assert.AreEqual(30, repeat.Max);
            Assert.AreEqual(3, repeat.Datas.Count);
            Assert.AreEqual(@" ""Test""=> ", repeat.Datas[0].GetData());
            Assert.IsInstanceOfType(repeat.Datas[1], typeof(IntegerGenerator));
            Assert.AreEqual(" ", repeat.Datas[2].GetData());
        }
コード例 #6
0
        public void CreateBuilderTextTest3()
        {
            try
            {
                const string text = @"
@{Repeat Min=10 Max=30}
Easy Test => @{FailLine 3}
@{EndRepeat}
";
                TemplateBuilderParser.CreateBuilderText(text).CreateDataGenerator();
                Assert.Fail();
            }
            catch (BuilderParserException ex)
            {
                Assert.AreEqual(3, ex.Line);
            }
        }
コード例 #7
0
        public void CreateBuilderTextTest2()
        {
            const string text     = @"
@{Repeat Min=10 Max=30}
Easy Test => @{Integer}
@{EndRepeat}
";
            var          template = (TemplateData)TemplateBuilderParser.CreateBuilderText(text).CreateDataGenerator();

            Assert.AreEqual(2, template.Datas.Count);
            Assert.AreEqual(Environment.NewLine, template.Datas[0].GetData());
            Assert.IsInstanceOfType(template.Datas[1], typeof(RepeatData));

            var repeat = (RepeatData)template.Datas[1];

            Assert.AreEqual(10, repeat.Min);
            Assert.AreEqual(30, repeat.Max);
            Assert.AreEqual(3, repeat.Datas.Count);
            Assert.AreEqual("Easy Test => ", repeat.Datas[0].GetData());
            Assert.IsInstanceOfType(repeat.Datas[1], typeof(IntegerGenerator));
            Assert.AreEqual(Environment.NewLine, repeat.Datas[2].GetData());
        }