Skip to content

Commit

Permalink
Merge pull request #178 from VATSIM-UK/176-external-airports
Browse files Browse the repository at this point in the history
feat(validation): Dont require external guest airports to be present
  • Loading branch information
AndyTWF authored Apr 15, 2022
2 parents 50b948f + 8186969 commit c322687
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/Compiler/Validate/AllSectorsMustHaveValidGuestAirports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ public void Validate(SectorElementCollection sectorElements, CompilerArguments a
{
foreach (SectorGuest guest in sector.Guests)
{
if (guest.DepartureAirport != "*" && !airports.Contains(guest.DepartureAirport))
if (guest.DepartureAirport != "*" && IsHomeAirport(guest.DepartureAirport) &&
!airports.Contains(guest.DepartureAirport))
{
string message =
$"Invalid departure GUEST airport {guest.DepartureAirport} on sector {sector.Name}";
events.AddEvent(new ValidationRuleFailure(message, guest));
break;
}

if (guest.ArrivalAirport != "*" && !airports.Contains(guest.ArrivalAirport))
if (guest.ArrivalAirport != "*" && IsHomeAirport(guest.ArrivalAirport) &&
!airports.Contains(guest.ArrivalAirport))
{
string message =
$"Invalid arrival GUEST airport {guest.ArrivalAirport} on sector {sector.Name}";
Expand All @@ -34,5 +36,10 @@ public void Validate(SectorElementCollection sectorElements, CompilerArguments a
}
}
}

private bool IsHomeAirport(string airport)
{
return airport.StartsWith("EG");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CompilerTest.Validate
{
public class AllSectorsMustHaveValidGuestAirportsTest: AbstractValidatorTestCase
public class AllSectorsMustHaveValidGuestAirportsTest : AbstractValidatorTestCase
{
public AllSectorsMustHaveValidGuestAirportsTest()
{
Expand All @@ -20,6 +20,7 @@ public AllSectorsMustHaveValidGuestAirportsTest()
[InlineData("EGCC", "EGCC", "EGKK")]
[InlineData("EGKK", "EGLL", "EGKK")]
[InlineData("EGKK", "EGLL", "EGCC")]
[InlineData("EHAM", "EDDM", "EIDW")]
public void TestItPassesOnAllValid(string first, string second, string third)
{
sectorElements.Add(
Expand All @@ -40,16 +41,16 @@ public void TestItPassesOnAllValid(string first, string second, string third)
}
)
);

AssertNoValidationErrors();
}

[Theory]
[InlineData("EGLL", "EGCC", "WHAT", 2)]
[InlineData("EGCC", "WHAT", "EGKK", 1)]
[InlineData("EGKK", "WHAT", "WHAT", 2)]
[InlineData("WHAT", "EGCC", "EGLL", 2)]
[InlineData("WHAT", "WHAT", "WHAT", 2)]
[InlineData("EGLL", "EGCC", "EGNO", 2)]
[InlineData("EGCC", "EGNO", "EGKK", 1)]
[InlineData("EGKK", "EGNO", "EGNO", 2)]
[InlineData("EGNO", "EGCC", "EGLL", 2)]
[InlineData("EGNO", "EGNO", "EGNO", 2)]
public void TestItFailsOnInvalid(string first, string second, string third, int timesCalled)
{
sectorElements.Add(
Expand All @@ -70,7 +71,7 @@ public void TestItFailsOnInvalid(string first, string second, string third, int
}
)
);

AssertValidationErrors(timesCalled);
}

Expand Down

0 comments on commit c322687

Please sign in to comment.