Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpdk committed Jul 28, 2015
1 parent ff1a44d commit 45d9465
Show file tree
Hide file tree
Showing 13 changed files with 855 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/tempServer

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

Expand Down
52 changes: 52 additions & 0 deletions Example.cs
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");
}
}
}
}
20 changes: 20 additions & 0 deletions Library/BaseDirHelper.cs
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;
}
}
}
34 changes: 34 additions & 0 deletions Library/DBTestConnectionStringFactory.cs
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;";
}
}
}
15 changes: 15 additions & 0 deletions Library/IDBConnectionStringFactory.cs
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);
}
}
Loading

0 comments on commit 45d9465

Please sign in to comment.