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 IntegrationTestSetAvailableReinforcements_WithMultipleUsers() { // Arrange NationRepository repository = new NationRepository(DevelopmentStorageAccountConnectionString); SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("B59C5710-F3B3-4AAB-983D-9899ADEB4F28"); String dummyUserId = "DummyUserId"; String secondDummyUserId = "DummyUserId2"; await sessionRepository.SetupSession(validGuid, dummyUserId); await sessionRepository.SetupAddPlayer(validGuid, secondDummyUserId); var dataTable = SessionRepository.GetTableForSessionData(TableClient, validGuid); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(sessionRepository.GetTableForSessionData(validGuid))) { repository.SetAvailableReinforcements(batchOperation, validGuid, dummyUserId, "*", 10U); repository.SetAvailableReinforcements(batchOperation, validGuid, secondDummyUserId, "*", 20U); } // Assert var operation = TableOperation.Retrieve <NationTableEntry>(validGuid.ToString(), "Nation_" + dummyUserId); var result = await dataTable.ExecuteAsync(operation); NationTableEntry resultPlayerStronglyTyped = result.Result as NationTableEntry; Assert.AreEqual(10U, resultPlayerStronglyTyped.AvailableReinforcements); operation = TableOperation.Retrieve <NationTableEntry>(validGuid.ToString(), "Nation_" + secondDummyUserId); result = await dataTable.ExecuteAsync(operation); resultPlayerStronglyTyped = result.Result as NationTableEntry; Assert.AreEqual(20U, resultPlayerStronglyTyped.AvailableReinforcements); }
public async Task MarkPlayerCompletedPhase(Guid sessionId, string userId, Guid phaseId) { // Get the session data table CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId); // Fetch existing entry var operation = TableOperation.Retrieve <NationTableEntry>(sessionId.ToString(), "Nation_" + userId); var result = await sessionDataTable.ExecuteAsync(operation); // Modify entry NationTableEntry playerEntry = result.Result as NationTableEntry; playerEntry.IsValid(); playerEntry.CompletedPhase = phaseId; // Write entry back (fails on write conflict) try { TableOperation insertOperation = TableOperation.Replace(playerEntry); await sessionDataTable.ExecuteAsync(insertOperation); } catch (StorageException exception) { if (exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed) { throw new ConcurrencyException(); } else { throw exception; } } }
static internal async Task <NationTableEntry> SetupAddPlayer(this SessionRepository repository, Guid sessionId, String userId) { var dataTable = repository.GetTableForSessionData(sessionId); NationTableEntry newSessionPlayerEntry = new NationTableEntry(sessionId, userId); TableOperation insertOperation = TableOperation.InsertOrReplace(newSessionPlayerEntry); await dataTable.ExecuteAsync(insertOperation); return(newSessionPlayerEntry); }
public void SetAvailableReinforcements(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, String userId, String currentEtag, UInt32 reinforcements) { BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle; // Get the session data table CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId); // Create a DynamicTableEntity so that we can do a partial update of this table (a merge) DynamicTableEntity nationEntry = NationTableEntry.CreateDynamicTableEntity(sessionId, userId, currentEtag); NationTableEntry.SetAvailableReinforcements(nationEntry, reinforcements); batchOperationHandle.BatchOperation.Merge(nationEntry); }
public async Task JoinSession(Guid sessionId, String userId, PlayerColour colour) { var dataTable = GetTableForSessionData(sessionId); // Create a new table entry NationTableEntry newSessionPlayerEntry = new NationTableEntry(sessionId, userId) { ColourId = (Int32)colour }; // Kick off the insert operation TableOperation insertOperation = TableOperation.Insert(newSessionPlayerEntry); await dataTable.ExecuteAsync(insertOperation); }
public async Task <INationData> GetNation(Guid sessionId, string userId) { // Get the session data table CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId); var operation = TableOperation.Retrieve <NationTableEntry>(sessionId.ToString(), "Nation_" + userId); var result = await sessionDataTable.ExecuteAsync(operation); NationTableEntry typedResult = result.Result as NationTableEntry; if (typedResult != null) { typedResult.IsValid(); } return(typedResult); }
public async Task IntegrationTestCreateSession() { // Arrange SessionRepository repository = new SessionRepository(DevelopmentStorageAccountConnectionString); String dummyUserId = "DummyUserId"; // Act Guid newSessionGuid = await repository.CreateSession(dummyUserId, PlayerColour.Black); // Assert Assert.IsNotNull(newSessionGuid); var dataTable = repository.GetTableForSessionData(newSessionGuid); TableOperation operation = TableOperation.Retrieve <SessionTableEntry>(newSessionGuid.ToString(), dummyUserId); TableResult result = await SessionTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(SessionTableEntry)); SessionTableEntry resultStronglyTyped = result.Result as SessionTableEntry; Assert.AreEqual(dummyUserId, resultStronglyTyped.OwnerId); Assert.AreEqual(Guid.Empty, resultStronglyTyped.PhaseId); Assert.AreEqual(SessionPhase.NotStarted, resultStronglyTyped.PhaseType); Assert.IsTrue(resultStronglyTyped.IsColourUsed(PlayerColour.Black)); operation = TableOperation.Retrieve <NationTableEntry>(newSessionGuid.ToString(), "Nation_" + dummyUserId); result = await dataTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(NationTableEntry)); NationTableEntry resultPlayerStronglyTyped = result.Result as NationTableEntry; Assert.AreEqual(newSessionGuid, resultPlayerStronglyTyped.SessionId); Assert.AreEqual(dummyUserId, resultPlayerStronglyTyped.UserId); Assert.AreEqual(Guid.Empty, resultPlayerStronglyTyped.CompletedPhase); }
public async Task IntegrationTestJoinSession() { // Arrange SessionRepository repository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("68E4A0DC-BAB8-4C79-A6E9-D0A7494F3B45"); String dummyUserId = "DummyUserId"; await repository.SetupSession(validGuid, "CreatingUser"); // Act await repository.JoinSession(validGuid, dummyUserId, PlayerColour.Black); // Assert var dataTable = repository.GetTableForSessionData(validGuid); 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.SessionId); Assert.AreEqual(dummyUserId, resultPlayerStronglyTyped.UserId); Assert.AreEqual(Guid.Empty, resultPlayerStronglyTyped.CompletedPhase); }