public async Task IntegrationTestGetQueuedCommands() { // Arrange CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString); Guid operationGuid = await repository.DeployReinforcements(SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", 10U); Guid secondOperationGuid = await repository.DeployReinforcements(SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", 5U); // Act IEnumerable <ICommandQueueMessage> pendingMessages = await repository.GetQueuedCommands(SessionGuid, SessionPhaseGuid); // Assert Assert.IsNotNull(pendingMessages); Assert.IsTrue(2 <= pendingMessages.Count()); foreach (IDeployReinforcementsMessage message in pendingMessages) { Assert.AreEqual(SessionGuid, message.SessionId); Assert.AreEqual(SessionPhaseGuid, message.PhaseId); if (message.OperationId == operationGuid) { Assert.AreEqual(CommandQueueMessageType.Reinforce, message.MessageType); Assert.AreEqual(10U, message.NumberOfTroops); } else if (message.OperationId == secondOperationGuid) { Assert.AreEqual(CommandQueueMessageType.Reinforce, message.MessageType); Assert.AreEqual(5U, message.NumberOfTroops); } } }
public async Task <Guid> PostDeployTroops(Guid sessionId, Guid regionId, uint numberOfTroops) { IRegionData region = await RegionRepository.GetRegionOrThrow(sessionId, regionId) .IsRegionOwnerOrThrow(User.Identity.GetUserId()); ISession session = await SessionRepository.GetSessionOrThrow(region) .IsUserIdJoinedOrThrow(NationRepository, User.Identity.GetUserId()) .IsPhaseTypeOrThrow(SessionPhase.Reinforcements); INationData nation = await NationRepository.GetNation(sessionId, User.Identity.GetUserId()); if (nation.AvailableReinforcements < numberOfTroops) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "You do not have that many troops available to deploy" }); } else if (numberOfTroops <= 0) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "You can not deploy less than 1 troop" }); } else { return(await CommandQueue.DeployReinforcements(session.GameId, session.PhaseId, region.RegionId, region.CurrentEtag, numberOfTroops)); } }
public async Task IntegrationTestCreateReinforceMessage() { // Arrange CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString); // Act Guid operationGuid = await repository.DeployReinforcements(SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", 10U); // Assert var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + operationGuid.ToString()); var result = await CommandTable.ExecuteAsync(operation); CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry; Assert.IsNotNull(queuedCommand); Assert.AreEqual(operationGuid, queuedCommand.OperationId); Assert.AreEqual(SessionGuid, queuedCommand.SessionId); Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId); Assert.AreEqual(CommandQueueMessageType.Reinforce, queuedCommand.MessageType); Assert.AreEqual(RegionGuid, queuedCommand.TargetRegion); Assert.AreEqual("DummyEtag", queuedCommand.TargetRegionEtag); Assert.AreEqual(10U, queuedCommand.NumberOfTroops); }