diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-06-04 09:57:10 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-06-04 09:57:10 +0300 |
| commit | eeba1f2f7571dc5bfc299444d99cf643677698c5 (patch) | |
| tree | 030ed21787fd79635d65106ba81e19b2a25ec578 /Software/Visual_Studio/Tango.UnitTesting | |
| parent | 7e98f62f4a3ef6715206311adde99572663a22a5 (diff) | |
| parent | acf120606f7495bd132c0250fccb1b975e9660da (diff) | |
| download | Tango-eeba1f2f7571dc5bfc299444d99cf643677698c5.tar.gz Tango-eeba1f2f7571dc5bfc299444d99cf643677698c5.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
3 files changed, 114 insertions, 29 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs index e09b17149..67252f914 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs @@ -44,6 +44,15 @@ namespace Tango.UnitTesting } /// <summary> + /// Gets the tango build path. + /// </summary> + /// <returns></returns> + public static String GetBuildPath() + { + return Path.GetFullPath(@"..\..\Build\Debug"); + } + + /// <summary> /// Gets the SQLite database file path in DB folder. /// </summary> /// <returns></returns> diff --git a/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs new file mode 100644 index 000000000..21bdf3295 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs @@ -0,0 +1,97 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Transport; +using Tango.Transport.Transporters; +using Tango.Transport.Adapters; +using Tango.PMR.IO; +using Tango.PMR; +using Google.Protobuf; +using Tango.Transport.Discovery; +using Tango.PMR.Discovery; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("Remote Runner")] + public class RemoteRunner_TST + { + [TestMethod] + public void Run_Remote_Runner_Connect_Upload_And_Execute_Process() + { + Process runner = Process.Start(Path.Combine(Helper.GetBuildPath(), "Tango.RemoteRunner.UI.exe")); + runner.WaitForInputIdle(); + + Thread.Sleep(2000); + + UdpDiscoveryClient<BasicDiscoveryMessage> discoveryClient = new UdpDiscoveryClient<BasicDiscoveryMessage>(2018); + var discoveryResponse = discoveryClient.Discover().Result; + + ITransportAdapter adapter = new TcpTransportAdapter(discoveryResponse.Address, discoveryResponse.Message.Port); + ITransporter transporter = new BasicTransporter(adapter); + transporter.Connect().Wait(); + + Thread.Sleep(1000); + + String uploadFileName = "RemoteRunnerExeTest.zip"; + String executeFileName = "RemoteRunnerExeTest.exe"; + + FileInfo exeFile = new FileInfo(Helper.GetResourcePath(uploadFileName)); + + var uploadResponse = transporter.SendRequest<FileUploadRequest, FileUploadResponse>(new FileUploadRequest() + { + FileName = uploadFileName, + Length = exeFile.Length, + }).Result.Message; + + int currentFilePosition = 0; + + do + { + using (FileStream fs = new FileStream(exeFile.FullName, FileMode.Open)) + { + fs.Position = currentFilePosition; + + FileChunkUploadRequest chunkRequest = new FileChunkUploadRequest(); + chunkRequest.UploadID = uploadResponse.UploadID; + + long remaining = exeFile.Length - currentFilePosition; + + byte[] buffer = new byte[uploadResponse.MaxChunkLength > remaining ? uploadResponse.MaxChunkLength : remaining]; + fs.Read(buffer, 0, buffer.Length); + chunkRequest.Buffer = ByteString.CopyFrom(buffer); + + transporter.SendRequest<FileChunkUploadRequest, FileChunkUploadResponse>(chunkRequest).Wait(); + + currentFilePosition += buffer.Length; + } + + } while (currentFilePosition < exeFile.Length); + + Thread.Sleep(1000); + + var response = transporter.SendRequest<ExecuteProcessRequest, ExecuteProcessResponse>(new ExecuteProcessRequest() + { + UploadID = uploadResponse.UploadID, + FileName = executeFileName, + }, TimeSpan.FromSeconds(30)).Result.Message; + + Thread.Sleep(5000); + + transporter.SendRequest<KillProcessRequest, KillProcessResponse>(new KillProcessRequest() + { + ProcessID = response.ProcessID, + }).Wait(); + + transporter.Disconnect().Wait(); + + runner.Kill(); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index b01b6374b..d0fa1add9 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -54,6 +54,9 @@ <HintPath>..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> </Reference> <Reference Include="Microsoft.CSharp" /> + <Reference Include="Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL"> + <EmbedInteropTypes>True</EmbedInteropTypes> + </Reference> <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> </Reference> @@ -90,6 +93,7 @@ <Compile Include="DependencyInjection_TST.cs" /> <Compile Include="Logging_TST.cs" /> <Compile Include="MachineStudio_TST.cs" /> + <Compile Include="RemoteRunner_TST.cs" /> <Compile Include="Temporary_TST.cs" /> <Compile Include="TFS_TST.cs" /> <Compile Include="Outlook_TST.cs" /> @@ -168,40 +172,15 @@ <Project>{998f8471-dc1b-41b6-9d96-354e1b4e7a32}</Project> <Name>Tango.TFS</Name> </ProjectReference> + <ProjectReference Include="..\Tango.Transport\Tango.Transport.csproj"> + <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project> + <Name>Tango.Transport</Name> + </ProjectReference> <ProjectReference Include="..\Utilities\Tango.DBObservablesGenerator.CLI\Tango.DBObservablesGenerator.CLI.csproj"> <Project>{ebb7cb9f-6af2-456b-a5dd-1b136b605d90}</Project> <Name>Tango.DBObservablesGenerator.CLI</Name> </ProjectReference> </ItemGroup> - <ItemGroup> - <COMReference Include="Microsoft.Office.Core"> - <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid> - <VersionMajor>2</VersionMajor> - <VersionMinor>8</VersionMinor> - <Lcid>0</Lcid> - <WrapperTool>primary</WrapperTool> - <Isolated>False</Isolated> - <EmbedInteropTypes>True</EmbedInteropTypes> - </COMReference> - <COMReference Include="Microsoft.Office.Interop.Outlook"> - <Guid>{00062FFF-0000-0000-C000-000000000046}</Guid> - <VersionMajor>9</VersionMajor> - <VersionMinor>6</VersionMinor> - <Lcid>0</Lcid> - <WrapperTool>primary</WrapperTool> - <Isolated>False</Isolated> - <EmbedInteropTypes>True</EmbedInteropTypes> - </COMReference> - <COMReference Include="stdole"> - <Guid>{00020430-0000-0000-C000-000000000046}</Guid> - <VersionMajor>2</VersionMajor> - <VersionMinor>0</VersionMinor> - <Lcid>0</Lcid> - <WrapperTool>primary</WrapperTool> - <Isolated>False</Isolated> - <EmbedInteropTypes>True</EmbedInteropTypes> - </COMReference> - </ItemGroup> <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
