示例#1
0
        public async Task FetchChallengeScoring_ShouldBeOfTypeFetchChallengeScoringResponse()
        {
            // 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 FindChallengeScoringRequest
            {
                Game          = EnumGame.LeagueOfLegends,
                ChallengeType = EnumChallengeType.All
            };

            var client = new GameService.GameServiceClient(host.CreateChannel());

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

            //Assert
            response.Should().BeOfType <FindChallengeScoringResponse>();
        }
示例#2
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();
            }
        }
示例#3
0
        public async Task Success2()
        {
            // Arrange
            using var gamesHost = new GamesHostFactory();

            var gamesServiceClient = new GameService.GameServiceClient(gamesHost.CreateChannel());

            var findChallengeScoringRequest = new FindChallengeScoringRequest
            {
                Game = EnumGame.LeagueOfLegends
            };

            var findChallengeScoringResponse = await gamesServiceClient.FindChallengeScoringAsync(findChallengeScoringRequest);

            var createdAt = new DateTimeProvider(
                new DateTime(
                    2019,
                    12,
                    30,
                    21,
                    9,
                    22,
                    DateTimeKind.Utc));

            var startedAt = new DateTimeProvider(
                new DateTime(
                    2019,
                    12,
                    30,
                    22,
                    42,
                    50,
                    DateTimeKind.Utc));

            var challenge = new Challenge(
                new ChallengeId(),
                new ChallengeName("TEST CHALLENGE"),
                Game.LeagueOfLegends,
                BestOf.One,
                Entries.Two,
                new ChallengeTimeline(createdAt, ChallengeDuration.OneDay),
                new Scoring(
                    findChallengeScoringResponse.Scoring.Items.OrderBy(scoring => scoring.Order)
                    .ToDictionary(scoring => scoring.StatName, scoring => scoring.StatWeighting)));

            var participant = new Participant(
                new ParticipantId(),
                new UserId(),
                PlayerId.Parse("V1R8S4W19KGdqSTn-rRO-pUGv6lfu2BkdVCaz_8wd-m6zw"),
                new DateTimeProvider(createdAt.DateTime + TimeSpan.FromMinutes(5)));

            challenge.Register(participant);

            challenge.Register(
                new Participant(
                    new ParticipantId(),
                    new UserId(),
                    new PlayerId(),
                    new DateTimeProvider(createdAt.DateTime + TimeSpan.FromMinutes(10))));

            challenge.Start(startedAt);

            var mockServiceBusPublisher = new Mock <IServiceBusPublisher>();

            mockServiceBusPublisher.Setup(serviceBusPublisher => serviceBusPublisher.PublishAsync(It.IsAny <ChallengeSynchronizedIntegrationEvent>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            using var challengesHost = new ChallengesHostFactory().WithWebHostBuilder(
                      builder =>
            {
                builder.ConfigureTestContainer <ContainerBuilder>(
                    container =>
                {
                    container.RegisterInstance(mockServiceBusPublisher.Object).As <IServiceBusPublisher>().SingleInstance();
                });
            });

            challengesHost.Server.CleanupDbContext();

            await challengesHost.Server.UsingScopeAsync(
                async scope =>
            {
                var repository = scope.GetRequiredService <IChallengeRepository>();

                repository.Create(challenge);

                await repository.CommitAsync(false);
            });

            var recurringJob = new ChallengeRecurringJob(
                new ChallengeService.ChallengeServiceClient(challengesHost.CreateChannel()),
                new GameService.GameServiceClient(gamesHost.CreateChannel()));

            // Act
            await recurringJob.SynchronizeChallengesAsync(EnumGame.LeagueOfLegends);

            // Assert
            await challengesHost.Server.UsingScopeAsync(
                async scope =>
            {
                var repository = scope.GetRequiredService <IChallengeRepository>();

                var persistentChallenge = await repository.FindChallengeAsync(challenge.Id);

                persistentChallenge.FindParticipant(participant.PlayerId).Matches.Should().HaveCount(2);
            });

            mockServiceBusPublisher.Verify(
                serviceBusPublisher => serviceBusPublisher.PublishAsync(It.IsAny <ChallengeSynchronizedIntegrationEvent>()),
                Times.Exactly(1));
        }
示例#4
0
 public override async Task <FindChallengeScoringResponse> FindChallengeScoring(FindChallengeScoringRequest request, ServerCallContext context)
 {
     return(new FindChallengeScoringResponse
     {
         Scoring = await _challengeService.GetScoringAsync(request.Game.ToEnumeration <Game>())
     });
 }