Exemplo n.º 1
0
        public async Task CreateChallengePayout_ShouldBeOfTypeFindChallengePayoutResponse()
        {
            // 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 CreateChallengePayoutRequest
            {
                ChallengeId = new ChallengeId(),
                EntryFee    = new CurrencyDto
                {
                    Amount = 20,
                    Type   = EnumCurrencyType.Money
                },
                PayoutEntries = 10
            };

            var client = new CashierService.CashierServiceClient(host.CreateChannel());

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

            //Assert
            response.Should().BeOfType <CreateChallengePayoutResponse>();
        }
Exemplo n.º 2
0
        public void CreateChallengePayout_ShouldThrowFailedPreconditionRpcException()
        {
            // 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 CreateChallengePayoutRequest
            {
                ChallengeId = new ChallengeId(),
                EntryFee    = new CurrencyDto
                {
                    Amount = 20,
                    Type   = EnumCurrencyType.Money
                }
            };

            var client = new CashierService.CashierServiceClient(host.CreateChannel());

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

            // Assert
            func.Should().Throw <RpcException>();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateChallengeAsync([FromBody] Requests.CreateChallengeRequest request)
        {
            var fetchDoxatagsRequest = new FetchDoxatagsRequest();

            var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest);

            var findChallengeScoringRequest = new FindChallengeScoringRequest
            {
                Game = request.Game
            };

            var findChallengeScoringResponse = await _gameServiceClient.FindChallengeScoringAsync(findChallengeScoringRequest);

            var createChallengeRequest = new CreateChallengeRequest
            {
                Name     = request.Name,
                Game     = request.Game,
                BestOf   = request.BestOf,
                Entries  = request.Entries,
                Duration = request.Duration,
                Scoring  = findChallengeScoringResponse.Scoring
            };

            var createChallengeResponse = await _challengesServiceClient.CreateChallengeAsync(createChallengeRequest);

            try
            {
                var createChallengePayoutRequest = new CreateChallengePayoutRequest
                {
                    ChallengeId   = createChallengeResponse.Challenge.Id,
                    PayoutEntries = createChallengeResponse.Challenge.Entries / 2, // TODO
                    EntryFee      = new CurrencyDto
                    {
                        Amount = request.EntryFee.Amount,
                        Type   = request.EntryFee.Type
                    }
                };

                var createChallengePayoutResponse = await _cashierServiceClient.CreateChallengePayoutAsync(createChallengePayoutRequest);

                return(this.Ok(ChallengeMapper.Map(createChallengeResponse.Challenge, createChallengePayoutResponse.Payout, fetchDoxatagsResponse.Doxatags)));
            }
            catch (RpcException exception)
            {
                var deleteChallengeRequest = new DeleteChallengeRequest
                {
                    ChallengeId = createChallengeResponse.Challenge.Id
                };

                await _challengesServiceClient.DeleteChallengeAsync(deleteChallengeRequest);

                throw exception.Capture();
            }
        }
Exemplo n.º 4
0
        public override async Task <CreateChallengePayoutResponse> CreateChallengePayout(CreateChallengePayoutRequest request, ServerCallContext context)
        {
            var result = await _challengeService.CreateChallengeAsync(
                request.ChallengeId.ParseEntityId <ChallengeId>(),
                new ChallengePayoutEntries(request.PayoutEntries),
                new EntryFee(request.EntryFee.Amount, request.EntryFee.Type.ToEnumeration <CurrencyType>()));

            if (result.IsValid)
            {
                var response = new CreateChallengePayoutResponse
                {
                    Payout = _mapper.Map <ChallengePayoutDto>(result.Response)
                };

                return(context.Ok(response));
            }

            throw context.FailedPreconditionRpcException(result);
        }