public Task UpdateParty(UpdatePartyRequest request) { var param = new ParamBuilder() .WithPartyId(request.Id) .WithParam("Name", request.Name) .WithParam("Location", request.Location) .WithParam("StartTime", request.StartTime); return(db.Update(param)); }
public async Task <Response> Handle(UpdateLocation command) { var request = new UpdatePartyRequest() { Id = command.Id, Location = command.Location }; await _dataProvider.UpdateParty(request); return(SuccessHandler.ReturnUpdateSuccess(EntityName)); }
private static void ValidateUpdatePartyRequest(UpdatePartyRequest request) { var updatedParty = request.UpdatedParty ?? throw new RpcException(new Status(StatusCode.InvalidArgument, "UpdatePartyInfo requires a non-empty updated party")); if (string.IsNullOrEmpty(updatedParty.Id)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "UpdatePartyInfo requires an updated party with a non-empty id")); } }
public void CancelParty(int partyID) { try { var request = new UpdatePartyRequest { PartyID = partyID, CloseDate = DateTime.Now, EventEnd = DateTime.Now, PartyStatusType = PartyStatusTypes.Canceled }; var response = ExigoDAL.WebService().UpdateParty(request); } catch { } }
public void ReturnInvalidArgumentWhenTheUpdatedPartyHasAnEmptyId() { // Check that having a non-empty id on the updated party is enforced by UpdatePartyInfo. var context = Util.CreateFakeCallContext(TestPlayerId, Pit); var missingPartyIdRequest = new UpdatePartyRequest { UpdatedParty = new PartyProto() }; var exception = Assert.ThrowsAsync <RpcException>(() => _partyService.UpdateParty(missingPartyIdRequest, context)); Assert.That(exception.Message, Contains.Substring("requires an updated party with a non-empty id")); Assert.AreEqual(StatusCode.InvalidArgument, exception.StatusCode); }
public void ReturnUpdatedPartySuccessfullyWhenAdequateInformationIsProvided() { // Setup the client such that it will successfully complete the operation. var updatedEntries = new List <Entry>(); _mockMemoryStoreClient.Setup(client => client.GetAsync <PartyDataModel>(_testUpdatedParty.Id)) .ReturnsAsync(_testParty); _mockTransaction.Setup(tr => tr.UpdateAll(It.IsAny <IEnumerable <Entry> >())) .Callback <IEnumerable <Entry> >(entries => updatedEntries.AddRange(entries)); _mockTransaction.Setup(tr => tr.Dispose()); _mockAnalyticsSender.Setup( sender => sender.Send(AnalyticsConstants.PartyClass, AnalyticsEventTypePlayerUpdatedParty, It.Is <Dictionary <string, object> >(d => AnalyticsAttributesExpectations(d)), TestPlayerId)); _mockAnalyticsSender.Setup( sender => sender.Send(AnalyticsConstants.PartyClass, AnalyticsEventTypePartyUpdated, It.Is <Dictionary <string, object> >(d => AnalyticsAttributesExpectations(d)), TestPlayerId)); // Check that the operation has completed successfully. var context = Util.CreateFakeCallContext(TestPlayerId, Pit); var request = new UpdatePartyRequest { UpdatedParty = _testUpdatedParty }; var returnedParty = _partyService.UpdateParty(request, context).Result.Party; Assert.IsNotNull(returnedParty); Assert.AreEqual(_testParty.Id, returnedParty.Id); Assert.AreEqual(TestPlayerId2, returnedParty.LeaderPlayerId); Assert.AreEqual(TestNewMinMembers, returnedParty.MinMembers); Assert.AreEqual(TestNewMaxMembers, returnedParty.MaxMembers); Assert.AreEqual(_testUpdatedParty.CurrentPhase, returnedParty.CurrentPhase); CollectionAssert.AreEquivalent(new Dictionary <string, string> { { "enemy", "Dumbledore" } }, returnedParty.Metadata); // Verify that the expected party was sent for update. Assert.AreEqual(1, updatedEntries.Count); var party = (PartyDataModel)updatedEntries[0]; Assert.AreEqual(_testParty.Id, party.Id); Assert.AreEqual(TestPlayerId2, party.LeaderPlayerId); Assert.AreEqual(TestNewMinMembers, party.MinMembers); Assert.AreEqual(TestNewMaxMembers, party.MaxMembers); Assert.AreEqual(PartyDataModel.Phase.Matchmaking, party.CurrentPhase); CollectionAssert.AreEquivalent(new Dictionary <string, string> { { "enemy", "Dumbledore" } }, party.Metadata); _mockAnalyticsSender.VerifyAll(); }
public void ReturnNotFoundWhenNoPartyWithTheGivenIdExists() { // Setup the client such that it will claim there are no parties with the given id. _mockMemoryStoreClient.Setup(client => client.GetAsync <PartyDataModel>(_testUpdatedParty.Id)) .ReturnsAsync((PartyDataModel)null); // Check that an exception was thrown signaling that the update operation failed. var context = Util.CreateFakeCallContext(TestPlayerId, Pit); var request = new UpdatePartyRequest { UpdatedParty = _testUpdatedParty }; var exception = Assert.ThrowsAsync <RpcException>(() => _partyService.UpdateParty(request, context)); Assert.That(exception.Message, Contains.Substring("no such party with the given id")); Assert.AreEqual(StatusCode.NotFound, exception.StatusCode); }
// Updates the Party's information, excluding its member list. // TODO: Move to FieldMasks. public override async Task <UpdatePartyResponse> UpdateParty(UpdatePartyRequest request, ServerCallContext context) { var playerId = AuthHeaders.ExtractPlayerId(context); ValidateUpdatePartyRequest(request); using (var memClient = _memoryStoreClientManager.GetClient()) { var updatedParty = request.UpdatedParty; var party = await memClient.GetAsync <PartyDataModel>(updatedParty.Id) ?? throw new RpcException(new Status(StatusCode.NotFound, "There is no such party with the given id")); if (party.LeaderPlayerId != playerId) { throw new RpcException(new Status(StatusCode.PermissionDenied, "The update operation can only be done by the leader of the party")); } if (!party.UpdatePartyLeader(updatedParty.LeaderPlayerId)) { throw new RpcException(new Status(StatusCode.FailedPrecondition, "The proposed new leader is not a member of the party")); } if (!party.UpdateMinMaxMembers(updatedParty.MinMembers, updatedParty.MaxMembers)) { throw new RpcException(new Status(StatusCode.FailedPrecondition, "Encountered error while updating the minimum and maximum amount of members")); } // TODO(iuliaharasim/dom): Move logic specific to updating a party into a separate class. party.CurrentPhase = ConvertToDataModel(updatedParty.CurrentPhase); party.UpdateMetadata(updatedParty.Metadata); using (var transaction = memClient.CreateTransaction()) { transaction.UpdateAll(new List <Entry> { party }); } return(new UpdatePartyResponse { Party = ConvertToProto(party) }); } }
public void ReturnFailedPreconditionWhenNewLeaderIsNotAMemberOfTheParty() { // Setup the client such that it will claim that the party doesn't have as member the newly proposed leader. var party = new PartyDataModel(_testParty); party.MemberIdToPit.Remove(TestPlayerId2); _mockMemoryStoreClient.Setup(client => client.GetAsync <PartyDataModel>(_testUpdatedParty.Id)).ReturnsAsync(party); // Check that an exception was thrown signaling that the update operation failed. var context = Util.CreateFakeCallContext(TestPlayerId, Pit); var request = new UpdatePartyRequest { UpdatedParty = _testUpdatedParty }; var exception = Assert.ThrowsAsync <RpcException>(() => _partyService.UpdateParty(request, context)); Assert.That(exception.Message, Contains.Substring("new leader is not a member")); Assert.AreEqual(StatusCode.FailedPrecondition, exception.StatusCode); }
public void ReturnPermissionDeniedWhenPlayerIsNotTheLeader() { // Setup the client such that it will claim that the party has as leader a different player other than the // one making the request. var party = new PartyDataModel(_testParty); party.UpdatePartyLeader(TestPlayerId2); _mockMemoryStoreClient.Setup(client => client.GetAsync <PartyDataModel>(_testUpdatedParty.Id)).ReturnsAsync(party); // Check that an exception was thrown signaling that the update operation failed. var context = Util.CreateFakeCallContext(TestPlayerId, Pit); var request = new UpdatePartyRequest { UpdatedParty = _testUpdatedParty }; var exception = Assert.ThrowsAsync <RpcException>(() => _partyService.UpdateParty(request, context)); Assert.That(exception.Message, Contains.Substring("can only be done by the leader")); Assert.AreEqual(StatusCode.PermissionDenied, exception.StatusCode); }
public void ReturnFailedPreconditionIfEncounteringErrorWhileUpdatingMemberLimits() { _mockMemoryStoreClient.Setup(client => client.GetAsync <PartyDataModel>(_testUpdatedParty.Id)) .ReturnsAsync(_testParty); // Perform a request where the updated value of maxMembers is less than the current amount of members. var updatedParty = new PartyProto(_testUpdatedParty) { MinMembers = 1, MaxMembers = 1 }; var request = new UpdatePartyRequest { UpdatedParty = updatedParty }; // Check that an exception was thrown signaling that the update operation failed. var context = Util.CreateFakeCallContext(TestPlayerId, Pit); var exception = Assert.ThrowsAsync <RpcException>(() => _partyService.UpdateParty(request, context)); Assert.That(exception.Message, Contains.Substring("error while updating the minimum and maximum")); Assert.AreEqual(StatusCode.FailedPrecondition, exception.StatusCode); }