Skip to content

Commit

Permalink
Added Connected test
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fawcett committed Jan 20, 2023
1 parent f0735e4 commit 5b20074
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions SimListenerTest/ConnectTests.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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<string, string> Data = new KeyValuePair<string, string>("PLANE LATITUDE", "");
List<string> 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);
}
}
}

0 comments on commit 5b20074

Please sign in to comment.