using XFEEDToolBox.Core.Execution;
using XFEEDToolBox.Core.Models;
using XFEExtension.NetCore.XUnit.Attributes;
namespace XFEEDToolBox.Test;
[TestFixture]
public class TradeAcceptancePolicyTests
{
private static readonly TradeOrder Cheap=new("water","Water",1,100,200);
private static TradeLeg Leg=>new(){Number=1,From=Check.Station(1),To=Check.Station(2),Orders=[Cheap]};
private static PlayerState Empty=>new(){InGame=true,Docked=true,MarketId=1,CargoReliable=true,CargoCount=0};
private static PlayerState Laden=>Empty with{CargoCount=1,Inventory=[new("water","Water",1)]};
private static RoutePlan Plan=>new(){Request=Check.Request with{CargoCapacity=1},Legs=[Leg]};
[Test] public void ExpensiveRareAndOverOneTonnePlansAreRejectedBeforeAnyTrade()
{
var policy=new TradeAcceptancePolicy();policy.ValidatePlan(Plan,Empty);
foreach(var order in new[]{Cheap with{Quantity=2},Cheap with{Commodity="platinum",BuyPrice=100},Cheap with{BuyPrice=501}})
Check.Throws<InvalidOperationException>(()=>policy.ValidatePlan(Plan with{Legs=[Leg with{Orders=[order]}]},Empty));
Check.Throws<InvalidOperationException>(()=>policy.ValidatePlan(Plan with{Request=Plan.Request with{CargoCapacity=2}},Empty));
}
[Test] public void ExistingCargoIsNeverReusedDiscardedOrSoldAsTestCargo()
{
var policy=new TradeAcceptancePolicy();
foreach(var player in new[]{Laden,Empty with{CargoReliable=false},Empty with{Inventory=[new("gold","Gold",1)]}})
Check.Throws<InvalidOperationException>(()=>policy.ValidatePlan(Plan,player));
}
[Test] public void BuyRechecksExactStationEmptyCargoAndAuthorizedOrder()
{
var policy=new TradeAcceptancePolicy();var buy=new TradeAction(TradeActionKind.Buy,Leg,Cheap);policy.ValidateAction(buy,Empty);
foreach(var player in new[]{Laden,Empty with{MarketId=2},Empty with{Docked=false}})
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(buy,player));
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(buy with{Order=Cheap with{Quantity=2}},Empty));
}
[Test] public void DepartureAndSaleRequireExactlyTheSingleLegalTestCommodity()
{
var policy=new TradeAcceptancePolicy();var travel=new TradeAction(TradeActionKind.Travel,Leg,null);
policy.ValidateAction(travel,Laden);
foreach(var player in new[]{Laden with{CargoCount=2},Laden with{Inventory=[new("water","Water",1,1)]},Laden with{Inventory=[new("water","Water",1,MissionId:4)]},Laden with{Inventory=[new("gold","Gold",1)]}})
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(travel,player));
var sell=new TradeAction(TradeActionKind.Sell,Leg,Cheap);policy.ValidateAction(sell,Laden with{MarketId=2});
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(sell,Laden));
}
[Test] public void ExistingLimpetsArePreservedWithoutIncreasingTheTestTradeQuantity()
{
var limpets=new InventoryItem("drones","Limpets",16);var policy=new TradeAcceptancePolicy([limpets]);
policy.ValidatePlan(Plan,Empty with{CargoCount=16,Inventory=[limpets]});
var laden=Laden with{CargoCount=17,Inventory=[limpets,new("water","Water",1)]};
policy.ValidateAction(new(TradeActionKind.Travel,Leg,null),laden);
policy.ValidateAction(new(TradeActionKind.Sell,Leg,Cheap),laden with{MarketId=2});
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(new(TradeActionKind.Travel,Leg,null),laden with{CargoCount=18,Inventory=[limpets,new("water","Water",2)]}));
Check.Throws<InvalidOperationException>(()=>new TradeAcceptancePolicy([new("gold","Gold",16)]).ValidatePlan(Plan,Empty with{CargoCount=16,Inventory=[new("gold","Gold",16)]}));
}
}
using XFEEDToolBox.Core.Execution;
using XFEEDToolBox.Core.Models;
using XFEExtension.NetCore.XUnit.Attributes;
namespace XFEEDToolBox.Test;
[TestFixture]
public class TradeAcceptancePolicyTests
{
private static readonly TradeOrder Cheap=new("water","Water",1,100,200);
private static TradeLeg Leg=>new(){Number=1,From=Check.Station(1),To=Check.Station(2),Orders=[Cheap]};
private static PlayerState Empty=>new(){InGame=true,Docked=true,MarketId=1,CargoReliable=true,CargoCount=0};
private static PlayerState Laden=>Empty with{CargoCount=1,Inventory=[new("water","Water",1)]};
private static RoutePlan Plan=>new(){Request=Check.Request with{CargoCapacity=1},Legs=[Leg]};
[Test] public void ExpensiveRareAndOverOneTonnePlansAreRejectedBeforeAnyTrade()
{
var policy=new TradeAcceptancePolicy();policy.ValidatePlan(Plan,Empty);
foreach(var order in new[]{Cheap with{Quantity=2},Cheap with{Commodity="platinum",BuyPrice=100},Cheap with{BuyPrice=501}})
Check.Throws<InvalidOperationException>(()=>policy.ValidatePlan(Plan with{Legs=[Leg with{Orders=[order]}]},Empty));
Check.Throws<InvalidOperationException>(()=>policy.ValidatePlan(Plan with{Request=Plan.Request with{CargoCapacity=2}},Empty));
}
[Test] public void ExistingCargoIsNeverReusedDiscardedOrSoldAsTestCargo()
{
var policy=new TradeAcceptancePolicy();
foreach(var player in new[]{Laden,Empty with{CargoReliable=false},Empty with{Inventory=[new("gold","Gold",1)]}})
Check.Throws<InvalidOperationException>(()=>policy.ValidatePlan(Plan,player));
}
[Test] public void BuyRechecksExactStationEmptyCargoAndAuthorizedOrder()
{
var policy=new TradeAcceptancePolicy();var buy=new TradeAction(TradeActionKind.Buy,Leg,Cheap);policy.ValidateAction(buy,Empty);
foreach(var player in new[]{Laden,Empty with{MarketId=2},Empty with{Docked=false}})
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(buy,player));
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(buy with{Order=Cheap with{Quantity=2}},Empty));
}
[Test] public void DepartureAndSaleRequireExactlyTheSingleLegalTestCommodity()
{
var policy=new TradeAcceptancePolicy();var travel=new TradeAction(TradeActionKind.Travel,Leg,null);
policy.ValidateAction(travel,Laden);
foreach(var player in new[]{Laden with{CargoCount=2},Laden with{Inventory=[new("water","Water",1,1)]},Laden with{Inventory=[new("water","Water",1,MissionId:4)]},Laden with{Inventory=[new("gold","Gold",1)]}})
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(travel,player));
var sell=new TradeAction(TradeActionKind.Sell,Leg,Cheap);policy.ValidateAction(sell,Laden with{MarketId=2});
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(sell,Laden));
}
[Test] public void ExistingLimpetsArePreservedWithoutIncreasingTheTestTradeQuantity()
{
var limpets=new InventoryItem("drones","Limpets",16);var policy=new TradeAcceptancePolicy([limpets]);
policy.ValidatePlan(Plan,Empty with{CargoCount=16,Inventory=[limpets]});
var laden=Laden with{CargoCount=17,Inventory=[limpets,new("water","Water",1)]};
policy.ValidateAction(new(TradeActionKind.Travel,Leg,null),laden);
policy.ValidateAction(new(TradeActionKind.Sell,Leg,Cheap),laden with{MarketId=2});
Check.Throws<InvalidOperationException>(()=>policy.ValidateAction(new(TradeActionKind.Travel,Leg,null),laden with{CargoCount=18,Inventory=[limpets,new("water","Water",2)]}));
Check.Throws<InvalidOperationException>(()=>new TradeAcceptancePolicy([new("gold","Gold",16)]).ValidatePlan(Plan,Empty with{CargoCount=16,Inventory=[new("gold","Gold",16)]}));
}
}