예제 #1
0
        public override async Task <FindChallengeResponse> FindChallenge(FindChallengeRequest request, ServerCallContext context)
        {
            var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>();

            if (!await _challengeService.ChallengeExistsAsync(challengeId))
            {
                throw context.NotFoundRpcException("Challenge not found.");
            }

            var challenge = await _challengeQuery.FindChallengeAsync(challengeId);

            var response = new FindChallengeResponse
            {
                Challenge = ChallengeProfile.Map(challenge !)
            };

            return(context.Ok(response));
        }
예제 #2
0
        public async Task FindChallenge_ShouldBeOfTypeFindChallengeResponse()
        {
            // Arrange
            var          userId      = new UserId();
            const string email       = "*****@*****.**";
            var          challengeId = new ChallengeId();

            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 challengeRepository = scope.GetRequiredService <IChallengeRepository>();

                var challenge = new Challenge(
                    challengeId,
                    new ChallengeName("test"),
                    Game.LeagueOfLegends,
                    BestOf.Five,
                    Entries.Eight,
                    new ChallengeTimeline(new UtcNowDateTimeProvider(), ChallengeDuration.FiveDays),
                    new Scoring());

                challengeRepository.Create(challenge);
                await challengeRepository.CommitAsync(false);
            });

            var request = new FindChallengeRequest
            {
                ChallengeId = challengeId
            };

            var client = new ChallengeService.ChallengeServiceClient(host.CreateChannel());

            // Act
            var response = await client.FindChallengeAsync(request);

            //Assert
            response.Should().BeOfType <FindChallengeResponse>();
        }
예제 #3
0
        public async Task <IActionResult> FindChallengeAsync(string challengeId)
        {
            var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(new FetchDoxatagsRequest());

            var findChallengePayoutRequest = new FindChallengePayoutRequest
            {
                ChallengeId = challengeId
            };

            var findChallengePayoutResponse = await _cashierServiceClient.FindChallengePayoutAsync(findChallengePayoutRequest);

            var findChallengeRequest = new FindChallengeRequest
            {
                ChallengeId = challengeId
            };

            var findChallengeResponse = await _challengesServiceClient.FindChallengeAsync(findChallengeRequest);

            return(this.Ok(ChallengeMapper.Map(findChallengeResponse.Challenge, findChallengePayoutResponse.Payout, fetchDoxatagsResponse.Doxatags)));
        }
예제 #4
0
        public void FindChallenge_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 FindChallengeRequest
            {
                ChallengeId = new ChallengeId()
            };

            var client = new ChallengeService.ChallengeServiceClient(host.CreateChannel());

            // Act Assert
            var func = new Func <Task>(async() => await client.FindChallengeAsync(request));

            func.Should().Throw <RpcException>();
        }
예제 #5
0
        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();
            }
        }
 /// <summary>
 /// Begin a new FindChallengeRequest
 /// </summary>
 /// <param name="requestData"></param>
 /// <returns></returns>
 public FindChallengeResponse FindChallengeRequest(FindChallengeRequest requestData)
 {
     return(JsonConvert.DeserializeObject <FindChallengeResponse>(Requestor.PostString(Urls.FindChallengeRequest, JsonHelper.SerializeData(requestData)).ResponseJson));
 }
        /// <summary>
        /// Begin a new asynchronous FindChallengeRequest
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public async Task <FindChallengeResponse> FindChallengeRequestAsync(FindChallengeRequest requestData)
        {
            var res = await Requestor.PostStringAsync(Urls.FindChallengeRequest, JsonHelper.SerializeData(requestData));

            return(JsonConvert.DeserializeObject <FindChallengeResponse>(res.ResponseJson));
        }