Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        public void CreateChallenge_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 CreateChallengeRequest();

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

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

            func.Should().Throw <RpcException>();
        }
Ejemplo n.º 3
0
        public async Task CreateChallenge_ShouldBeOfTypeCreateChallengeResponse()
        {
            // 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 CreateChallengeRequest
            {
                BestOf   = BestOf.Five,
                Duration = 5,
                Entries  = Entries.Four,
                Game     = EnumGame.LeagueOfLegends,
                Name     = "Test",
                Scoring  = new ChallengeScoringDto
                {
                    Items =
                    {
                        new ChallengeScoringDto.Types.Item
                        {
                            StatName      = "StatName",
                            StatWeighting = 5F,
                            Order         = 0
                        }
                    }
                }
            };

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

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

            //Assert
            response.Should().BeOfType <CreateChallengeResponse>();
        }