From 3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 6 Dec 2017 10:11:45 +0200 Subject: Moved ExtendedObject & RelayCommand to Core. CodeGeneration EntityCodeFile working + cycle reference! --- .../Tango.UnitTesting/CodeGeneration_TST.cs | 88 ++++++++++++++++++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 6 ++ 2 files changed, 94 insertions(+) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') 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.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.DalNameToStandardName(field.Name); + codeField.Description = field.Name.Replace("_", " ").ToLower(); + + + if (field.PropertyType.IsGenericType) + { + codeField.Type = String.Format("ObservableCollection<{0}>", Singularize(ObservableEntity.DalNameToStandardName(field.PropertyType.GenericTypeArguments.Single().Name))); + codeField.Construct = true; + } + else + { + if (field.PropertyType.IsClass && field.PropertyType != typeof(String)) + { + codeField.Type = Singularize(ObservableEntity.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 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); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 79dab4c0d..f3f5a1abb 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -61,6 +61,7 @@ + ..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net46\System.Data.SQLite.dll @@ -82,12 +83,17 @@ + + + {caedae94-11ed-473c-888a-268a6d38cd20} + Tango.CodeGeneration + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core -- cgit v1.3.1