Ejemplo n.º 1
0
        public async Task SnapshotChallengeParticipant_ShouldThrowFailedPreconditionRpcException()
        {
            // 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.Two,
                    new ChallengeTimeline(new UtcNowDateTimeProvider(), ChallengeDuration.FiveDays),
                    new Scoring());

                challenge.Register(
                    new Participant(
                        new ParticipantId(),
                        new UserId(),
                        new PlayerId(),
                        new UtcNowDateTimeProvider()));

                challenge.Register(
                    new Participant(
                        new ParticipantId(),
                        new UserId(),
                        new PlayerId(),
                        new UtcNowDateTimeProvider()));

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

            var request = new SnapshotChallengeParticipantRequest
            {
                ChallengeId  = challengeId,
                GamePlayerId = new PlayerId()
            };

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

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

            func.Should().Throw <RpcException>();
        }
Ejemplo n.º 2
0
        public async Task SynchronizeChallengesAsync(EnumGame game)
        {
            foreach (var challenge in await this.FetchChallengesAsync(game))
            {
                var fetchChallengeMatchesRequest = new FetchChallengeMatchesRequest
                {
                    Game         = game,
                    StartedAt    = challenge.Timeline.StartedAt,
                    EndedAt      = challenge.Timeline.EndedAt,
                    Participants =
                    {
                        challenge.Participants
                    }
                };

                await foreach (var fetchChallengeMatchesResponse in _gameServiceClient.FetchChallengeMatches(fetchChallengeMatchesRequest)
                               .ResponseStream.ReadAllAsync())
                {
                    var snapshotChallengeParticipantRequest = new SnapshotChallengeParticipantRequest
                    {
                        ChallengeId  = challenge.Id,
                        GamePlayerId = fetchChallengeMatchesResponse.GamePlayerId,
                        Matches      =
                        {
                            fetchChallengeMatchesResponse.Matches
                        }
                    };

                    await _challengeServiceClient.SnapshotChallengeParticipantAsync(snapshotChallengeParticipantRequest);
                }

                var synchronizeChallengeRequest = new SynchronizeChallengeRequest
                {
                    ChallengeId = challenge.Id
                };

                await _challengeServiceClient.SynchronizeChallengeAsync(synchronizeChallengeRequest);
            }
        }
Ejemplo n.º 3
0
        public void SnapshotChallengeParticipant_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 SnapshotChallengeParticipantRequest
            {
                ChallengeId  = new ChallengeId(),
                GamePlayerId = new PlayerId()
            };

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

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

            func.Should().Throw <RpcException>();
        }