public void ServerFailsToProcessRequest() { var squad = GenerateSquad(); var bus = new BusMock(); // Fake channel with fake instant response var channel = new ChannelMock(); channel.Mock((SubstitutePlayerRequest req) => new SubstitutePlayerResponse() { IsSuccess = false }); var action = new SubstitutePlayersAction(new PlayerId(0), new PlayerId(1)); // Check before CheckSquad(squad); var handler = new SubstitutePlayerHandler(bus, squad, channel); var task = handler.Process(action); // Check after CheckSquad(squad); CheckThatSquadIsNotChanged(squad); Assert.AreEqual(TaskState.Failed, task.State); Assert.AreEqual(SubstitutePlayerHandler.FailToSubstituePlayersOnServer, task.Error); }
public void TryToSwapTwoPlayersThatAreNotOnThePitch() { var squad = GenerateSquad(); var bus = new BusMock(); // Fake channel with fake instant response var channel = new ChannelMock(); channel.Mock((SubstitutePlayerRequest req) => new SubstitutePlayerResponse() { IsSuccess = true }); var action = new SubstitutePlayersAction(new PlayerId(20), new PlayerId(21)); // Check before CheckSquad(squad); Assert.IsFalse(squad.PlayersOnPitch.Contains(action.Player1)); Assert.IsFalse(squad.PlayersOnPitch.Contains(action.Player2)); var handler = new SubstitutePlayerHandler(bus, squad, channel); var task = handler.Process(action); // Check after CheckSquad(squad); CheckThatSquadIsNotChanged(squad); Assert.AreEqual(TaskState.Failed, task.State); Assert.AreEqual(SubstitutePlayerHandler.PlayersNotOnPitch, task.Error); }
public void TestHappyPath() { // Create defualt squad and then swap player at index 0 // with player at index 1. Both are on pitch. var squad = GenerateSquad(); var bus = new BusMock(); // Fake channel with fake instant response var channel = new ChannelMock(); channel.Mock((SubstitutePlayerRequest req) => new SubstitutePlayerResponse() { IsSuccess = true }); var action = new SubstitutePlayersAction(new PlayerId(0), new PlayerId(1)); // Check before CheckSquad(squad); Assert.AreEqual(0, (long)squad.PlayersOnPitch[0]); Assert.AreEqual(1, (long)squad.PlayersOnPitch[1]); var handler = new SubstitutePlayerHandler(bus, squad, channel); var task = handler.Process(action); // Check after CheckSquad(squad); Assert.AreEqual(TaskState.Successful, task.State); Assert.AreEqual(0, (long)squad.PlayersOnPitch[1]); Assert.AreEqual(1, (long)squad.PlayersOnPitch[0]); // Check that we notify rest of system that squad is changed. Assert.AreEqual(1, bus.SentMessages.Count); Assert.AreEqual(typeof(SquadUpdatedEvent), bus.SentMessages[0].GetType()); }