-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
855 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using MySql.Data.MySqlClient; | ||
using System; | ||
using System.IO; | ||
using MySql.Server; | ||
|
||
namespace Example | ||
{ | ||
[TestClass] | ||
public class Example | ||
{ | ||
//Starting the MySql server. Here it is done in the AssemblyInitialize method for performance purposes. | ||
//It could also be restarted in every test using [TestInitialize] attribute | ||
[AssemblyInitialize] | ||
public static void Initialize(TestContext context) | ||
{ | ||
MySqlServer dbServer = MySqlServer.Instance; | ||
dbServer.StartServer(); | ||
|
||
//Let us create a table | ||
dbServer.ExecuteNonQuery("CREATE TABLE testTable (`id` INT NOT NULL, `value` CHAR(150) NULL, PRIMARY KEY (`id`)) ENGINE = MEMORY;"); | ||
|
||
//Insert data. You could of course insert data from a *.sql file | ||
dbServer.ExecuteNonQuery("INSERT INTO testTable (`value`) VALUES ('some value')"); | ||
} | ||
|
||
//The server is shutdown as the test ends | ||
[AssemblyCleanup] | ||
public static void Cleanup() | ||
{ | ||
MySqlServer dbServer = MySqlServer.Instance; | ||
|
||
dbServer.ShutDown(); | ||
} | ||
|
||
//Concrete test. Writes data and reads it again. | ||
[TestMethod] | ||
public void TestMethod() | ||
{ | ||
MySqlServer database = MySqlServer.Instance; | ||
|
||
database.ExecuteNonQuery("insert into testTable (`id`, `value`) VALUES (2, 'test value')"); | ||
|
||
using (MySqlDataReader reader = database.ExecuteReader("select * from testTable WHERE id = 2")) | ||
{ | ||
reader.Read(); | ||
|
||
Assert.AreEqual("test value", reader.GetString("value"), "Inserted and read string should match"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace MySql.Server | ||
{ | ||
internal class BaseDirHelper | ||
{ | ||
static string baseDir; | ||
public static string GetBaseDir() | ||
{ | ||
if (baseDir == null) | ||
{ | ||
baseDir = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent.FullName.ToString(); | ||
} | ||
|
||
return baseDir; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
|
||
namespace MySql.Server | ||
{ | ||
/* | ||
* Static class used to serve connection strings | ||
*/ | ||
internal class DBTestConnectionStringFactory : IDBConnectionStringFactory | ||
{ | ||
/* | ||
* Returns a connection string of the server | ||
*/ | ||
public string Server(){ | ||
// return "Server=localhost;Protocol=pipe;"; | ||
return "Server=" + "127.0.0.1" + ";Protocol=pipe;"; | ||
} | ||
|
||
/* | ||
* Returns a connection string of the default database (the test server) | ||
*/ | ||
public string Database() | ||
{ | ||
return "Server=" + "127.0.0.1" + ";Database=testserver;Protocol=pipe;"; | ||
} | ||
|
||
/** | ||
* Returns a connection string of a specific database | ||
*/ | ||
public string Database(string databaseName) | ||
{ | ||
return "Server=" + "127.0.0.1" + ";Database=" + databaseName + ";Protocol=pipe;"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MySql.Server | ||
{ | ||
internal interface IDBConnectionStringFactory | ||
{ | ||
string Server(); | ||
string Database(); | ||
string Database(string databaseName); | ||
} | ||
} |
Oops, something went wrong.