Exemplo n.º 1
0
        public void _DecimalGenerator_CS()
        {
            var dataSet = DataSet <_DecimalModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = 100;

            using (var g = new DataSetGenerator(dataSet, LanguageNames.CSharp))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(4, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._DecimalModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(9, statements.Length);
                Assert.AreEqual("{", statements[0]);
                Assert.AreEqual("DataSet<_DecimalModel> result = DataSet<_DecimalModel>.Create().AddRows(2);", statements[1]);
                Assert.AreEqual("_DecimalModel _ = result._;", statements[2]);
                Assert.AreEqual("_.SuspendIdentity();", statements[3]);
                Assert.AreEqual(@"_.Column[0] = null;", statements[4]);
                Assert.AreEqual(@"_.Column[1] = 100M;", statements[5]);
                Assert.AreEqual("_.ResumeIdentity();", statements[6]);
                Assert.AreEqual("return result;", statements[7]);
                Assert.AreEqual("}", statements[8]);
            }
        }
Exemplo n.º 2
0
        public void _DecimalGenerator_VB()
        {
            var dataSet = DataSet <_DecimalModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = 100;

            using (var g = new DataSetGenerator(dataSet, LanguageNames.VisualBasic))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(4, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._DecimalModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(7, statements.Length);
                Assert.AreEqual("Dim result As DataSet(Of _DecimalModel) = DataSet(Of _DecimalModel).Create().AddRows(2)", statements[0]);
                Assert.AreEqual("Dim x As _DecimalModel = result.Entity", statements[1]);
                Assert.AreEqual("x.SuspendIdentity()", statements[2]);
                Assert.AreEqual(@"x.Column(0) = Nothing", statements[3]);
                Assert.AreEqual(@"x.Column(1) = 100D", statements[4]);
                Assert.AreEqual("x.ResumeIdentity()", statements[5]);
                Assert.AreEqual("Return result", statements[6]);
            }
        }
Exemplo n.º 3
0
        public void _GuidGenerator_VB()
        {
            var dataSet = DataSet <_GuidModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = new Guid("ADD56204-38F3-4E24-B281-AC40CDDE7C67");

            using (var g = new DataSetGenerator(dataSet, LanguageNames.VisualBasic))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(5, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._GuidModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);
                Assert.AreEqual("System.Guid", referencedTypes[4]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(7, statements.Length);
                Assert.AreEqual("Dim result As DataSet(Of _GuidModel) = DataSet(Of _GuidModel).Create().AddRows(2)", statements[0]);
                Assert.AreEqual("Dim x As _GuidModel = result.Entity", statements[1]);
                Assert.AreEqual("x.SuspendIdentity()", statements[2]);
                Assert.AreEqual(@"x.Column(0) = Nothing", statements[3]);
                Assert.AreEqual(@"x.Column(1) = New Guid(""add56204-38f3-4e24-b281-ac40cdde7c67"")", statements[4]);
                Assert.AreEqual("x.ResumeIdentity()", statements[5]);
                Assert.AreEqual("Return result", statements[6]);
            }
        }
Exemplo n.º 4
0
        public void _BinaryGenerator_VB()
        {
            var dataSet = DataSet <_BinaryModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = new Binary(new byte[] { 1, 2, 3 });

            using (var g = new DataSetGenerator(dataSet, LanguageNames.VisualBasic))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(6, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.Binary", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._BinaryModel", referencedTypes[3]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[4]);
                Assert.AreEqual("System.Convert", referencedTypes[5]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(7, statements.Length);
                Assert.AreEqual("Dim result As DataSet(Of _BinaryModel) = DataSet(Of _BinaryModel).Create().AddRows(2)", statements[0]);
                Assert.AreEqual("Dim x As _BinaryModel = result.Entity", statements[1]);
                Assert.AreEqual("x.SuspendIdentity()", statements[2]);
                Assert.AreEqual(@"x.Column(0) = Nothing", statements[3]);
                Assert.AreEqual(@"x.Column(1) = New Binary(Convert.FromBase64String(""AQID""))", statements[4]);
                Assert.AreEqual("x.ResumeIdentity()", statements[5]);
                Assert.AreEqual("Return result", statements[6]);
            }
        }
