Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Laval <jeremie.laval@gmail.com>2011-01-22 05:54:52 +0300
committerJérémie Laval <jeremie.laval@gmail.com>2011-01-22 05:55:15 +0300
commit7a505099cf82968b87462226071e43d63b548183 (patch)
tree8dd28e9e7da0cf9d2f366f97ed63862d10a09f9a /mcs/class/WebMatrix.Data
parentbd10f1c50a7a6b8018fa957efcdc1e4ed4519bde (diff)
Add unit test for Database
Diffstat (limited to 'mcs/class/WebMatrix.Data')
-rw-r--r--mcs/class/WebMatrix.Data/Makefile2
-rw-r--r--mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DatabaseTests.cs94
-rw-r--r--mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DynamicRecordTests.cs2
-rw-r--r--mcs/class/WebMatrix.Data/Test/testsqlite.dbbin0 -> 2048 bytes
-rw-r--r--mcs/class/WebMatrix.Data/WebMatrix.Data_test.dll.sources1
5 files changed, 97 insertions, 2 deletions
diff --git a/mcs/class/WebMatrix.Data/Makefile b/mcs/class/WebMatrix.Data/Makefile
index 6837c52076b..1bca6fb491c 100644
--- a/mcs/class/WebMatrix.Data/Makefile
+++ b/mcs/class/WebMatrix.Data/Makefile
@@ -7,4 +7,4 @@ LIBRARY = WebMatrix.Data.dll
include ../../build/library.make
LIB_MCS_FLAGS += -r:$(corlib) -r:System.dll -r:System.Data.dll -r:System.Core.dll -r:System.Configuration.dll
-TEST_MCS_FLAGS += -r:System.dll -r:System.Data.dll
+TEST_MCS_FLAGS += -r:System.dll -r:System.Data.dll -r:Mono.Data.Sqlite.dll
diff --git a/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DatabaseTests.cs b/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DatabaseTests.cs
new file mode 100644
index 00000000000..12f3cf6264f
--- /dev/null
+++ b/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DatabaseTests.cs
@@ -0,0 +1,94 @@
+//
+// DatabaseTests.cs
+//
+// Author:
+// Jérémie "garuma" Laval <jeremie.laval@gmail.com>
+//
+// Copyright (c) 2011 Novell
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#if NET_4_0
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Data.Common;
+using System.Collections.Generic;
+
+using WebMatrix.Data;
+
+using NUnit.Framework;
+
+namespace MonoTests.WebMatrix.Data
+{
+ [TestFixtureAttribute]
+ public class DatabaseTests
+ {
+ Database database;
+
+ [SetUp]
+ public void Setup ()
+ {
+ string path = Path.Combine ("Test", "testsqlite.db");
+ database = Database.OpenConnectionString ("Data Source="+path+";Version=3;", "Mono.Data.Sqlite");
+ }
+
+ [Test]
+ public void QuerySingleTest ()
+ {
+ var result = database.QuerySingle ("select * from memos where Text=@0 limit 1", "Grendel");
+
+ Assert.IsNotNull (result);
+ Assert.AreEqual ("Grendel", result.Text);
+ Assert.AreEqual (5, result.Priority);
+ }
+
+ [Test]
+ public void SimpleQueryTest ()
+ {
+ var result = database.Query ("select * from memos");
+
+ Assert.IsNotNull (result);
+ Assert.AreEqual (5, result.Count ());
+
+ var col1 = new string[] { "Webmatrix", "Grendel", "Garuma", "jpobst", "Gonzalo" };
+ var col2 = new object[] { 10, 5, -1, 6, 4 };
+ int index = 0;
+
+ foreach (var row in result) {
+ Assert.AreEqual (col1[index], row.Text);
+ Assert.AreEqual (col2[index], row.Priority);
+ index++;
+ }
+ }
+
+ [Test]
+ public void ConnectionOpenedTest ()
+ {
+ bool opened = false;
+ Database.ConnectionOpened += (sender, e) => opened = sender == database;
+
+ var result = database.QuerySingle ("select * from memos where Text=@0 limit 1", "Grendel");
+
+ Assert.IsTrue (opened);
+ }
+ }
+}
+#endif
diff --git a/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DynamicRecordTests.cs b/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DynamicRecordTests.cs
index 0a9a177ac6b..c180ca2e24e 100644
--- a/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DynamicRecordTests.cs
+++ b/mcs/class/WebMatrix.Data/Test/WebMatrix.Data/DynamicRecordTests.cs
@@ -96,4 +96,4 @@ namespace MonoTests.WebMatrix.Data
}
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/WebMatrix.Data/Test/testsqlite.db b/mcs/class/WebMatrix.Data/Test/testsqlite.db
new file mode 100644
index 00000000000..06fd900473f
--- /dev/null
+++ b/mcs/class/WebMatrix.Data/Test/testsqlite.db
Binary files differ
diff --git a/mcs/class/WebMatrix.Data/WebMatrix.Data_test.dll.sources b/mcs/class/WebMatrix.Data/WebMatrix.Data_test.dll.sources
index 017d36adb25..927528aa296 100644
--- a/mcs/class/WebMatrix.Data/WebMatrix.Data_test.dll.sources
+++ b/mcs/class/WebMatrix.Data/WebMatrix.Data_test.dll.sources
@@ -1,3 +1,4 @@
WebMatrix.Data/ConnectionEventArgsTests.cs
WebMatrix.Data/DynamicRecordTests.cs
../WebMatrix.Data/DynamicRecord.cs
+WebMatrix.Data/DatabaseTests.cs