File: ReadTest_AllTypes_MySql.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (165 lines) | stat: -rw-r--r-- 5,072 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#define DbLinqGuidTest

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Globalization;
using NUnit.Framework;
using AllTypesExample;


namespace Test_NUnit_MySql
{

    /// <summary>
    /// this test will exercise reading of columns of all MySQL types 
    /// (such as decimal, decimal?, DateTime? etc)
    /// </summary>
    [TestFixture]
    public class ReadTest_AllTypes
    {
        public AllTypes CreateDB()
        {
            string DbServer = Environment.GetEnvironmentVariable("DbLinqServer") ?? "localhost";
            string connStr = string.Format("server={0};user id=LinqUser; password=linq2; database=AllTypes", DbServer);

            //return CreateDB(System.Data.ConnectionState.Closed);
            AllTypes db = new AllTypes(new MySql.Data.MySqlClient.MySqlConnection(connStr));

            return db;
        }

        [Test]
        public void AT1_SelectAllIntTypes()
        {
            AllTypes db = CreateDB();

            var q = from p in db.AllIntTypes select p;
            int count = q.ToList().Count;
            Assert.IsTrue(count > 0, "Expected some entries in AllIntTypes, got none");
        }

        [Test]
        public void AT2_SelectAllFloatTypes()
        {
            AllTypes db = CreateDB();

            var q = from p in db.FloatTypes select p;
            int count = q.ToList().Count;
            Assert.IsTrue(count > 0, "Expected some entries in FloatTypes, got none");
        }

        [Test]
        public void AT2_SelectOtherTypes()
        {
            AllTypes db = CreateDB();

            var q = from p in db.OtherTypes select p.DateTimeN;
            int count = q.ToList().Count;
            Assert.IsTrue(count > 0, "Expected some entries in AllTypes, got none");
        }

        [Test]
        public void AT3_SelectDecimalN()
        {
            AllTypes db = CreateDB();

            var q = from p in db.FloatTypes select p.DecimalN;
            int count = q.ToList().Count;
            Assert.IsTrue(count > 0, "Expected some entries in AllTypes, got none");
        }

#if DBLINQ_ENUMTEST
        [Test]
        public void AT4_SelectEnum()
        {
            AllTypes db = CreateDB();

            var q = from p in db.Allinttypes select p.DbLinq_EnumTest;
            int count = q.ToList().Count;
            Assert.IsTrue(count > 0, "Expected some enums in AllTypes, got none");
        }

        [Test]
        public void AT5_SelectEnum_()
        {
            AllTypes db = CreateDB();

            var q = from p in db.Allinttypes select p.DbLinq_EnumTest;
            string sql_string = db.GetQueryText(q);

            DbLinq_EnumTest enumValue = q.First();
            Assert.IsTrue(enumValue > 0, "Expected enum value>0 in AllTypes, got enumValue=" + enumValue);
        }
#endif

        [Test]
        public void AT6_ReadBlob()
        {
            //DbLinq could not read byte[]
            //This test was contributed by Anatoli Koutsevol 

            Console.WriteLine("from p in db.Othertypes orderby p.DateTime_ select p.blob;");
            AllTypes db = CreateDB();

            var result = from p in db.OtherTypes orderby p.DateTime select p.Blob;
            foreach (var blob in result)
            {
                Console.WriteLine("blob[{0}]", blob.Length);
            }
            Console.WriteLine("Press enter to continue.");
        }

#if DbLinqGuidTest

        [Test]
        public void AT7_ReadGuidFromVarchar()
        {
            Console.WriteLine("from p in db.Othertypes orderby p.DateTime_ select p.blob;");
            AllTypes db = CreateDB();

            var query = from p in db.OtherTypes orderby p.DateTime select p.DbLinqGuidTest;
            Guid? guid = query.First();
            Assert.IsTrue(guid != null);
        }

        [Test]
        public void AT8_ReadGuidFromVarbinary()
        {
            Console.WriteLine("from p in db.Othertypes orderby p.DateTime_ select p.blob;");
            AllTypes db = CreateDB();

            var query = from p in db.OtherTypes orderby p.DateTime select p.DbLinqGuidTest2;
            Guid guid = query.First();
            string guidStr = guid.ToString();
            Assert.IsTrue(guidStr == "{0101}");
        }
#endif
        [Test]
        public void Test_Unknown()
        {
            AllTypes db = CreateDB();

            var result = from p in db.OtherTypes
                         orderby p.DateTime
                         select
                             p.Blob;
            foreach (var blob in result)
            {
                Console.WriteLine("blob[{0}]", blob.Length);
            }
        }

        [Test]
        public void Test_Select_DateTime_ParseExact()
        {
            AllTypes db = CreateDB();
            var result = from p in db.ParsingData
                         select DateTime.ParseExact(p.DateTimeStr, "yyyy.MM.dd", CultureInfo.InvariantCulture);
            DateTime dt1 = result.First();
            Assert.IsTrue(dt1.Year == 2008);
        }

    }
}