Exemplo n.º 5
0
        public void _GuidGenerator_CS()
        {
            var dataSet = DataSet <_GuidModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = new Guid("ADD56204-38F3-4E24-B281-AC40CDDE7C67");

            using (var g = new DataSetGenerator(dataSet, LanguageNames.CSharp))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(5, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._GuidModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);
                Assert.AreEqual("System.Guid", referencedTypes[4]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(9, statements.Length);
                Assert.AreEqual("{", statements[0]);
                Assert.AreEqual("DataSet<_GuidModel> result = DataSet<_GuidModel>.Create().AddRows(2);", statements[1]);
                Assert.AreEqual("_GuidModel _ = result._;", statements[2]);
                Assert.AreEqual("_.SuspendIdentity();", statements[3]);
                Assert.AreEqual(@"_.Column[0] = null;", statements[4]);
                Assert.AreEqual(@"_.Column[1] = new Guid(""add56204-38f3-4e24-b281-ac40cdde7c67"");", statements[5]);
                Assert.AreEqual("_.ResumeIdentity();", statements[6]);
                Assert.AreEqual("return result;", statements[7]);
                Assert.AreEqual("}", statements[8]);
            }
        }
Exemplo n.º 6
0
        public void _BinaryGenerator_CS()
        {
            var dataSet = DataSet <_BinaryModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = new Binary(new byte[] { 1, 2, 3 });

            using (var g = new DataSetGenerator(dataSet, LanguageNames.CSharp))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(6, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.Binary", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._BinaryModel", referencedTypes[3]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[4]);
                Assert.AreEqual("System.Convert", referencedTypes[5]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(9, statements.Length);
                Assert.AreEqual("{", statements[0]);
                Assert.AreEqual("DataSet<_BinaryModel> result = DataSet<_BinaryModel>.Create().AddRows(2);", statements[1]);
                Assert.AreEqual("_BinaryModel _ = result._;", statements[2]);
                Assert.AreEqual("_.SuspendIdentity();", statements[3]);
                Assert.AreEqual(@"_.Column[0] = null;", statements[4]);
                Assert.AreEqual(@"_.Column[1] = new Binary(Convert.FromBase64String(""AQID""));", statements[5]);
                Assert.AreEqual("_.ResumeIdentity();", statements[6]);
                Assert.AreEqual("return result;", statements[7]);
                Assert.AreEqual("}", statements[8]);
            }
        }
