public void DoCombatAcceptSurrender() { // Arrange Mock <Npc> mockNpcRow = new Mock <Npc>(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.CombatId) .Returns(2); mockNpcRow.Expect(n => n.Ship.InProgressCombat.Status) .Returns(Combat.CombatStatus.Incomplete); // Setup it up so that it's the police turn mockNpcRow.Expect(n => n.Ship.InProgressCombat.ShipTurn.ShipId) .Returns(1) .Verifiable(); mockNpcRow.Expect(n => n.Ship.ShipId) .Returns(1) .Verifiable(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.Surrendered) .Returns(true) .Verifiable(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.AcceptSurrender()) .Verifiable(); NpcPolice police = new NpcPolice(mockNpcRow.Object); // Act police.DoCombat(); // Assert mockNpcRow.Verify(); }
public void DoTravel() { // Arrange Race npcRace = new Race(); CosmoSystem[] inRangeSystems = { new CosmoSystem(), new CosmoSystem(), new CosmoSystem() }; inRangeSystems[0].SystemId = 1; inRangeSystems[0].Race = new Race(); inRangeSystems[1].SystemId = 2; inRangeSystems[1].Race = npcRace; inRangeSystems[2].SystemId = 3; inRangeSystems[2].Race = new Race(); Mock <Npc> mockNpcRow = new Mock <Npc>(); mockNpcRow.Expect(n => n.Ship.GetInRangeSystems()) .Returns(inRangeSystems) .Verifiable(); mockNpcRow.Expect(n => n.Race) .Returns(npcRace) .Verifiable(); // Should try to travel to the system with the same race as the Npc mockNpcRow.Expect(n => n.Ship.Travel(inRangeSystems[1])) .Returns(6) .Verifiable(); NpcPolice police = new NpcPolice(mockNpcRow.Object); // Act police.DoTravel(); // Assert mockNpcRow.Verify(); }
/// <summary> /// Does the action. /// </summary> public virtual void DoAction() { Logger.Write(string.Format("Processing NpcId: {0}", this.NpcId), "NPC", 20, 0, TraceEventType.Start, "Npc.DoAction"); NpcBase npc = null; switch (this.NType) { case NpcType.GoodBalancer: // Special system good price/count balancer NPC npc = new NpcGoodBalancer(this); break; case NpcType.NpcBalancer: // Npc Balancer NPC npc = new NpcBalancer(this); break; case NpcType.Cleaner: // Cleaner NPC npc = new NpcCleaner(this); break; case NpcType.Trader: // Trader NPC npc = new NpcTrader(this); break; case NpcType.Pirate: // Pirate NPC npc = new NpcPirate(this); break; case NpcType.Police: // Police NPC npc = new NpcPolice(this); break; default: throw new ArgumentOutOfRangeException("NType", this.NType, "Invalid NPC Type"); } // Do the actual NPC action npc.DoAction(); }
public void DoCombatChargeJumpdrive() { // Arrange Mock <Npc> mockNpcRow = new Mock <Npc>(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.CombatId) .Returns(2); mockNpcRow.Expect(n => n.Ship.InProgressCombat.Status) .Returns(Combat.CombatStatus.Incomplete); // Setup it up so that it's the police turn mockNpcRow.Expect(n => n.Ship.InProgressCombat.ShipTurn.ShipId) .Returns(1) .Verifiable(); mockNpcRow.Expect(n => n.Ship.ShipId) .Returns(1) .Verifiable(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.Surrendered) .Returns(false) .Verifiable(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.CargoJettisoned) .Returns(false) .Verifiable(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.FireWeapon()) .Throws(new ArgumentOutOfRangeException("Out of turn points")) .Verifiable(); mockNpcRow.Expect(n => n.Ship.InProgressCombat.ChargeJumpDrive()) .Verifiable(); NpcPolice police = new NpcPolice(mockNpcRow.Object); // Act police.DoCombat(); // Assert mockNpcRow.Verify(); }
public void DoSearch() { // Arrange // This set has a player entry EntitySet <Player> playerSet = new EntitySet <Player>(); playerSet.Add(new Player()); // This set is empty EntitySet <Player> npcSet = new EntitySet <Player>(); Mock <Ship> playerShip = new Mock <Ship>(); playerShip.Expect(s => s.Players) .Returns(playerSet) .Verifiable(); playerShip.Expect(s => s.ShipId) .Returns(1) .Verifiable(); Mock <Ship> lastSearchedShip = new Mock <Ship>(); lastSearchedShip.Expect(s => s.Players) .Returns(playerSet) .Verifiable(); lastSearchedShip.Expect(s => s.ShipId) .Returns(2) .Verifiable(); Mock <Ship> playerInCombatShip = new Mock <Ship>(); playerInCombatShip.Expect(s => s.Players) .Returns(playerSet) .Verifiable(); playerInCombatShip.Expect(s => s.InProgressCombat) .Returns(new Combat()) .Verifiable(); playerInCombatShip.Expect(s => s.ShipId) .Returns(3) .Verifiable(); Mock <Ship> npcShip = new Mock <Ship>(); npcShip.Expect(s => s.Players) .Returns(npcSet) .Verifiable(); npcShip.Expect(s => s.ShipId) .Returns(4) .Verifiable(); Mock <Npc> mockNpcRow = new Mock <Npc>(); mockNpcRow.Expect(n => n.LastAttackedShipId) .Returns(lastSearchedShip.Object.ShipId); mockNpcRow.Expect(n => n.Ship.GetShipsToAttack()) .Returns(new Ship[] { playerShip.Object, lastSearchedShip.Object, playerInCombatShip.Object, npcShip.Object }) .Verifiable(); // The player ship is the only one we can attack/search mockNpcRow.Expect(n => n.Ship.Attack(playerShip.Object)) .AtMostOnce() .Verifiable(); // Police should start searching mockNpcRow.Expect(n => n.Ship.InProgressCombat.StartSearch()) .AtMostOnce() .Verifiable(); NpcPolice police = new NpcPolice(mockNpcRow.Object); // Act police.DoSearch(); // Assert mockNpcRow.Verify(); }