public async Task FindPlayerGameCredential_ShouldBeOfTypeFindPlayerGameCredentialResponse() { // Arrange var userId = new UserId(); const string email = "*****@*****.**"; var claims = new[] { new Claim(JwtClaimTypes.Subject, userId.ToString()), new Claim(JwtClaimTypes.Email, email) }; var host = TestHost.WithClaimsFromBearerAuthentication(claims); host.Server.CleanupDbContext(); await host.Server.UsingScopeAsync( async scope => { var credentialRepository = scope.GetRequiredService <IGameCredentialRepository>(); var credential = new Credential( userId, Game.LeagueOfLegends, new PlayerId(), new UtcNowDateTimeProvider()); credentialRepository.CreateCredential(credential); await credentialRepository.UnitOfWork.CommitAsync(); }); var request = new FindPlayerGameCredentialRequest { Game = EnumGame.LeagueOfLegends }; var client = new GameService.GameServiceClient(host.CreateChannel()); // Act var response = await client.FindPlayerGameCredentialAsync(request); //Assert response.Should().BeOfType <FindPlayerGameCredentialResponse>(); }
public void FindPlayerGameCredential_ShouldThrowNotFoundRpcException() { // Arrange var userId = new UserId(); const string email = "*****@*****.**"; var claims = new[] { new Claim(JwtClaimTypes.Subject, userId.ToString()), new Claim(JwtClaimTypes.Email, email) }; var host = TestHost.WithClaimsFromBearerAuthentication(claims); host.Server.CleanupDbContext(); var request = new FindPlayerGameCredentialRequest { Game = EnumGame.LeagueOfLegends }; var client = new GameService.GameServiceClient(host.CreateChannel()); // Act Assert var func = new Func <Task>(async() => await client.FindPlayerGameCredentialAsync(request)); func.Should().Throw <RpcException>(); }
public override async Task <FindPlayerGameCredentialResponse> FindPlayerGameCredential( FindPlayerGameCredentialRequest request, ServerCallContext context ) { var httpContext = context.GetHttpContext(); var userId = httpContext.GetUserId(); var credential = await _gameCredentialService.FindCredentialAsync(userId, request.Game.ToEnumeration <Game>()); if (credential == null) { throw context.NotFoundRpcException("Game credential not found."); } var response = new FindPlayerGameCredentialResponse { Credential = _mapper.Map <GameCredentialDto>(credential) }; return(context.Ok(response)); }
public async Task <IActionResult> RegisterChallengeParticipantAsync(string challengeId) { var participantId = new ParticipantId(); var findChallengeRequest = new FindChallengeRequest { ChallengeId = challengeId }; var findChallengeResponse = await _challengesServiceClient.FindChallengeAsync(findChallengeRequest); var findPlayerGameCredentialRequest = new FindPlayerGameCredentialRequest { Game = findChallengeResponse.Challenge.Game }; var findPlayerGameCredentialResponse = await _gameServiceClient.FindPlayerGameCredentialAsync(findPlayerGameCredentialRequest); var fetchDoxatagsRequest = new FetchDoxatagsRequest(); var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest); var findChallengePayoutRequest = new FindChallengePayoutRequest { ChallengeId = challengeId }; var challengePayoutResponse = await _cashierServiceClient.FindChallengePayoutAsync(findChallengePayoutRequest); var createTransactionRequest = new CreateTransactionRequest { Custom = new CustomTransaction { Type = EnumTransactionType.Charge, Currency = challengePayoutResponse.Payout.EntryFee }, Metadata = { new Dictionary <string, string> { [nameof(ChallengeId)] = challengeId, [nameof(ParticipantId)] = participantId } } }; var createTransactionResponse = await _cashierServiceClient.CreateTransactionAsync(createTransactionRequest); try { var registerChallengeParticipantRequest = new RegisterChallengeParticipantRequest { ChallengeId = challengeId, GamePlayerId = findPlayerGameCredentialResponse.Credential.PlayerId, ParticipantId = participantId }; var participant = await _challengesServiceClient.RegisterChallengeParticipantAsync(registerChallengeParticipantRequest); return(this.Ok(ChallengeMapper.Map(challengePayoutResponse.Payout.ChallengeId, participant.Participant, fetchDoxatagsResponse.Doxatags))); } catch (RpcException exception) { var deleteTransactionRequest = new DeleteTransactionRequest { TransactionId = createTransactionResponse.Transaction.Id }; await _cashierServiceClient.DeleteTransactionAsync(deleteTransactionRequest); throw exception.Capture(); } }