public async Task IntegrationTestMarkPlayerCompletedPhase() { // Arrange NationRepository repository = new NationRepository(DevelopmentStorageAccountConnectionString); SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("68E4A0DC-BAB8-4C79-A6E9-D0A7494F3B45"); String dummyUserId = "DummyUserId"; await sessionRepository.SetupSession(validGuid, dummyUserId) .SetupSessionPhase(sessionRepository, SessionPhase.Reinforcements); var dataTable = SessionRepository.GetTableForSessionData(TableClient, validGuid); // Act await repository.MarkPlayerCompletedPhase(validGuid, dummyUserId, validGuid); // Assert var operation = TableOperation.Retrieve <NationTableEntry>(validGuid.ToString(), "Nation_" + dummyUserId); var result = await dataTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(NationTableEntry)); NationTableEntry resultPlayerStronglyTyped = result.Result as NationTableEntry; Assert.AreEqual(validGuid, resultPlayerStronglyTyped.CompletedPhase); }
public async Task <Guid> PostRedeployTroops(Guid sessionId, Guid regionId, uint numberOfTroops, Guid targetRegionId) { IRegionData sourceRegion = await RegionRepository.GetRegionOrThrow(sessionId, regionId) .IsRegionOwnerOrThrow(User.Identity.GetUserId()); ISession session = await SessionRepository.GetSessionOrThrow(sourceRegion) .IsUserIdJoinedOrThrow(NationRepository, User.Identity.GetUserId()) .IsPhaseTypeOrThrow(SessionPhase.Redeployment); IRegionData targetRegion = await RegionRepository.GetRegionOrThrow(session.GameId, targetRegionId) .IsRegionOwnerOrThrow(User.Identity.GetUserId()) .IsRegionConnectedOrThrow(sourceRegion.RegionId); INationData nation = await NationRepository.GetNation(sessionId, User.Identity.GetUserId()); if (sourceRegion.TroopCount <= numberOfTroops) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "You do not have that many troops available to redeploy" }); } else if (numberOfTroops <= 0) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "You can not redeploy less than 1 troop" }); } else if (nation.CompletedPhase == session.PhaseId) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.Conflict, ReasonPhrase = "You may only issue 1 redeployment" }); } else { Guid redeployOp = await CommandQueue.Redeploy(session.GameId, session.PhaseId, nation.CurrentEtag, sourceRegion.RegionId, targetRegion.RegionId, numberOfTroops); try { await NationRepository.MarkPlayerCompletedPhase(sessionId, User.Identity.GetUserId(), session.PhaseId); } catch (ConcurrencyException) { // The host has moved onto the next phase while we were waiting. No further action required. } return(redeployOp); } }