aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-04-23 22:25:54 +0300
committerShlomo Hecht <shlomo@twine-s.com>2019-04-23 22:25:54 +0300
commitebcb9ce27131e4bbd14c96b5f897a67bc752aaeb (patch)
tree293aee8b1751ce7fce542645722c0f1a96b73097 /Software/Visual_Studio/Tango.UnitTesting
parent52967e858bd52621208f6360e84f4c47ec435816 (diff)
parent636ad730569dfef1a4ee04c8d716d510bcc47ee1 (diff)
downloadTango-ebcb9ce27131e4bbd14c96b5f897a67bc752aaeb.tar.gz
Tango-ebcb9ce27131e4bbd14c96b5f897a67bc752aaeb.zip
merge alarm handling from remote
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/App.config26
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Helper.cs9
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs14
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs86
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmpbin0 -> 140174 bytes
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmpbin0 -> 1351734 bytes
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs121
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj27
8 files changed, 268 insertions, 15 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/App.config b/Software/Visual_Studio/Tango.UnitTesting/App.config
index 074da9ac0..1261bcbe9 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/App.config
+++ b/Software/Visual_Studio/Tango.UnitTesting/App.config
@@ -63,7 +63,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
@@ -71,27 +71,27 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
+ <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
@@ -105,6 +105,18 @@
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
+ </dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
diff --git a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs
index 6a4f860b9..0498935ae 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs
+++ b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs
@@ -28,6 +28,15 @@ namespace Tango.UnitTesting
}
/// <summary>
+ /// Gets the absolute path to the 'Resources' folder.
+ /// </summary>
+ /// <returns></returns>
+ public static String GetResourcePath()
+ {
+ return Path.GetFullPath(@"..\..\..\Resources\");
+ }
+
+ /// <summary>
/// Gets the PMR (Protobuf Messages Repository) path.
/// </summary>
/// <returns></returns>
diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs
index d4585388a..e30cd6d77 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs
+++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs
@@ -22,14 +22,14 @@ namespace Tango.UnitTesting.MachineService
IWebTransportClient client = new WebTransportClient();
- var res1 = client.PostJson<LoginRequest, LoginResponse>($"{address}/api/MachineStudio/Login", new LoginRequest()
- {
- Email = "TestUser@twine-s.com",
- Password = "ASJH_asdjkl1234",
- Version = "1.0.0.0"
- }).Result;
+ //var res1 = client.PostJson<LoginRequest, LoginResponse>($"{address}/api/MachineStudio/Login", new LoginRequest()
+ //{
+ // Email = "TestUser@twine-s.com",
+ // Password = "ASJH_asdjkl1234",
+ // Version = "1.0.0.0"
+ //}).Result;
- String token = res1.AccessToken;
+ String token = "1234";
client.AuthenticationToken = token;
var res2 = client.PostJson<CheckForUpdatesRequest, CheckForUpdatesResponse>($"{address}/api/MachineStudio/CheckForUpdates", new CheckForUpdatesRequest()
diff --git a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs
new file mode 100644
index 000000000..073841997
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs
@@ -0,0 +1,86 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.IO;
+using Tango.Pulse;
+
+namespace Tango.UnitTesting.Pulse
+{
+ [TestClass]
+ [TestCategory("Pulse")]
+ public class Pulse_TST
+ {
+ [TestMethod]
+ public void Validate_Reading_Writing()
+ {
+ String abcFile = Path.Combine(Helper.GetResourcePath(), "Pulse", "ABC.dst");
+
+ TwnFile twnFile = new TwnFile();
+ twnFile.Name = "My design";
+ twnFile.NumberOfCopies = 1;
+ twnFile.MediaID = 0;
+ twnFile.SpoolingMethod = SpoolingMethods.SpoolPerSegment;
+
+ Bitmap thumbnail = new Bitmap(1280, 720);
+ using (Graphics g = Graphics.FromImage(thumbnail))
+ {
+ g.Clear(Color.Transparent);
+ g.DrawString("My design", new Font(new FontFamily("Arial"), 70), Brushes.Red, 1280 / 2, 720 / 2);
+ }
+ twnFile.Thumbnail = thumbnail;
+
+ twnFile.EmbroideryFileFormat = "dst";
+ twnFile.EmbroideryFile = File.ReadAllBytes(abcFile);
+
+ //Add gradient segment.
+ TwnSegment gradientSegment = new TwnSegment();
+ gradientSegment.Length = 10; //10 centimeters.
+ gradientSegment.BrushStops.Add(new TwnStop(255, 0, 0, 0)); //0%
+ gradientSegment.BrushStops.Add(new TwnStop(0, 0, 255, 1)); //100%
+ twnFile.Segments.Add(gradientSegment);
+
+ //Add solid segment.
+ TwnSegment solidSegment = new TwnSegment();
+ solidSegment.Length = 20;
+ solidSegment.BrushStops.Add(new TwnStop(0, 255, 0, 0));
+ twnFile.Segments.Add(solidSegment);
+
+ //Validate reading/writing.
+ using (MemoryStream ms = new MemoryStream())
+ {
+ twnFile.ToStream(ms);
+
+ ms.Position = 0;
+
+ TwnFile twnFile2 = TwnFile.FromStream(ms);
+
+ String serialized = JsonConvert.SerializeObject(twnFile, Formatting.Indented);
+
+ String deserialized = JsonConvert.SerializeObject(twnFile2, Formatting.Indented);
+
+ Assert.AreEqual(serialized, deserialized);
+ }
+ }
+
+ [TestMethod]
+ public void Read_Pulse_Sample_File()
+ {
+ String sampleFile = Path.Combine(Helper.GetResourcePath(), "Pulse", "test.twn");
+ TwnFile twnFile = TwnFile.FromFile(sampleFile);
+ var imgFile = TemporaryManager.Default.CreateFile(".png");
+
+ String json = twnFile.ToJsonString();
+
+ twnFile.Thumbnail.Save(imgFile, ImageFormat.Png);
+
+ Helper.ShowInExplorer(imgFile);
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp
new file mode 100644
index 000000000..1d48c010b
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp
Binary files differ
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmp b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmp
new file mode 100644
index 000000000..0135298a5
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmp
Binary files differ
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
new file mode 100644
index 000000000..59237b4a0
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
@@ -0,0 +1,121 @@
+using Google.Protobuf;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Core.IO;
+using Tango.CSV;
+using Tango.PMR.TCC;
+using Tango.TCC.BL;
+using Tango.TCC.BL.Entities;
+
+namespace Tango.UnitTesting.TCC
+{
+ [TestClass]
+ [TestCategory("TCC")]
+ public class TCC_TST
+ {
+ [TestMethod]
+ public void Detect()
+ {
+ var original_bitmap = Directory.GetCurrentDirectory() + "\\TCC\\TCC Resources\\bitmap.bmp";
+
+ using (ColorDetector detector = new ColorDetector())
+ {
+ DetectionInput input = new DetectionInput()
+ {
+ Number = 5,
+ Columns = 10,
+ Rows = 11,
+ TargetIndex = 99,
+ Bitmap = ByteString.CopyFrom(File.ReadAllBytes(original_bitmap)),
+ RequestColorMatrix = true,
+ RequestDebugImage = true,
+ };
+
+ var output = detector.Detect(input);
+
+ if (input.RequestDebugImage)
+ {
+ using (MemoryStream ms = new MemoryStream(output.DebugBitmap.ToArray()))
+ {
+ var outputBitmap = TemporaryManager.Default.CreateFile(".bmp");
+ outputBitmap.Persist = true;
+ ms.Position = 0;
+ Bitmap bmp = new Bitmap(ms);
+ bmp.Save(outputBitmap);
+ Process.Start(outputBitmap);
+ }
+ }
+
+ if (input.RequestColorMatrix)
+ {
+ using (Bitmap colorMatrixBmp = ColorDetector.DetectionOutputToImage(input, output, 300, 320))
+ {
+ var outputBitmap = TemporaryManager.Default.CreateFile(".bmp");
+ outputBitmap.Persist = true;
+ colorMatrixBmp.Save(outputBitmap);
+ Process.Start(outputBitmap);
+ }
+
+ var benchmarksCsvFile = TemporaryManager.Default.CreateFile(".csv");
+ benchmarksCsvFile.Persist = true;
+
+ using (CsvFile<DetectionColor> benchmarksRGB = new CsvFile<DetectionColor>(new CsvDestination(benchmarksCsvFile)))
+ {
+ foreach (var color in output.ColorMatrix)
+ {
+ benchmarksRGB.Append(color);
+ }
+ }
+
+ Helper.ShowInExplorer(benchmarksCsvFile);
+
+ Assert.IsTrue(output.Number == 15);
+ }
+ }
+ }
+
+ [TestMethod]
+ public void Test_Database()
+ {
+ using (TCCContext db = new TCCContext(new DataSource()
+ {
+ Address = "localhost\\SQLEXPRESS",
+ Catalog = "TCC",
+ IntegratedSecurity = true,
+ Type = DataSourceType.SQLServer,
+ }))
+ {
+ var device = db.Devices.FirstOrDefault();
+ Assert.IsNotNull(device);
+ db.SaveChanges();
+ }
+ }
+
+ private byte[] GetBitmapData(byte[] bitmap)
+ {
+ using (MemoryStream ms = new MemoryStream(bitmap))
+ {
+ ms.Position = 0;
+ Bitmap image = new Bitmap(ms);
+ Rectangle area = new Rectangle(0, 0, image.Width, image.Height);
+ BitmapData bitmapData = image.LockBits(area, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
+ int stride = bitmapData.Stride;
+ IntPtr ptr = bitmapData.Scan0;
+ int numBytes = bitmapData.Stride * image.Height;
+ byte[] rgbValues = new byte[numBytes];
+ Marshal.Copy(ptr, rgbValues, 0, numBytes);
+ return rgbValues;
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj
index d1bba995e..6fd23451d 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj
+++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj
@@ -102,6 +102,7 @@
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.108.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
+ <Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
@@ -123,9 +124,11 @@
<Compile Include="Logging\Parsing_TST.cs" />
<Compile Include="MachineService\PPC_Controller_TST.cs" />
<Compile Include="MachineStudio\MachineStudio_TST.cs" />
+ <Compile Include="Pulse\Pulse_TST.cs" />
<Compile Include="RemoteRunner_TST.cs" />
<Compile Include="SQLExaminer\SQLExaminer_TST.cs" />
<Compile Include="Core\TemporaryManager_TST.cs" />
+ <Compile Include="TCC\TCC_TST.cs" />
<Compile Include="TFS\TFS_TST.cs" />
<Compile Include="Outlook_TST.cs" />
<Compile Include="Embroidery\Embroidery_TST.cs" />
@@ -138,6 +141,12 @@
<Content Include="AdvancedInstaller\DemoProject\DemoProject.aip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Content Include="TCC\TCC Resources\bitmap.bmp">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="TCC\TCC Resources\bitmap_ok.bmp">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
@@ -174,6 +183,10 @@
<Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
<Name>Tango.Core</Name>
</ProjectReference>
+ <ProjectReference Include="..\Tango.CSV\Tango.CSV.csproj">
+ <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project>
+ <Name>Tango.CSV</Name>
+ </ProjectReference>
<ProjectReference Include="..\Tango.DAL.Local\Tango.DAL.Local.csproj">
<Project>{0e0eef3e-8f4e-4f23-9d19-479fd8d76c12}</Project>
<Name>Tango.DAL.Local</Name>
@@ -202,6 +215,10 @@
<Project>{40073806-914e-4e78-97ab-fa9639308ebe}</Project>
<Name>Tango.Protobuf</Name>
</ProjectReference>
+ <ProjectReference Include="..\Tango.Pulse\Tango.Pulse.csproj">
+ <Project>{8435223D-DB6B-45E3-A08B-45B7416F8481}</Project>
+ <Name>Tango.Pulse</Name>
+ </ProjectReference>
<ProjectReference Include="..\Tango.Scripting\Tango.Scripting.csproj">
<Project>{401989e7-ae1e-4002-b0ee-9a9f63740b97}</Project>
<Name>Tango.Scripting</Name>
@@ -230,6 +247,14 @@
<Project>{5001990f-977b-48ff-b217-0236a5022ad8}</Project>
<Name>Tango.Web</Name>
</ProjectReference>
+ <ProjectReference Include="..\TCC\Tango.TCC.BL\Tango.TCC.BL.csproj">
+ <Project>{f209fae8-73f9-441b-97f4-0844a0279390}</Project>
+ <Name>Tango.TCC.BL</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\TCC\Tango.TCC.OpenCV.DLL\Tango.TCC.OpenCV.DLL.csproj">
+ <Project>{5d0d4053-cab3-4a4a-929e-37a76483bc22}</Project>
+ <Name>Tango.TCC.OpenCV.DLL</Name>
+ </ProjectReference>
<ProjectReference Include="..\Utilities\Tango.DBObservablesGenerator.CLI\Tango.DBObservablesGenerator.CLI.csproj">
<Project>{ebb7cb9f-6af2-456b-a5dd-1b136b605d90}</Project>
<Name>Tango.DBObservablesGenerator.CLI</Name>
@@ -264,7 +289,7 @@
<Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file