diff --git a/SimListenerTest/ConnectTests.cs b/SimListenerTest/ConnectTests.cs index 53fa243..1bda628 100644 --- a/SimListenerTest/ConnectTests.cs +++ b/SimListenerTest/ConnectTests.cs @@ -1,11 +1,14 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestTools.UnitTesting; using SimListener; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Runtime.Intrinsics.X86; using System.Text; using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace SimListener.Tests { @@ -66,12 +69,60 @@ public void AddRequestsTest5() string answer = cnx.AddRequests(Test); - foreach( var req in cnx.AircraftData() ) + foreach (var req in cnx.AircraftData()) { - Console.WriteLine( $"OUTPUT -> {req}" ); + Console.WriteLine($"OUTPUT -> {req}"); } - Assert.IsTrue( cnx.AircraftData().Contains( Data ) ); + Assert.IsTrue(cnx.AircraftData().Contains(Data)); + } + + [TestMethod()] + public void ConnectedTest1() + { + Connect cnx = new(); + + + Process[] processes = Process.GetProcessesByName("FlightSimulator"); + if (processes.Length == 0) + { + Console.Write( "Flight Simulator is not Running"); + Assert.IsTrue(true); + return; + } + + cnx.ConnectToSim(); + + Console.WriteLine($"Connection is {cnx.Connected}"); + + if (!cnx.Connected) + { + // Sim Connect has not connected. + Assert.IsTrue(false); + return; + } + + KeyValuePair Data = new KeyValuePair("PLANE LATITUDE", ""); + List Test = new() { Data.Key }; + string answer = cnx.AddRequests(Test); + + foreach (var i in Enumerable.Range(0, 60 )) + { + foreach (var req in cnx.AircraftData()) + { + if( req.Key == Data.Key && req.Value != "" ) + { + // If we find data we can pass the test + Console.WriteLine($"Output -> {req}"); + Assert.IsTrue( true ); + return; + } + } + Thread.Sleep(1000); + } + + // If after a minute we find no data connection isn't working + Assert.IsTrue(false); } } } \ No newline at end of file