From 7060dc80c707fc0441ff69fe4f899107cb3f6fc1 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 27 Nov 2017 20:35:08 +0200 Subject: Split DAL to DAl.Local & DAL.Remote due to ambiguity of table names in EF. Implemented Unit testing for SQLite & SQL Server connections. --- .../Visual_Studio/Tango.UnitTesting/App.config | 20 +++++++ .../Visual_Studio/Tango.UnitTesting/DAL_TST.cs | 64 ++++++++++++++++++++++ Software/Visual_Studio/Tango.UnitTesting/Helper.cs | 9 +++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 30 ++++++++++ .../Tango.UnitTesting/packages.config | 5 ++ 5 files changed, 128 insertions(+) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/App.config create mode 100644 Software/Visual_Studio/Tango.UnitTesting/DAL_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/Tango.UnitTesting/App.config b/Software/Visual_Studio/Tango.UnitTesting/App.config new file mode 100644 index 000000000..901eeb586 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/App.config @@ -0,0 +1,20 @@ + + + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.UnitTesting/DAL_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/DAL_TST.cs new file mode 100644 index 000000000..b56f04c70 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/DAL_TST.cs @@ -0,0 +1,64 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.DAL; +using System.Linq; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("DAL")] + public class DAL_TST + { + [TestMethod] + public void Validate_Server_SQLServer_Connection() + { + Guid guid = Guid.NewGuid(); + + using (var db = new DAL.Remote.DB.RemoteDB("LOCALHOST\\SQLEXPRESS", false)) + { + var action = new DAL.Remote.DB.ACTION(); + action.CODE = 1; + action.NAME = "Action 1"; + action.DESCRIPTION = "Description 1"; + action.GUID = guid; + action.LAST_UPDATED = DateTime.Now; + + db.ACTIONS.Add(action); + db.SaveChanges(); + } + + using (var db = new DAL.Remote.DB.RemoteDB("LOCALHOST\\SQLEXPRESS", false)) + { + var action = db.ACTIONS.Single(x => x.GUID == guid); + db.ACTIONS.Remove(action); + db.SaveChanges(); + } + } + + [TestMethod] + public void Validate_Local_SQLite_Connection() + { + String guid = Guid.NewGuid().ToString(); + + using (var db = new DAL.Local.DB.LocalDB(Helper.GetSQLiteFilePath())) + { + var action = new DAL.Local.DB.ACTION(); + action.CODE = 1; + action.NAME = "Action 1"; + action.DESCRIPTION = "Description 1"; + action.GUID = guid; + + db.ACTIONS.Add(action); + db.SaveChanges(); + } + + using (var db = new DAL.Local.DB.LocalDB(Helper.GetSQLiteFilePath())) + { + var actions = db.ACTIONS.ToList(); + var action = db.ACTIONS.Single(x => x.GUID == guid); + db.ACTIONS.Remove(action); + db.SaveChanges(); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs index ece74d3f3..21e36168c 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs @@ -34,6 +34,15 @@ namespace Tango.UnitTesting return Path.GetFullPath(@"..\..\..\PMR\Messages\"); } + /// + /// Gets the SQLite database file path in DB folder. + /// + /// + public static String GetSQLiteFilePath() + { + return Path.GetFullPath(@"..\..\..\DB\Tango.db"); + } + /// /// Initializes the logging manager. /// diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 02a500341..494981db1 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -40,6 +40,12 @@ 4 + + ..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll @@ -53,7 +59,19 @@ ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net46\System.Data.SQLite.dll + + + ..\packages\System.Data.SQLite.EF6.1.0.106.0\lib\net46\System.Data.SQLite.EF6.dll + True + + + ..\packages\System.Data.SQLite.Linq.1.0.106.0\lib\net46\System.Data.SQLite.Linq.dll + True + @@ -62,8 +80,10 @@ + + @@ -71,6 +91,14 @@ {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core + + {0e0eef3e-8f4e-4f23-9d19-479fd8d76c12} + Tango.DAL.Local + + + {38197109-8610-4d3f-92b9-16d48df94d7c} + Tango.DAL.Remote + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} Tango.Logging @@ -96,6 +124,8 @@ + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.UnitTesting/packages.config b/Software/Visual_Studio/Tango.UnitTesting/packages.config index d3cd9d043..3ffe10b39 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/packages.config +++ b/Software/Visual_Studio/Tango.UnitTesting/packages.config @@ -1,7 +1,12 @@  + + + + + \ No newline at end of file -- cgit v1.3.1