2022-03-23 03:13:49 +00:00
|
|
|
using MultiversalDiplomacy.Adjudicate;
|
2022-03-27 21:36:49 +00:00
|
|
|
using MultiversalDiplomacy.Adjudicate.Decision;
|
2022-03-16 00:24:16 +00:00
|
|
|
using MultiversalDiplomacy.Model;
|
|
|
|
using MultiversalDiplomacy.Orders;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace MultiversalDiplomacyTests;
|
|
|
|
|
|
|
|
class TestCaseBuilderTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void BuilderCreatesUnits()
|
|
|
|
{
|
2022-03-29 05:34:57 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap());
|
2022-03-16 00:24:16 +00:00
|
|
|
|
|
|
|
Assert.That(setup.World.Powers.Count(), Is.EqualTo(7), "Unexpected power count");
|
|
|
|
Assert.That(setup.World.Units, Is.Empty, "Expected no units to be created yet");
|
|
|
|
|
|
|
|
setup
|
|
|
|
["England"]
|
|
|
|
.Army("London").Exists()
|
|
|
|
.Fleet("Irish Sea").Exists()
|
|
|
|
["Russia"]
|
|
|
|
.Fleet("Saint Petersburg", "west coast").Exists();
|
|
|
|
|
|
|
|
Assert.That(setup.Orders, Is.Empty, "Expected no orders to be created yet");
|
|
|
|
Assert.That(setup.World.Units, Is.Not.Empty, "Expected units to be created");
|
|
|
|
|
2022-03-30 00:16:00 +00:00
|
|
|
Unit armyLON = setup.World.GetUnitAt("London");
|
2022-03-16 00:24:16 +00:00
|
|
|
Assert.That(armyLON.Power.Name, Is.EqualTo("England"), "Unit created with wrong power");
|
|
|
|
Assert.That(armyLON.Type, Is.EqualTo(UnitType.Army), "Unit created with wrong type");
|
|
|
|
|
2022-03-30 00:16:00 +00:00
|
|
|
Unit fleetIRI = setup.World.GetUnitAt("Irish Sea");
|
2022-03-16 00:24:16 +00:00
|
|
|
Assert.That(fleetIRI.Power.Name, Is.EqualTo("England"), "Unit created with wrong power");
|
|
|
|
Assert.That(fleetIRI.Type, Is.EqualTo(UnitType.Fleet), "Unit created with wrong type");
|
|
|
|
|
2022-03-30 00:16:00 +00:00
|
|
|
Unit fleetSTP = setup.World.GetUnitAt("Saint Petersburg");
|
2022-03-16 00:24:16 +00:00
|
|
|
Assert.That(fleetSTP.Power.Name, Is.EqualTo("Russia"), "Unit created with wrong power");
|
|
|
|
Assert.That(fleetSTP.Type, Is.EqualTo(UnitType.Fleet), "Unit created with wrong type");
|
|
|
|
Assert.That(
|
|
|
|
fleetSTP.Location,
|
|
|
|
Is.EqualTo(setup.World.GetWater("STP", "wc")),
|
|
|
|
"Unit created on wrong coast");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BuilderCreatesOrders()
|
|
|
|
{
|
2022-03-29 05:34:57 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap());
|
2022-03-16 00:24:16 +00:00
|
|
|
|
|
|
|
Assert.That(setup.World.Powers.Count(), Is.EqualTo(7), "Unexpected power count");
|
|
|
|
Assert.That(setup.World.Units, Is.Empty, "Expected no units to be created yet");
|
|
|
|
Assert.That(setup.Orders, Is.Empty, "Expected no orders to be created yet");
|
|
|
|
|
|
|
|
setup
|
|
|
|
["Germany"]
|
|
|
|
.Army("Berlin").MovesTo("Kiel")
|
|
|
|
.Army("Prussia").Holds()
|
|
|
|
["England"]
|
|
|
|
.Fleet("North Sea").Convoys.Army("London").To("Holland")
|
|
|
|
["France"]
|
|
|
|
.Army("Kiel").Supports.Army("London", powerName: "England").MoveTo("Holland")
|
|
|
|
.Army("Munich").Supports.Army("Kiel").Hold();
|
|
|
|
|
|
|
|
Assert.That(setup.Orders, Is.Not.Empty, "Expected orders to be created");
|
|
|
|
Assert.That(setup.World.Units, Is.Not.Empty, "Expected units to be created");
|
|
|
|
List<UnitOrder> orders = setup.Orders.OfType<UnitOrder>().ToList();
|
|
|
|
|
|
|
|
Func<UnitOrder, bool> OrderForProvince(string name)
|
2022-03-30 19:52:57 +00:00
|
|
|
=> order => order.Unit.Province.Name == name;
|
2022-03-16 00:24:16 +00:00
|
|
|
|
|
|
|
UnitOrder orderBer = orders.Single(OrderForProvince("Berlin"));
|
|
|
|
Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type");
|
|
|
|
Assert.That(
|
|
|
|
(orderBer as MoveOrder)?.Location,
|
|
|
|
Is.EqualTo(setup.World.GetLand("Kiel")),
|
|
|
|
"Unexpected move order destination");
|
|
|
|
|
|
|
|
UnitOrder orderPru = orders.Single(OrderForProvince("Prussia"));
|
|
|
|
Assert.That(orderPru, Is.InstanceOf<HoldOrder>(), "Unexpected order type");
|
|
|
|
|
|
|
|
UnitOrder orderNth = orders.Single(OrderForProvince("North Sea"));
|
|
|
|
Assert.That(orderNth, Is.InstanceOf<ConvoyOrder>(), "Unexpected order type");
|
|
|
|
Assert.That(
|
|
|
|
(orderNth as ConvoyOrder)?.Target,
|
|
|
|
Is.EqualTo(setup.World.GetUnitAt("London")),
|
|
|
|
"Unexpected convoy order target");
|
|
|
|
Assert.That(
|
|
|
|
(orderNth as ConvoyOrder)?.Location,
|
|
|
|
Is.EqualTo(setup.World.GetLand("Holland")),
|
|
|
|
"Unexpected convoy order destination");
|
|
|
|
|
|
|
|
UnitOrder orderKie = orders.Single(OrderForProvince("Kiel"));
|
|
|
|
Assert.That(orderKie, Is.InstanceOf<SupportMoveOrder>(), "Unexpected order type");
|
|
|
|
Assert.That(
|
|
|
|
(orderKie as SupportMoveOrder)?.Target,
|
|
|
|
Is.EqualTo(setup.World.GetUnitAt("London")),
|
|
|
|
"Unexpected convoy order target");
|
|
|
|
Assert.That(
|
|
|
|
(orderKie as SupportMoveOrder)?.Location,
|
|
|
|
Is.EqualTo(setup.World.GetLand("Holland")),
|
|
|
|
"Unexpected convoy order destination");
|
|
|
|
|
|
|
|
UnitOrder orderMun = orders.Single(OrderForProvince("Munich"));
|
|
|
|
Assert.That(orderMun, Is.InstanceOf<SupportHoldOrder>(), "Unexpected order type");
|
|
|
|
Assert.That(
|
|
|
|
(orderMun as SupportHoldOrder)?.Target,
|
|
|
|
Is.EqualTo(setup.World.GetUnitAt("Kiel")),
|
|
|
|
"Unexpected convoy order target");
|
|
|
|
|
|
|
|
Assert.That(orders.Where(OrderForProvince("London")), Is.Empty, "Unexpected order");
|
|
|
|
}
|
2022-03-23 03:13:49 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BuilderProvidesReferencesForValidation()
|
|
|
|
{
|
2022-03-27 21:36:49 +00:00
|
|
|
IPhaseAdjudicator rubberStamp = new TestAdjudicator(validate: TestAdjudicator.RubberStamp);
|
2022-03-23 03:13:49 +00:00
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
TestCaseBuilder setup = new TestCaseBuilder(World.WithStandardMap());
|
2022-03-23 03:13:49 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var orderMun);
|
|
|
|
|
|
|
|
Assert.That(orderMun, Is.Not.Null, "Expected order reference");
|
|
|
|
Assert.That(
|
|
|
|
orderMun.Order.Power,
|
|
|
|
Is.EqualTo(setup.World.GetPower("Germany")),
|
|
|
|
"Wrong power");
|
|
|
|
Assert.That(
|
|
|
|
orderMun.Order.Unit.Location,
|
|
|
|
Is.EqualTo(setup.World.GetLand("Mun")),
|
|
|
|
"Wrong unit");
|
|
|
|
|
2022-03-27 21:36:49 +00:00
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Validation,
|
2022-03-23 03:13:49 +00:00
|
|
|
Throws.Exception,
|
|
|
|
"Validation property should be inaccessible before validation actually happens");
|
|
|
|
setup.ValidateOrders(rubberStamp);
|
2022-03-27 21:36:49 +00:00
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Validation,
|
2022-03-23 03:13:49 +00:00
|
|
|
Throws.Nothing,
|
|
|
|
"Validation property should be accessible after validation");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
orderMun.Validation.Order,
|
|
|
|
Is.EqualTo(orderMun.Order),
|
|
|
|
"Validation for wrong order");
|
|
|
|
Assert.That(
|
|
|
|
orderMun.Validation.Valid,
|
|
|
|
Is.True,
|
|
|
|
"Unexpected validation result");
|
|
|
|
Assert.That(
|
|
|
|
orderMun.Validation.Reason,
|
|
|
|
Is.EqualTo(ValidationReason.Valid),
|
|
|
|
"Unexpected validation reason");
|
|
|
|
}
|
2022-03-27 21:36:49 +00:00
|
|
|
|
|
|
|
public void BuilderProvidesReferencesForAdjudication()
|
|
|
|
{
|
|
|
|
IPhaseAdjudicator rubberStamp = new TestAdjudicator(
|
|
|
|
validate: TestAdjudicator.RubberStamp,
|
|
|
|
adjudicate: TestAdjudicator.NoMoves);
|
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
TestCaseBuilder setup = new TestCaseBuilder(World.WithStandardMap());
|
2022-03-27 21:36:49 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var orderMun);
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Adjudications,
|
|
|
|
Throws.Exception,
|
|
|
|
"Adjudication property should be inaccessible before validation");
|
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Retreat,
|
|
|
|
Throws.Exception,
|
|
|
|
"Retreat property should be inaccessible before validation");
|
|
|
|
|
|
|
|
setup.ValidateOrders(rubberStamp);
|
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Adjudications,
|
|
|
|
Throws.Exception,
|
|
|
|
"Adjudication property should be inaccessible before adjudication");
|
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Retreat,
|
|
|
|
Throws.Exception,
|
|
|
|
"Retreat property should be inaccessible before adjudication");
|
|
|
|
|
|
|
|
var decisions = setup.AdjudicateOrders(rubberStamp);
|
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Adjudications,
|
|
|
|
Throws.Nothing,
|
|
|
|
"Adjudication property should be accessible after adjudication");
|
|
|
|
Assert.That(
|
|
|
|
code: () => _ = orderMun.Retreat,
|
|
|
|
Throws.Nothing,
|
|
|
|
"Retreat property should be accessible after validation");
|
|
|
|
|
|
|
|
Assert.That(orderMun.Retreat, Is.Null, "Noop adjudicator shouldn't cause retreats");
|
|
|
|
Assert.That(
|
|
|
|
orderMun.Adjudications.Count,
|
|
|
|
Is.EqualTo(1),
|
|
|
|
"Unexpected number of adjudications");
|
|
|
|
AdjudicationDecision decision = orderMun.Adjudications.First();
|
|
|
|
Assert.That(decision.Resolved, Is.True, "Unexpected unresolved decision");
|
|
|
|
Assert.That(
|
|
|
|
decision,
|
|
|
|
Is.AssignableTo<IsDislodged>(),
|
|
|
|
"Noop adjudicator should provide a dislodge decision for a hold");
|
|
|
|
CollectionAssert.Contains(
|
|
|
|
decisions,
|
|
|
|
decision,
|
|
|
|
"Expected the adjudicated decision to be provided by the order reference");
|
|
|
|
}
|
2022-03-16 00:24:16 +00:00
|
|
|
}
|