예제 #1
0
            public void ReturnsLeaderboardIdParams()
            {
                // Arrange -> Act
                var leaderboardIdParams = new LeaderboardIdParams();

                // Assert
                Assert.IsAssignableFrom <LeaderboardIdParams>(leaderboardIdParams);
            }
예제 #2
0
            public void ReturnsDefaults()
            {
                // Arrange
                var leaderboardIdParams = new LeaderboardIdParams();

                // Act
                leaderboardIdParams.AddDefaults();

                // Assert
                Assert.Empty(leaderboardIdParams);
            }
예제 #3
0
            public void LeaderboardIdIsInvalid_ThrowsFormatException()
            {
                // Arrange
                var leaderboardIdParams = new LeaderboardIdParams();
                var leaderboardId       = "a";

                // Act -> Assert
                Assert.Throws <FormatException>(() =>
                {
                    leaderboardIdParams.Add(leaderboardId);
                });
            }
예제 #4
0
            public void LeaderboardIdIsValid_AddsLeaderboardIdAsInt32()
            {
                // Arrange
                var leaderboardIdParams = new LeaderboardIdParams();
                var leaderboardId       = "2047616";

                // Act
                leaderboardIdParams.Add(leaderboardId);

                // Assert
                Assert.Equal(2047616, leaderboardIdParams.Last());
            }
        public async Task <IHttpActionResult> GetPlayerDailyEntries(
            long steamId,
            LeaderboardIdParams lbids,
            Products products,
            bool?production = null,
            CancellationToken cancellationToken = default)
        {
            // Validate steamId
            var player = await(from p in db.Players.AsNoTracking()
                               where p.SteamId == steamId
                               select new PlayerDTO
            {
                Id          = p.SteamId.ToString(),
                UpdatedAt   = p.LastUpdate,
                DisplayName = p.Name,
                Avatar      = p.Avatar,
            })
                         .FirstOrDefaultAsync(cancellationToken);

            if (player == null)
            {
                return(NotFound());
            }

            // Validate lbids
            var validLbids = await(from l in db.DailyLeaderboards.AsNoTracking()
                                   where lbids.Contains(l.LeaderboardId)
                                   select l.LeaderboardId)
                             .ToListAsync(cancellationToken);
            var invalidLbids = lbids.Except(validLbids).ToList();

            if (invalidLbids.Any())
            {
                return(NotFound());
            }

            var query = from e in db.DailyEntries.AsNoTracking()
                        where e.SteamId == steamId
                        where products.Contains(e.Leaderboard.Product.Name)
                        select e;

            if (lbids.Any())
            {
                query = query.Where(e => lbids.Contains(e.LeaderboardId));
            }
            if (production != null)
            {
                query = query.Where(e => e.Leaderboard.IsProduction == production);
            }
            query                 = from e in query
                            let l = e.Leaderboard
                                    orderby l.Date descending, l.ProductId descending, l.IsProduction
            select e;

            var total = await query.CountAsync(cancellationToken);

            var entries = await(from e in query
                                let l                 = e.Leaderboard
                                                let r = e.Replay
                                                        select new DailyEntryDTO
            {
                Leaderboard = new DailyLeaderboardDTO
                {
                    Id           = l.LeaderboardId,
                    UpdatedAt    = l.LastUpdate,
                    Name         = l.Name,
                    DisplayName  = l.DisplayName,
                    IsProduction = l.IsProduction,
                    ProductName  = l.Product.Name,
                    Product      = new ProductDTO
                    {
                        Id          = l.Product.ProductId,
                        Name        = l.Product.Name,
                        DisplayName = l.Product.DisplayName,
                    },
                    Date  = l.Date,
                    Total = l.Entries.Count(),
                },
                Rank  = e.Rank,
                Score = e.Score,
                End   = new EndDTO
                {
                    Zone  = e.Zone,
                    Level = e.Level,
                },
                KilledBy = r.KilledBy,
                Version  = r.Version,
            })
                          .ToListAsync(cancellationToken);

            var content = new PlayerDailyEntriesDTO
            {
                Player  = player,
                Total   = total,
                Entries = entries,
            };

            return(Ok(content));
        }