diff options
| author | Roy <roy.mail.net@gmail.com> | 2017-12-06 10:11:45 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2017-12-06 10:11:45 +0200 |
| commit | 3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e (patch) | |
| tree | def622f54dff1dfc0820ed8fdd96edad98c05ec3 /Software/Visual_Studio/Tango.UnitTesting | |
| parent | 3689238cb9ca77cbd7fa34dbd15003af87266e36 (diff) | |
| download | Tango-3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e.tar.gz Tango-3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e.zip | |
Moved ExtendedObject & RelayCommand to Core.
CodeGeneration EntityCodeFile working + cycle reference!
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/CodeGeneration_TST.cs | 88 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj | 6 |
2 files changed, 94 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); + } + } +} 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 @@ <Reference Include="System" /> <Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.Core" /> + <Reference Include="System.Data.Entity.Design" /> <Reference Include="System.Data.SQLite, Version=1.0.106.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL"> <HintPath>..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net46\System.Data.SQLite.dll</HintPath> </Reference> @@ -82,12 +83,17 @@ <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="DAL_TST.cs" /> <Compile Include="Synchronization_TST.cs" /> + <Compile Include="CodeGeneration_TST.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> <None Include="packages.config" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\Tango.CodeGeneration\Tango.CodeGeneration.csproj"> + <Project>{caedae94-11ed-473c-888a-268a6d38cd20}</Project> + <Name>Tango.CodeGeneration</Name> + </ProjectReference> <ProjectReference Include="..\Tango.Core\Tango.Core.csproj"> <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> |
