From 17612c08da93c75d4c941a643bc7602c18f351d8 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 23 Feb 2019 20:15:36 +0200 Subject: Implemented auto DTO generation. Implemented mapping of DTO <=> Observables. Organization of unit tests. Removed DELETED from ADDRESS & CONTACT. --- .../Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs | 42 +++ .../Tango.UnitTesting/Core/TemporaryManager_TST.cs | 34 ++ .../Tango.UnitTesting/Embroidery/Embroidery_TST.cs | 31 ++ .../Tango.UnitTesting/Embroidery_TST.cs | 31 -- .../Integration/JobDescriptionFile_TST.cs | 65 ++++ .../Tango.UnitTesting/Integration_TST.cs | 65 ---- .../Tango.UnitTesting/Logging/Parsing_TST.cs | 34 ++ .../Visual_Studio/Tango.UnitTesting/Logging_TST.cs | 34 -- .../MachineService/MachineStudio_Controller_TST.cs | 2 +- .../MachineService/PPC_Controller_TST.cs | 6 +- .../Tango.UnitTesting/MachineService_TST.cs | 65 ---- .../MachineStudio/MachineStudio_TST.cs | 147 ++++++++ .../Tango.UnitTesting/MachineStudio_TST.cs | 147 -------- .../Tango.UnitTesting/Protobuf_TST.cs | 132 ------- .../SQLExaminer/SQLExaminer_TST.cs | 395 +++++++++++++++++++++ .../Tango.UnitTesting/SQLExaminer_TST.cs | 395 --------------------- .../Tango.UnitTesting/Scripting_TST.cs | 45 --- .../Visual_Studio/Tango.UnitTesting/TFS/TFS_TST.cs | 145 ++++++++ .../Visual_Studio/Tango.UnitTesting/TFS_TST.cs | 145 -------- .../Tango.UnitTesting/Tango.UnitTesting.csproj | 21 +- .../Tango.UnitTesting/Temporary_TST.cs | 34 -- 21 files changed, 907 insertions(+), 1108 deletions(-) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Core/TemporaryManager_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Embroidery/Embroidery_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/Embroidery_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Integration/JobDescriptionFile_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/Integration_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/MachineStudio/MachineStudio_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/MachineStudio_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/Protobuf_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/SQLExaminer/SQLExaminer_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/Scripting_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/TFS/TFS_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/TFS_TST.cs delete mode 100644 Software/Visual_Studio/Tango.UnitTesting/Temporary_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs new file mode 100644 index 000000000..58a05ee83 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/BL/DTO_TST.cs @@ -0,0 +1,42 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Builders; +using Tango.BL.DTO; +using System.Data.Entity; +using DeepEqual.Syntax; + +namespace Tango.UnitTesting.BL +{ + [TestClass] + [TestCategory("BL - DTO")] + public class DTO_TST + { + /// + /// Creates the DTO from observable and map DTO to observable test. + /// + [TestMethod] + public void Create_DTO_From_Observable_and_Map_DTO_To_Observable() + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var config = new ConfigurationBuilder(db).SetFirst().WithIdsPacks().Build(); + var configDTO = ConfigurationDTO.FromObservable(config); + + Assert.IsTrue(configDTO.Equals(config)); + + configDTO.MapToObservable(config); + + Assert.IsTrue(configDTO.Equals(config)); + + config = configDTO.ToObservable(); + + Assert.IsTrue(configDTO.Equals(config)); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Core/TemporaryManager_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Core/TemporaryManager_TST.cs new file mode 100644 index 000000000..b017b4e11 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Core/TemporaryManager_TST.cs @@ -0,0 +1,34 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Core.IO; + +namespace Tango.UnitTesting.Core +{ + [TestClass] + [TestCategory("Temporary Files & Folders")] + public class TemporaryManager_TST + { + [TestMethod] + public void Create_Temporary_Folder_And_Files_Display_And_Delete() + { + TemporaryManager manager = TemporaryManager.Default; + + var folder = manager.CreateFolder(); + + folder.Display(); + + Thread.Sleep(1000); + + for (int i = 0; i < 10; i++) + { + var file = folder.CreateFile(); + Thread.Sleep(1000); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Embroidery/Embroidery_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Embroidery/Embroidery_TST.cs new file mode 100644 index 000000000..cf72cd2c5 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Embroidery/Embroidery_TST.cs @@ -0,0 +1,31 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR; +using Tango.PMR.Embroidery; + +namespace Tango.UnitTesting.Embroidery +{ + [TestClass] + [TestCategory("Embroidery")] + public class Embroidery_TST + { + [DllImport("Tango.Embroidery.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "AnalyzeEmbroideryFile")] + public static extern int AnalyzeEmbroideryFile(IntPtr data, int size, ref IntPtr output); + + [TestMethod] + public void Analyze_Embroidery_File() + { + AnalyzeInput input = new AnalyzeInput(); + input.FilePath = "C:\\Users\\Roy\\Desktop\\RGB_Strips.pes"; + + + NativePMR nativePMR = new NativePMR(AnalyzeEmbroideryFile); + AnalyzeOutput output = nativePMR.Invoke(input); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Embroidery_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Embroidery_TST.cs deleted file mode 100644 index ccd71fdc8..000000000 --- a/Software/Visual_Studio/Tango.UnitTesting/Embroidery_TST.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using Tango.PMR; -using Tango.PMR.Embroidery; - -namespace Tango.UnitTesting -{ - [TestClass] - [TestCategory("Embroidery")] - public class Embroidery_TST - { - [DllImport("Tango.Embroidery.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "AnalyzeEmbroideryFile")] - public static extern int AnalyzeEmbroideryFile(IntPtr data, int size, ref IntPtr output); - - [TestMethod] - public void Analyze_Embroidery_File() - { - AnalyzeInput input = new AnalyzeInput(); - input.FilePath = "C:\\Users\\Roy\\Desktop\\RGB_Strips.pes"; - - - NativePMR nativePMR = new NativePMR(AnalyzeEmbroideryFile); - AnalyzeOutput output = nativePMR.Invoke(input); - } - } -} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Integration/JobDescriptionFile_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Integration/JobDescriptionFile_TST.cs new file mode 100644 index 000000000..506d1dc94 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Integration/JobDescriptionFile_TST.cs @@ -0,0 +1,65 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Operation; +using Tango.PMR.Printing; + + +namespace Tango.UnitTesting.Integration +{ + [TestClass] + [TestCategory("Integration")] + public class JobDescriptionFile_TST + { + [TestMethod] + public void Write_Read_Validate_JobDescriptionFile() + { + Random rnd = new Random(); + + List segments = new List(); + + for (int i = 0; i < 10; i++) + { + JobSegment seg = new JobSegment(); + seg.Length = i; + seg.Name = "Segment " + rnd.Next(); + + for (int j = 0; j < 10; j++) + { + JobBrushStop stop = new JobBrushStop(); + stop.Index = j; + stop.OffsetMeters = j; + stop.OffsetPercent = j; + + for (int k = 0; k < 6; k++) + { + stop.Dispensers.Add(new JobDispenser() + { + DispenserLiquidType = DispenserLiquidType.Cyan, + Index = k, + NanolitterPerSecond = k, + }); + } + + seg.BrushStops.Add(stop); + } + + + + segments.Add(seg); + } + + JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(segments); + MemoryStream ms = jobDescriptionFile.ToStream(); + ms.Position = 0; + var read_segments = JobDescriptionFile.ReadJobDescriptionFile(ms); + ms.Dispose(); + + Assert.IsTrue(Helper.IsDeepEqual(segments, read_segments)); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Integration_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Integration_TST.cs deleted file mode 100644 index cbfc521bd..000000000 --- a/Software/Visual_Studio/Tango.UnitTesting/Integration_TST.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Integration.Operation; -using Tango.PMR.Printing; - - -namespace Tango.UnitTesting -{ - [TestClass] - [TestCategory("Integration")] - public class Integration_TST - { - [TestMethod] - public void _Write_Read_Validate_JobDescriptionFile() - { - Random rnd = new Random(); - - List segments = new List(); - - for (int i = 0; i < 10; i++) - { - JobSegment seg = new JobSegment(); - seg.Length = i; - seg.Name = "Segment " + rnd.Next(); - - for (int j = 0; j < 10; j++) - { - JobBrushStop stop = new JobBrushStop(); - stop.Index = j; - stop.OffsetMeters = j; - stop.OffsetPercent = j; - - for (int k = 0; k < 6; k++) - { - stop.Dispensers.Add(new JobDispenser() - { - DispenserLiquidType = DispenserLiquidType.Cyan, - Index = k, - NanolitterPerSecond = k, - }); - } - - seg.BrushStops.Add(stop); - } - - - - segments.Add(seg); - } - - JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(segments); - MemoryStream ms = jobDescriptionFile.ToStream(); - ms.Position = 0; - var read_segments = JobDescriptionFile.ReadJobDescriptionFile(ms); - ms.Dispose(); - - Assert.IsTrue(Helper.IsDeepEqual(segments, read_segments)); - } - } -} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs new file mode 100644 index 000000000..57856f9cb --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Logging/Parsing_TST.cs @@ -0,0 +1,34 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Logging; +using Tango.Logging; + +namespace Tango.UnitTesting.Logging +{ + [TestClass] + [TestCategory("Logging")] + public class Parsing_TST + { + [TestMethod] + public void Parse_Application_Logs() + { + ApplicationLogFileParser parser = new ApplicationLogFileParser(); + var logFiles = parser.GetLogFiles(); + var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); + var logs = parser.Parse(logFile); + } + + [TestMethod] + public void Parse_Embedded_Logs() + { + EmbeddedLogFileParser parser = new EmbeddedLogFileParser(); + var logFiles = parser.GetLogFiles(); + var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); + var logs = parser.Parse(logFile); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs deleted file mode 100644 index c4a697715..000000000 --- a/Software/Visual_Studio/Tango.UnitTesting/Logging_TST.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Integration.Logging; -using Tango.Logging; - -namespace Tango.UnitTesting -{ - [TestClass] - [TestCategory("Logging")] - public class Logging_TST - { - [TestMethod] - public void Parse_Application_Logs() - { - ApplicationLogFileParser parser = new ApplicationLogFileParser(); - var logFiles = parser.GetLogFiles(); - var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); - var logs = parser.Parse(logFile); - } - - [TestMethod] - public void Parse_Embedded_Logs() - { - EmbeddedLogFileParser parser = new EmbeddedLogFileParser(); - var logFiles = parser.GetLogFiles(); - var logFile = logFiles.OrderByDescending(x => x.DateTime).First(); - var logs = parser.Parse(logFile); - } - } -} 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 8a126df2e..56a57ab92 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs @@ -6,7 +6,7 @@ using Tango.MachineStudio.Common.Web; using Tango.Transport.Web; using System.Linq; -namespace Tango.UnitTesting.Web +namespace Tango.UnitTesting.MachineService { [TestClass] [TestCategory("Machine Service - Machine Studio")] diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs index 23ab74f3b..7c3d497b8 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs @@ -7,7 +7,7 @@ using System.Linq; using Tango.PPC.Common.Web; using Tango.Core.IO; -namespace Tango.UnitTesting.Web +namespace Tango.UnitTesting.MachineService { [TestClass] [TestCategory("Machine Service - PPC")] @@ -62,8 +62,8 @@ namespace Tango.UnitTesting.Web }).GetAwaiter().GetResult(); //Now get DEV data source using the machine studio client in order to validate the setup information. - MachineStudio.Common.Web.MachineStudioWebClient msClient = new MachineStudio.Common.Web.MachineStudioWebClient(address, null); - var res6 = msClient.Login(new MachineStudio.Common.Web.LoginRequest() + Tango.MachineStudio.Common.Web.MachineStudioWebClient msClient = new Tango.MachineStudio.Common.Web.MachineStudioWebClient(address, null); + var res6 = msClient.Login(new Tango.MachineStudio.Common.Web.LoginRequest() { Email = "TestUser@twine-s.com", Password = "ASJH_asdjkl1234", diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs deleted file mode 100644 index 455a45895..000000000 --- a/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Tango.Transport.Web; -using Tango.Web.Authentication; - -namespace Tango.UnitTesting -{ - [TestClass] - [TestCategory("Machine Service")] - public class MachineService_TST - { - private class TokenObject : IEquatable - { - public String Value { get; set; } - - public bool Equals(TokenObject other) - { - return Value == other.Value; - } - } - - [TestMethod] - public void Test_Tokens_Manager() - { - TokensManager tokensManager = new TokensManager(); - - TokenObject t1 = new TokenObject(); - t1.Value = "Roy"; - - TokenObject t2 = new TokenObject(); - t2.Value = "Sagi"; - - String token1 = tokensManager.GetOrCreate(t1).AccessToken; - String token2 = tokensManager.GetOrCreate(t2).AccessToken; - - Assert.AreEqual(tokensManager.GetTokenObject(token1), t1); - Assert.AreEqual(tokensManager.GetTokenObject(token2), t2); - - TokenObject t3 = new TokenObject(); - t3.Value = "Roy"; - - String token3 = tokensManager.GetOrCreate(t3).AccessToken; - Assert.AreEqual(token3, token1); - Assert.AreEqual(tokensManager.GetTokenObject(token1), tokensManager.GetTokenObject(token3)); - - TokenObject tOld = new TokenObject() - { - Value = "Expired Token" - }; - - tokensManager.ExpirationTime = TimeSpan.FromSeconds(2); - - Thread.Sleep(2000); - - String recent_token = tokensManager.GetOrCreate(tOld).AccessToken; - - Thread.Sleep(1000); - - tokensManager.Validate(recent_token); - - Assert.ThrowsException(() => tokensManager.Validate(token1)); - } - } -} diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineStudio/MachineStudio_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineStudio/MachineStudio_TST.cs new file mode 100644 index 000000000..b8c374d4f --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineStudio/MachineStudio_TST.cs @@ -0,0 +1,147 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.MachineStudio.Common.Automation; +using TestStack.White; +using TestStack.White.Factory; +using TestStack.White.UIItems; +using TestStack.White.UIItems.Finders; +using TestStack.White.UIItems.ListBoxItems; +using TestStack.White.UIItems.WindowItems; +using TestStack.White.WindowsAPI; + +namespace Tango.UnitTesting.MachineStudio +{ + public static class AutomationExtensions + { + public static T GetByAutomationId(this Window window, String id) where T : IUIItem + { + return window.Get(SearchCriteria.ByAutomationId(id)); + } + } + + [TestClass] + [TestCategory("Machine Studio")] + public class MachineStudio_TST + { + private Window GetMachineStudioWindow() + { + var app = Application.AttachOrLaunch(new System.Diagnostics.ProcessStartInfo() { FileName = Helper.GetMachineStudioPath() }); + var window = app.GetWindow("Tango", InitializeOption.NoCache); + return window; + } + + private Window GetCurrentDialogWindow() + { + var app = Application.AttachOrLaunch(new System.Diagnostics.ProcessStartInfo() { FileName = Helper.GetMachineStudioPath() }); + return app.GetWindows().LastOrDefault(x => x.IsModal); + } + + private void Kill(int delay = 4000) + { + Thread.Sleep(delay); + var app = Application.AttachOrLaunch(new System.Diagnostics.ProcessStartInfo() { FileName = Helper.GetMachineStudioPath() }); + app.Kill(); + } + + private void Wait(int delay = 1000) + { + Thread.Sleep(delay); + } + + private void ConfirmMessageBox() + { + Wait(); + var dialog = GetCurrentDialogWindow(); + + if (dialog != null) + { + dialog.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN); + } + } + + [TestMethod] + public void Login() + { + var window = GetMachineStudioWindow(); + + window.WaitTill(() => window.GetByAutomationId