public void HiringAFiredWorkerRemovesRecentWorkerIndicator() { BoardState game = DataTest.SampleGame; HireWorkerAction player1Hire = new HireWorkerAction() { PlayerId = 1 }; game = Tick.Apply(game, new List <GameAction> { player1Hire, player1Hire }); Assert.AreEqual(0, GameWorkersTest.UnhiredWorkersCount(game), "This test relies on the fact that there are exactly two unhired workers"); FireWorkerAction fire = new FireWorkerAction() { PlayerId = 1 }; game = Tick.Apply(game, new List <GameAction> { fire }); HireWorkerAction player0Hire = new HireWorkerAction() { PlayerId = 0 }; game = Tick.Apply(game, new List <GameAction> { player0Hire }); Assert.AreEqual(0, game.Players[1].RecentWorkers.Count); }
public void CannotHireWorkerJustFied() { BoardState game = DataTest.SampleGame; HireWorkerAction hire = new HireWorkerAction() { PlayerId = 1 }; game = Tick.Apply(game, new List <GameAction> { hire, hire }); Assert.AreEqual(0, GameWorkersTest.UnhiredWorkersCount(game), "This test relies on the fact that there are exactly two unhired workers"); FireWorkerAction fire = new FireWorkerAction() { PlayerId = 1 }; game = Tick.Apply(game, new List <GameAction> { fire }); Assert.That(game.Players[1].RecentWorkers.Count > 0); Assert.AreEqual(1, GameWorkersTest.UnhiredWorkersCount(game)); game = Tick.Apply(game, new List <GameAction> { hire }); Assert.AreEqual(1, GameWorkersTest.UnhiredWorkersCount(game)); }
public void FireWorkerActionWorks() { BoardState game = DataTest.SampleGame; FireWorkerAction fire = new FireWorkerAction { PlayerId = 0 }; game = Tick.Apply(game, new List <GameAction> { fire }); Assert.AreEqual(0, GameWorkersTest.GetPlayerWorkers(game, 0).Length); }
public void FireWorkerChoosesHighestPaid() { BoardState game = DataTest.SampleGame; decimal highestWageBefore = game.Players[1].WorkerIds.Select(w => game.Workers[w]).Max(w => w.Wage); FireWorkerAction fire = new FireWorkerAction { PlayerId = 1 }; game = Tick.Apply(game, new List <GameAction> { fire }); decimal highestWageAfter = game.Players[1].WorkerIds.Select(w => game.Workers[w]).Max(w => w.Wage); Assert.Greater(highestWageBefore, highestWageAfter); }
public void CannotFireIfGameIsNotStarted() { BoardState game = DataTest.SampleGame; game.State = GameState.GameNotStarted; FireWorkerAction fire = new FireWorkerAction { PlayerId = 0 }; int workersBefore = GameWorkersTest.UnhiredWorkersCount(game); game = Tick.Apply(game, new List <GameAction> { fire }); Assert.AreEqual(workersBefore, GameWorkersTest.UnhiredWorkersCount(game)); }
public void SerializeItAll() { JoinAction join = new JoinAction { PlayerId = 1, PlayerName = "Test Player" }; HireWorkerAction hire = new HireWorkerAction { PlayerId = 2 }; FireWorkerAction fire = new FireWorkerAction { PlayerId = 3 }; ProposeLoanAction propose = new ProposeLoanAction { PlayerId = 4, Period = TimeSpan.FromMinutes(1.0), PayBack = 20m, LoanAmount = 15m }; WithdrawProposalAction withdraw = new WithdrawProposalAction { PlayerId = 5, ProposalId = 2 }; GiveGiftAction gift = new GiveGiftAction { PlayerId = 6, ToPlayerId = 2, GiftAmount = 10.2m }; AssignWorkerAction research = new AssignWorkerAction { PlayerId = 7, Work = Job.Research, WorkerId = 1 }; AssignWorkerAction factory = new AssignWorkerAction { PlayerId = 8, Work = Job.Factory, WorkerId = 2 }; TakeLoanAction loan = new TakeLoanAction { PlayerId = 9, LoanProposalId = 1 }; StringBuilder sb = new StringBuilder(); sb.Append("{\"gameJson\": "); sb.Append(DataTest.SampleGame.ToJson()); sb.Append("\n, \"NoOp\": "); sb.Append(new NoOpAction().ToJson()); sb.Append("\n \"JoinGame\": "); sb.Append(join.ToJson()); sb.Append("\n \"HireWorker\": "); sb.Append(hire.ToJson()); sb.Append("\n \"FireWorker\": "); sb.Append(fire.ToJson()); sb.Append("\n \"ProposeLoan\": "); sb.Append(propose.ToJson()); sb.Append("\n \"WithdrawProposal\": "); sb.Append(withdraw.ToJson()); sb.Append("\n \"GiveGift\": "); sb.Append(gift.ToJson()); sb.Append("\n \"AssignWorkerResearch\": "); sb.Append(research.ToJson()); sb.Append("\n \"AssignWorkerFactory\": "); sb.Append(factory.ToJson()); sb.Append("\n \"TakeLoan\": "); sb.Append(loan.ToJson()); List <GameAction> actions = new List <GameAction> { hire, fire, loan }; string json = GameAction.SerializeList(actions); List <GameAction> fromJson = GameAction.DeserializeList(json); List <GameAction> empty = new List <GameAction>(); json = GameAction.SerializeList(empty); fromJson = GameAction.DeserializeList(json); }