aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs')
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs
new file mode 100644
index 000000000..b5240bd5f
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs
@@ -0,0 +1,88 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Tango.DAL.Remote.DB;
+using Tango.DAL.Remote.ObservableEntities;
+using Tango.Settings;
+using System.Linq;
+using System.Collections;
+using Tango.CodeGeneration;
+using System.Data.Entity;
+using System.Collections.Generic;
+using System.IO;
+using System.Data.Entity.Design.PluralizationServices;
+
+namespace Tango.UnitTesting
+{
+ [TestClass]
+ [TestCategory("Code Generation")]
+ public class CodeGeneration_TST
+ {
+ [TestMethod]
+ public void Generate_DAL_Observable_Entities()
+ {
+ String tempPath = Helper.GetTempFolderPath();
+
+ foreach (var table in typeof(RemoteDB).GetProperties().Where(x => typeof(IEnumerable).IsAssignableFrom(x.PropertyType)))
+ {
+ EntityCodeFile codeFile = new EntityCodeFile(Singularize(ObservableEntity<Object>.DalNameToStandardName(table.Name)))
+ {
+ TableName = Singularize(table.Name)
+ };
+
+ foreach (var field in table.PropertyType.GenericTypeArguments.First().GetProperties().Skip(4))
+ {
+ EntityCodeFileField codeField = new EntityCodeFileField();
+ codeField.FieldName = field.Name;
+ codeField.Name = ObservableEntity<Object>.DalNameToStandardName(field.Name);
+ codeField.Description = field.Name.Replace("_", " ").ToLower();
+
+
+ if (field.PropertyType.IsGenericType)
+ {
+ codeField.Type = String.Format("ObservableCollection<{0}>", Singularize(ObservableEntity<Object>.DalNameToStandardName(field.PropertyType.GenericTypeArguments.Single().Name)));
+ codeField.Construct = true;
+ }
+ else
+ {
+ if (field.PropertyType.IsClass && field.PropertyType != typeof(String))
+ {
+ codeField.Type = Singularize(ObservableEntity<Object>.DalNameToStandardName(field.PropertyType.Name));
+ codeField.Construct = true;
+ }
+ else
+ {
+ codeField.Type = field.PropertyType.Name;
+ }
+ }
+ codeFile.Fields.Add(codeField);
+ }
+
+ String code = codeFile.GenerateCode();
+
+ File.WriteAllText(Path.Combine(tempPath, codeFile.Name + ".cs"), code);
+ }
+
+ Helper.ShowInExplorer(tempPath);
+ }
+
+ [TestMethod]
+ public void Load_Observable_Machines()
+ {
+ using (RemoteDB db = new RemoteDB(SettingsManager.Default.DataBase.SQLServerAddress, false))
+ {
+ List<Machine> machines = db.MACHINES.ToList().Select(x => new Machine(x)).ToList();
+
+ foreach (var machine in machines)
+ {
+
+ }
+ }
+ }
+
+ private String Singularize(String text)
+ {
+ var serv = PluralizationService.CreateService(new System.Globalization.CultureInfo("en-us"));
+ return serv.Singularize(text);
+ }
+ }
+}