Exemplo n.º 7
0
        public void _StringGenerator_VB()
        {
            var dataSet = DataSet <_StringModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = "Line1" + Environment.NewLine + @"""Line2""";

            using (var g = new DataSetGenerator(dataSet, LanguageNames.VisualBasic))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(4, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._StringModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(7, statements.Length);
                Assert.AreEqual("Dim result As DataSet(Of _StringModel) = DataSet(Of _StringModel).Create().AddRows(2)", statements[0]);
                Assert.AreEqual("Dim x As _StringModel = result.Entity", statements[1]);
                Assert.AreEqual("x.SuspendIdentity()", statements[2]);
                Assert.AreEqual(@"x.Column(0) = Nothing", statements[3]);
                Assert.AreEqual("x.Column(1) = \"Line1\" & Global.Microsoft.VisualBasic.Constants.vbCrLf & \"\"\"Line2\"\"\"", statements[4]);
                Assert.AreEqual("x.ResumeIdentity()", statements[5]);
                Assert.AreEqual("Return result", statements[6]);
            }
        }
        public void _DateTimeOffsetGenerator_VB()
        {
            var dataSet = DataSet <_DateTimeOffsetModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = new DateTimeOffset(new DateTime(2018, 12, 13), new TimeSpan(5, 0, 0));

            using (var g = new DataSetGenerator(dataSet, LanguageNames.VisualBasic))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(5, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._DateTimeOffsetModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);
                Assert.AreEqual("System.DateTimeOffset", referencedTypes[4]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(7, statements.Length);
                Assert.AreEqual("Dim result As DataSet(Of _DateTimeOffsetModel) = DataSet(Of _DateTimeOffsetModel).Create().AddRows(2)", statements[0]);
                Assert.AreEqual("Dim x As _DateTimeOffsetModel = result.Entity", statements[1]);
                Assert.AreEqual("x.SuspendIdentity()", statements[2]);
                Assert.AreEqual(@"x.Column(0) = Nothing", statements[3]);
                Assert.AreEqual(@"x.Column(1) = DateTimeOffset.Parse(""2018-12-13T00:00:00.0000000+05:00"")", statements[4]);
                Assert.AreEqual("x.ResumeIdentity()", statements[5]);
                Assert.AreEqual("Return result", statements[6]);
            }
        }
        public void _DateTimeOffsetGenerator_CS()
        {
            var dataSet = DataSet <_DateTimeOffsetModel> .Create();

            dataSet.AddRows(2);
            var _ = dataSet._;

            _.Column[0] = null;
            _.Column[1] = new DateTimeOffset(new DateTime(2018, 12, 13), new TimeSpan(5, 0, 0));

            using (var g = new DataSetGenerator(dataSet, LanguageNames.CSharp))
            {
                var referencedTypes = g.GetReferencedTypes().ToArray();
                Assert.AreEqual(5, referencedTypes.Length);
                Assert.AreEqual("DevZest.Data.DataSet`1", referencedTypes[0]);
                Assert.AreEqual("DevZest.Data.DbInit.DbInitExtensions", referencedTypes[1]);
                Assert.AreEqual("DevZest.Data.DbInit.TestModels._DateTimeOffsetModel", referencedTypes[2]);
                Assert.AreEqual("DevZest.Data.Primitives.ModelExtensions", referencedTypes[3]);
                Assert.AreEqual("System.DateTimeOffset", referencedTypes[4]);

                var statements = g.GetStatements().ToArray();
                Assert.AreEqual(9, statements.Length);
                Assert.AreEqual("{", statements[0]);
                Assert.AreEqual("DataSet<_DateTimeOffsetModel> result = DataSet<_DateTimeOffsetModel>.Create().AddRows(2);", statements[1]);
                Assert.AreEqual("_DateTimeOffsetModel _ = result._;", statements[2]);
                Assert.AreEqual("_.SuspendIdentity();", statements[3]);
                Assert.AreEqual(@"_.Column[0] = null;", statements[4]);
                Assert.AreEqual(@"_.Column[1] = DateTimeOffset.Parse(""2018-12-13T00:00:00.0000000+05:00"");", statements[5]);
                Assert.AreEqual("_.ResumeIdentity();", statements[6]);
                Assert.AreEqual("return result;", statements[7]);
                Assert.AreEqual("}", statements[8]);
            }
        }
Exemplo n.º 10
0
        private async Task RunAsync(DbSession db, string[] tableNames, string language, string directory)
        {
            for (int i = 0; i < tableNames.Length; i++)
            {
                var tableName = tableNames[i];
                Console.WriteLine(string.Format(Messages.FetchingTableData, tableName));
                CancellationToken.ThrowIfCancellationRequested();
                var dataSet = await GetDataSetAsync(db, tableName);

                using (var g = new DataSetGenerator(dataSet, language))
                {
                    Directory.CreateDirectory(directory);
                    File.WriteAllLines(Path.Combine(directory, tableName + ".types"), g.GetReferencedTypes().ToArray());
                    File.WriteAllLines(Path.Combine(directory, tableName + ".statements"), g.GetStatements().ToArray());
                }
            }
        }
Exemplo n.º 11
0
 internal void Initialize(DataSetGenerator dataSetGenerator, Column column)
 {
     _dataSetGenerator = dataSetGenerator;
     Initialize(column);
 }