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>(); }
public void FetchChallengeMatches_ShouldBeOfTypeFetchChallengeMatchesResponse() { // 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 FetchChallengeMatchesRequest { Game = EnumGame.LeagueOfLegends, EndedAt = DateTime.UtcNow.ToTimestamp(), StartedAt = (DateTime.UtcNow - TimeSpan.FromDays(1)).ToTimestamp(), Participants = { new ChallengeParticipantDto { ChallengeId = new ChallengeId(), GamePlayerId = "testID1", Id = new Guid().ToString(), Score = 10, SynchronizedAt = DateTime.UtcNow.ToTimestamp(), UserId = new UserId() }, new ChallengeParticipantDto { ChallengeId = new ChallengeId(), GamePlayerId = "testID2", Id = new Guid().ToString(), Score = 20, SynchronizedAt = DateTime.UtcNow.ToTimestamp(), UserId = new UserId() }, new ChallengeParticipantDto { ChallengeId = new ChallengeId(), GamePlayerId = "testID3", Id = new Guid().ToString(), Score = 50, SynchronizedAt = DateTime.UtcNow.ToTimestamp(), UserId = new UserId() } } }; var client = new GameService.GameServiceClient(host.CreateChannel()); // Act var response = client.FetchChallengeMatches(request); //Assert response.Should().BeOfType <AsyncServerStreamingCall <FetchChallengeMatchesResponse> >(); }
public ChallengesController( IdentityService.IdentityServiceClient identityServiceClient, ChallengeService.ChallengeServiceClient challengesServiceClient, CashierService.CashierServiceClient cashierServiceClient, GameService.GameServiceClient gameServiceClient ) { _identityServiceClient = identityServiceClient; _challengesServiceClient = challengesServiceClient; _cashierServiceClient = cashierServiceClient; _gameServiceClient = gameServiceClient; }
private async Task ListenChat(GameService.GameServiceClient client, Channel channel) { try { using (var call = client.ListenChat(new Empty())) using (var chatStream = call.ResponseStream) { while (await chatStream.MoveNext(channel.ShutdownToken)) { ChatMessageRecived?.Invoke(chatStream.Current.Nickname, chatStream.Current.StickerID); } } } catch (Exception e) { Debug.LogError(e); throw; } }
public async Task FetchChallengeMatches( string playerId, DateTime startedAt, DateTime endedAt, int count ) { // 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 client = new GameService.GameServiceClient(TestHost.CreateChannel()); var matches = new List <GameMatchDto>(); await foreach (var fetchChallengeMatchesResponse in client.FetchChallengeMatches( new FetchChallengeMatchesRequest { Game = EnumGame.LeagueOfLegends, StartedAt = startedAt.ToTimestamp(), EndedAt = endedAt.ToTimestamp(), Participants = { new ChallengeParticipantDto { Id = new ParticipantId(), GamePlayerId = playerId } } }) .ResponseStream.ReadAllAsync()) { matches.AddRange(fetchChallengeMatchesResponse.Matches); } matches.Should().HaveCount(count); }
public async Task FindPlayerGameCredential_ShouldBeOfTypeFindPlayerGameCredentialResponse() { // 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(); await host.Server.UsingScopeAsync( async scope => { var credentialRepository = scope.GetRequiredService <IGameCredentialRepository>(); var credential = new Credential( userId, Game.LeagueOfLegends, new PlayerId(), new UtcNowDateTimeProvider()); credentialRepository.CreateCredential(credential); await credentialRepository.UnitOfWork.CommitAsync(); }); var request = new FindPlayerGameCredentialRequest { Game = EnumGame.LeagueOfLegends }; var client = new GameService.GameServiceClient(host.CreateChannel()); // Act var response = await client.FindPlayerGameCredentialAsync(request); //Assert response.Should().BeOfType <FindPlayerGameCredentialResponse>(); }
public void FindPlayerGameCredential_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 FindPlayerGameCredentialRequest { Game = EnumGame.LeagueOfLegends }; var client = new GameService.GameServiceClient(host.CreateChannel()); // Act Assert var func = new Func <Task>(async() => await client.FindPlayerGameCredentialAsync(request)); func.Should().Throw <RpcException>(); }
public async Task Success() { // Arrange var mockServiceBusPubliser = new Mock <IServiceBusPublisher>(); mockServiceBusPubliser.Setup(serviceBusPubliser => serviceBusPubliser.PublishAsync(It.IsAny <ChallengeParticipantRegisteredIntegrationEvent>())) .Verifiable(); var user = new User { Id = Guid.NewGuid(), Email = "*****@*****.**", EmailConfirmed = true, UserName = "******", Country = Country.Canada }; var account = new Account(user.Id.ConvertTo <UserId>()); var moneyAccount = new MoneyAccountDecorator(account); moneyAccount.Deposit(Money.TwoHundred).MarkAsSucceeded(); var doxatag = new Doxatag( account.Id, "TestUser", 1000, new UtcNowDateTimeProvider()); var gamePlayerId = new PlayerId(); var challenge = new Challenge( new ChallengeId(), new ChallengeName("TestChallenge"), Game.LeagueOfLegends, BestOf.One, Entries.Two, new ChallengeTimeline(new UtcNowDateTimeProvider(), ChallengeDuration.OneDay), Scoring); var payout = new ChallengePayoutFactory(); var challengePayout = new Cashier.Domain.AggregateModels.ChallengeAggregate.Challenge( challenge.Id, payout.CreateInstance().GetChallengePayout(ChallengePayoutEntries.One, MoneyEntryFee.OneHundred)); using var gamesHost = new GamesHostFactory().WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, account.Id)); gamesHost.Server.CleanupDbContext(); await gamesHost.Server.UsingScopeAsync( async scope => { var gameCredentialRepository = scope.GetRequiredService <IGameCredentialRepository>(); gameCredentialRepository.CreateCredential( new Credential( account.Id, challenge.Game, gamePlayerId, new UtcNowDateTimeProvider())); await gameCredentialRepository.UnitOfWork.CommitAsync(false); }); var gameServiceClient = new GameService.GameServiceClient(gamesHost.CreateChannel()); using var challengesHost = new ChallengesHostFactory().WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, account.Id)) .WithWebHostBuilder( builder => { builder.ConfigureTestContainer <ContainerBuilder>( container => { container.RegisterInstance(mockServiceBusPubliser.Object).As <IServiceBusPublisher>().SingleInstance(); }); }); challengesHost.Server.CleanupDbContext(); await challengesHost.Server.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(false); }); var challengeServiceClient = new ChallengeService.ChallengeServiceClient(challengesHost.CreateChannel()); using var cashierHost = new CashierHostFactory().WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, account.Id)); cashierHost.Server.CleanupDbContext(); await cashierHost.Server.UsingScopeAsync( async scope => { var accountRepository = scope.GetRequiredService <IAccountRepository>(); accountRepository.Create(account); await accountRepository.CommitAsync(); }); await cashierHost.Server.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengePayoutRepository>(); challengeRepository.Create(challengePayout); await challengeRepository.CommitAsync(); }); var cashierServiceClient = new CashierService.CashierServiceClient(cashierHost.CreateChannel()); using var identityHost = new IdentityHostFactory(); identityHost.Server.CleanupDbContext(); await identityHost.Server.UsingScopeAsync( async scope => { var doxatagRepository = scope.GetRequiredService <IUserService>(); await doxatagRepository.CreateAsync(user, "Pass@word1"); }); await identityHost.Server.UsingScopeAsync( async scope => { var doxatagRepository = scope.GetRequiredService <IDoxatagRepository>(); doxatagRepository.Create(doxatag); await doxatagRepository.UnitOfWork.CommitAsync(false); }); var identityServiceClient = new IdentityService.IdentityServiceClient(identityHost.CreateChannel()); using var challengesAggregatorHost = new ChallengesWebAggregatorHostFactory() .WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, account.Id)) .WithWebHostBuilder( builder => { builder.ConfigureTestContainer <ContainerBuilder>( container => { container.RegisterInstance(challengeServiceClient).SingleInstance(); container.RegisterInstance(cashierServiceClient).SingleInstance(); container.RegisterInstance(identityServiceClient).SingleInstance(); container.RegisterInstance(gameServiceClient).SingleInstance(); }); }); var client = challengesAggregatorHost.CreateClient(); // Act var response = await client.PostAsJsonAsync( $"api/challenges/{challenge.Id}/participants", new { }); // Assert response.EnsureSuccessStatusCode(); mockServiceBusPubliser.Verify( serviceBusPubliser => serviceBusPubliser.PublishAsync(It.IsAny <ChallengeParticipantRegisteredIntegrationEvent>()), Times.Once); }
private async Task ListenGameState(Channel channel) { var mapState = new ClientMapData(); var playerState = new ClientPlayerState(); await mSyncContext.Execute(() => PlayerConnected?.Invoke(playerState), channel.ShutdownToken); try { while (true) { try { mGameService = new GameService.GameServiceClient(channel); using (var call = mGameService.ConnectAndListenState(new Empty())) using (var stateStream = call.ResponseStream) { while (await stateStream.MoveNext(channel.ShutdownToken)) { channel.ShutdownToken.ThrowIfCancellationRequested(); var state = stateStream.Current; if (state.Map != null) { mapState.State = new MapState(state.Map); } if (state.Player != null) { playerState.PlayerState = new PlayerState(state.Player); } channel.ShutdownToken.ThrowIfCancellationRequested(); if (!mMapLoaded) { mMapLoaded = true; await mSyncContext.Execute(() => { MapLoaded?.Invoke(mapState); BaseCreated?.Invoke(state.BasePos.ToUnity()); }, channel.ShutdownToken); var tChat = ListenChat(mGameService, channel); var t0 = mWorkerCreationStateListener.ListenCreations(mChannel); var t1 = mBuildingTemplateCreationStateListener.ListenCreations(mChannel); var t2 = mCentralBuildingCreationStateListener.ListenCreations(mChannel); var t3 = mMiningCampCreationListener.ListenCreations(mChannel); var t4 = mBarrakCreationListener.ListenCreations(mChannel); var t5 = mRangedWarriorCreationStateListener.ListenCreations(mChannel); var t6 = mMeeleeWarriorCreationStateListener.ListenCreations(mChannel); } } } break; } catch (RpcException e) { if (e.Status.StatusCode != StatusCode.Unavailable) { throw; } await Task.Delay(TimeSpan.FromSeconds(0.5)); } } } catch (Exception e) { Debug.LogError(e); DisconnectedFromServer?.Invoke(); throw; } }
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)); }
public ClientImplementation(GameService.GameServiceClient client) { this._client = client; }
public ChallengeRecurringJob(ChallengeService.ChallengeServiceClient challengeServiceClient, GameService.GameServiceClient gameServiceClient) { _challengeServiceClient = challengeServiceClient; _gameServiceClient = gameServiceClient; }