示例#1
0
        public async Task GetTeamStatsAsync_GetsTheTeamStats()
        {
            var expectedDto = new TeamStatsDto
            {
                Year          = 2017,
                Week          = 10,
                TeamId        = "NYG",
                TeamName      = "New York Giants",
                GamesPlayed   = 10,
                Wins          = 2,
                Losses        = 8,
                PointsFor     = 188,
                PointsAgainst = 202
            };

            TeamStatsDto actualDto;

            using (new TransactionScope(TransactionScopeOption.RequiresNew,
                                        TransactionScopeAsyncFlowOption.Enabled))
            {
                await _repository.UpsertTeamStatsAsync(expectedDto);

                actualDto = await _repository.GetTeamStatsAsync(expectedDto.TeamId, expectedDto.Year, expectedDto.Week);
            }

            actualDto.TeamId.Should().Be(expectedDto.TeamId);
            actualDto.TeamName.Should().Be(expectedDto.TeamName);
            actualDto.Year.Should().Be(expectedDto.Year);
            actualDto.Week.Should().Be(expectedDto.Week);
            actualDto.GamesPlayed.Should().Be(expectedDto.GamesPlayed);
            actualDto.Wins.Should().Be(expectedDto.Wins);
            actualDto.Losses.Should().Be(expectedDto.Losses);
            actualDto.PointsFor.Should().Be(expectedDto.PointsFor);
            actualDto.PointsAgainst.Should().Be(expectedDto.PointsAgainst);
        }
示例#2
0
        public async Task UpsertTeamStatsAsync_Duplicate_Year_Week_TeamId_Test()
        {
            var dto = new TeamStatsDto
            {
                Year          = 2017,
                Week          = 10,
                TeamId        = "NYG",
                TeamName      = "New York Giants",
                GamesPlayed   = 10,
                Wins          = 2,
                Losses        = 8,
                PointsFor     = 188,
                PointsAgainst = 202
            };

            TeamStatsDto actualDto = null;

            using (new TransactionScope(TransactionScopeOption.RequiresNew,
                                        TransactionScopeAsyncFlowOption.Enabled))
            {
                await _repository.UpsertTeamStatsAsync(dto);

                await _repository.UpsertTeamStatsAsync(dto);

                actualDto = await _repository.GetTeamStatsAsync(dto.TeamId, dto.Year, dto.Week);
            }

            actualDto.Should().NotBeNull();
        }
        public async Task Get_Returns_Team_Stats_With_Ok_Status_Code()
        {
            var expectedDto = new TeamStatsDto
            {
                TeamId        = "NYG",
                Year          = 2017,
                Week          = 10,
                TeamName      = "New York Giants",
                GamesPlayed   = 10,
                Losses        = 8,
                Wins          = 2,
                PointsFor     = 202,
                PointsAgainst = 213
            };

            _mockRepository.Setup(m => m.GetTeamStatsAsync(expectedDto.TeamId, expectedDto.Year, expectedDto.Week))
            .ReturnsAsync(expectedDto);

            var response = await _httpClient.GetAsync($"api/v1/stats/teams/{expectedDto.TeamId}/{expectedDto.Year}/{expectedDto.Week}");

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var actualDto =
                JsonConvert.DeserializeObject <GetTeamStatsResponse>(await response.Content.ReadAsStringAsync());

            actualDto.TeamId.Should().Be(expectedDto.TeamId);
            actualDto.TeamName.Should().Be(expectedDto.TeamName);
            actualDto.GamesPlayed.Should().Be(expectedDto.GamesPlayed);
            actualDto.Losses.Should().Be(expectedDto.Losses);
            actualDto.Wins.Should().Be(expectedDto.Wins);
            actualDto.PointsFor.Should().Be(expectedDto.PointsFor);
            actualDto.PointsAgainst.Should().Be(expectedDto.PointsAgainst);
            actualDto.Year.Should().Be(expectedDto.Year);
            actualDto.Week.Should().Be(expectedDto.Week);
        }
示例#4
0
        public async Task Update(TeamStatsDto dto)
        {
            await _teamStatsRepository.UpsertTeamStatsAsync(dto);

            await StateManager.SetStateAsync(GetActorId(), new TeamStatsDto
            {
                Year          = dto.Year,
                TeamId        = dto.TeamId,
                TeamName      = dto.TeamName,
                GamesPlayed   = dto.GamesPlayed,
                Losses        = dto.Losses,
                Wins          = dto.Wins,
                PointsFor     = dto.PointsFor,
                PointsAgainst = dto.PointsAgainst,
                Week          = dto.Week
            });
        }
