public void SetAvailableReinforcements(IBatchOperationHandle batchOperationHandle, Guid sessionId, string userId, string currentEtag, uint reinforcements) { DummySession foundSession = SessionRepository.SessionMap[sessionId]; DummyBatchOperationHandle batchOperation = batchOperationHandle as DummyBatchOperationHandle; if (foundSession != null) { DummyNationData foundPlayer = foundSession.Players.Find(player => player.UserId == userId); if (foundPlayer != null) { batchOperation.QueuedOperations.Add(() => { foundPlayer.AvailableReinforcements = reinforcements; }); } else { throw new InvalidOperationException("Called MarkPlayerCompletedPhase with a non-existent user id"); } } else { throw new InvalidOperationException("Called JoinSession with a non-existent GUID"); } }
public async Task <bool> ReservePlayerColour(Guid sessionId, String sessionEtag, PlayerColour colour) { await StorageDelaySimulationTask; if (SessionMap.ContainsKey(sessionId)) { DummySession session = SessionMap[sessionId]; if (session.CurrentEtag == sessionEtag) { var colourQuery = from player in session.Players where player.Colour == colour select player; if (colourQuery.Count() == 0) { session.GenerateNewEtag(); return(true); } else { // Already taken return(false); } } else { // Doesn't match! throw new ConcurrencyException(); } } else { throw new InvalidOperationException("Shouldn't call ReservePlayerColour with an invalid session GUID"); } }
public Task SetSessionPhase(Guid sessionId, Guid currentPhaseId, SessionPhase newPhase) { DummySession foundSession = SessionMap[sessionId]; if (foundSession != null) { if (foundSession.PhaseId == currentPhaseId) { foundSession.SetupSessionPhase(newPhase); if (newPhase == SessionPhase.Victory) { foundSession.Round += 1; } return(Task.FromResult(false)); } else { throw new ConcurrencyException(); } } else { throw new InvalidOperationException("Called JoinSession with a non-existant GUID"); } }
static public ControllerMockSetupContext SetupDummySession(this ControllerMock controller, Guid sessionId, String ownerId, PlayerColour colour) { DummySession session = controller.SessionRepository.SetupDummySession(sessionId, ownerId, colour); return(new ControllerMockSetupContext { ControllerMock = controller, DummySession = session }); }
internal DummySession SetupDummySession(Guid sessionId, String ownerId, PlayerColour colour) { DummySession session = new DummySession { GameId = sessionId, OwnerId = ownerId }; session.SetupAddPlayer(ownerId, colour); SessionMap[sessionId] = session; return(session); }
public async Task <Guid> CreateSession(String userId, PlayerColour colour) { Guid newId = Guid.NewGuid(); SessionMap[newId] = new DummySession { GameId = newId, OwnerId = userId }; await JoinSession(newId, userId, colour); return(newId); }
public Task <IEnumerable <INationData> > GetNations(Guid sessionId) { DummySession foundSession = SessionRepository.SessionMap[sessionId]; if (foundSession != null) { IEnumerable <INationData> results = from player in foundSession.Players select player; return(Task.FromResult(results)); } else { throw new InvalidOperationException("Called GetNations with a non-existent GUID"); } }
public Task <INationData> GetNation(Guid sessionId, string userId) { DummySession foundSession = SessionRepository.SessionMap[sessionId]; if (foundSession != null) { var query = from player in foundSession.Players where player.UserId == userId select player; return(Task.FromResult <INationData>(query.FirstOrDefault())); } else { throw new InvalidOperationException("Called GetNation with a non-existent GUID"); } }
public Task JoinSession(Guid sessionId, String userId, PlayerColour colour) { DummySession foundSession = SessionMap[sessionId]; if (foundSession != null) { foundSession.Players.Add(new DummyNationData(userId) { Colour = colour }); foundSession.GenerateNewEtag(); return(Task.FromResult(false)); } else { throw new InvalidOperationException("Called JoinSession with a non-existant GUID"); } }
public void SetCardOwner(IBatchOperationHandle batchOperationHandle, Guid sessionId, Guid regionId, String userId, String currentEtag) { DummySession foundSession = SessionRepository.SessionMap[sessionId]; if (foundSession != null) { DummyNationData foundPlayer = foundSession.Players.Find(player => player.UserId == userId); if (foundPlayer != null) { SetCardOwnerInternal(batchOperationHandle, sessionId, regionId, userId, currentEtag); } else { throw new InvalidOperationException("Called SetCardOwner with a non-existent user id"); } } else { throw new InvalidOperationException("Called SetCardOwner with a non-existent session id"); } }
public Task MarkPlayerCompletedPhase(Guid sessionId, String userId, Guid phaseId) { DummySession foundSession = SessionRepository.SessionMap[sessionId]; if (foundSession != null) { DummyNationData foundPlayer = foundSession.Players.Find(player => player.UserId == userId); if (foundPlayer != null) { foundPlayer.CompletedPhase = phaseId; return(Task.FromResult(false)); } else { throw new InvalidOperationException("Called MarkPlayerCompletedPhase with a non-existent user id"); } } else { throw new InvalidOperationException("Called JoinSession with a non-existent GUID"); } }
public void SetCardOwnerInternal(IBatchOperationHandle batchOperationHandle, Guid sessionId, Guid regionId, String userId, String currentEtag) { DummySession foundSession = SessionRepository.SessionMap[sessionId]; if (foundSession != null) { if (RegionRepository.CardData.ContainsKey(regionId)) { DummyBatchOperationHandle batchOperation = batchOperationHandle as DummyBatchOperationHandle; batchOperation.QueuedOperations.Add(() => { RegionRepository.CardData[regionId].OwnerId = userId; }); } else { throw new InvalidOperationException("Called SetCardOwner with a non-existent region id"); } } else { throw new InvalidOperationException("Called SetCardOwner with a non-existent session id"); } }