Exemplo n.º 1
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>();
        }
Exemplo n.º 2
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)));
        }
Exemplo n.º 3
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>();
        }
Exemplo n.º 4
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();
            }
        }