示例#5
0
        public async Task UpsertTeamStatsAsync(TeamStatsDto dto)
        {
            var query = @"MERGE [dbo].[TeamStats] as target
                            using (SELECT @TeamId, @Year, @Week, @TeamName, @PointsFor, @PointsAgainst, @Wins, @Losses, @GamesPlayed) AS source
                                    ([TeamId], [Year], [Week], [TeamName], [PointsFor], [PointsAgainst], [Wins], [Losses], [GamesPlayed])
                            ON (target.[TeamId] = source.[TeamId])
                            WHEN MATCHED THEN
                                UPDATE SET
                                    [TeamId] = source.[TeamId],
                                    [Year] = source.[Year],
                                    [Week] = source.[Week],
                                    [TeamName] = source.[TeamName],
                                    [PointsFor] = source.[PointsFor],
                                    [PointsAgainst] = source.[PointsAgainst],
                                    [Wins] = source.[Wins],
                                    [Losses] = source.[Losses],
                                    [GamesPlayed] = source.[GamesPlayed],
                                    [LastUpdated] = getutcdate()
                            WHEN NOT MATCHED THEN
                                INSERT ([TeamId], [Year], [Week], [TeamName], [PointsFor], [PointsAgainst], [Wins], [Losses], [GamesPlayed], [Created])
                                VALUES (source.[TeamId], source.[Year], source.[Week], source.[TeamName], source.[PointsFor], source.[PointsAgainst], source.[Wins], source.[Losses], source.[GamesPlayed], getutcdate());";

            using (var connection = new SqlConnection(_settings.ConnectionString))
            {
                await connection.OpenAsync();

                await connection.ExecuteScalarAsync(
                    query,
                    new
                {
                    dto.TeamId,
                    dto.Year,
                    dto.Week,
                    dto.TeamName,
                    dto.PointsFor,
                    dto.PointsAgainst,
                    dto.Wins,
                    dto.Losses,
                    dto.GamesPlayed
                },
                    commandTimeout : (int)_settings.QueryTimeout.TotalSeconds);
            }
        }
        public async Task Put_Returns_Created_Status_Code_And_Location_In_Header()
        {
            var expectedDto = new TeamStatsDto
            {
                TeamId = "foo"
            };

            _mockRepository.Setup(m => m.UpsertTeamStatsAsync(expectedDto)).Returns(Task.FromResult(0));

            var requestModel = new PutTeamStatsRequest
            {
                TeamId = expectedDto.TeamId
            };

            var response = await _httpClient.PutAsync("api/v1/stats/teams", Stringify(requestModel));

            response.StatusCode.Should().Be(HttpStatusCode.Created);
            response.Headers.Location.Should().Be($"http://localhost/api/v1/stats/teams/{expectedDto.TeamId}/{expectedDto.Year}/{expectedDto.Week}");
        }
示例#7
0
        public MatchHistory(BaseModelView viewManager)
        {
            InitializeComponent();
            this.DataContext = viewManager;

            for (int i = 0; i < viewManager.MatchEntries.Count; i++)
            {
                int      champId    = viewManager.MatchlistEntry.Matches[i].Champion;
                string   champName  = viewManager.FullChampionNames[champId.ToString()];
                string   posName    = viewManager.MatchlistEntry.Matches[i].Lane;
                string   roleName   = viewManager.MatchlistEntry.Matches[i].Role;
                int      queueId    = viewManager.MatchlistEntry.Matches[i].Queue;
                Queues   gameQueue  = viewManager.AllQueuesList.Where(p => p.QueueId == queueId).FirstOrDefault();
                string   mapName    = gameQueue.Map;
                DateTime startDate  = DateTimeOffset.FromUnixTimeMilliseconds(viewManager.MatchlistEntry.Matches[i].Timestamp).UtcDateTime;
                int      daysAgo    = (DateTime.Now - startDate).Days;
                string   playedWhen = "";
                if (daysAgo < 1)
                {
                    playedWhen = (DateTime.Now - startDate).Hours.ToString() + " hour(s) ago";
                }
                else
                {
                    playedWhen = daysAgo.ToString() + " day(s) ago";
                }

                long   gameId          = viewManager.MatchlistEntry.Matches[i].GameId;
                long   gameDurationSec = viewManager.MatchEntries[i].GameDuration;
                int    minutes         = (int)(gameDurationSec / 60);
                int    sec             = (int)(gameDurationSec - 60 * minutes);
                string gameDuration    = minutes.ToString() + "min " + sec.ToString() + "sec";

                ParticipantDto player = viewManager.MatchEntries[i].Participants.Where(p => p.ChampionId == champId).FirstOrDefault();
                TeamStatsDto   team   = viewManager.MatchEntries[i].Teams.Where(p => p.TeamId == player.TeamId).FirstOrDefault();
                string         result = team.Win.ToUpper();
                string         stats  = player.Stats.Kills.ToString() + "/" + player.Stats.Deaths.ToString() + "/" + player.Stats.Assists.ToString();

                spMatchHistory.Children.Add(new MatchHistoryField(champName, posName, roleName, mapName,
                                                                  playedWhen, gameDuration, result, stats));
            }
        }
示例#8
0
 public async Task UpsertTeamStatsAsync(TeamStatsDto dto)
 {
     var actorId = new ActorId($"{dto.TeamId}/{dto.Year}/{dto.Week}".ToUpperInvariant());
     var actor   = ActorProxy.Create <IFootballStatsActor>(actorId, _settings.ActorServiceUri);
     await actor.Update(dto);
 }