예제 #1
0
        public async Task AverageScoreboardPercentTest()
        {
            PlayerInfo
                player1 = GeneratePlayer("A"),
                player2 = GeneratePlayer("B"),
                player3 = GeneratePlayer("C"),
                player4 = GeneratePlayer("D");
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            var matches = new[]
            {
                GenerateMatch(Server2, Day1, scoreboard: new[] { player1, player2, player4 }),
                GenerateMatch(Server1, Day2, scoreboard: new[] { player3, player2, player1, player4 }),
                GenerateMatch(Server2, Day3, scoreboard: new[] { player2, player4, player1 }),
                GenerateMatch(Server2, Day4, scoreboard: new[] { player3, player2 }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(player1.Name).AverageScoreboardPercent
            .Should().Be((100.0 + 100.0 / 3 + 0) / 3);
            PlayerStatisticStorage.GetStatistics(player2.Name).AverageScoreboardPercent
            .Should().Be((100.0 / 2 + 100.0 * 2 / 3 + 100.0 + 0) / 4);
            PlayerStatisticStorage.GetStatistics(player3.Name).AverageScoreboardPercent
            .Should().Be((100.0 + 100.0) / 2);
            PlayerStatisticStorage.GetStatistics(player4.Name).AverageScoreboardPercent
            .Should().Be((0.0 + 0.0 + 100.0 / 2) / 3);
        }
예제 #2
0
        public async Task KillToDeathRatioTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            var matches = new[]
            {
                GenerateMatch(Server1, Day1, scoreboard: new[]
                {
                    GeneratePlayer("A", kills: 2, deaths: 1), GeneratePlayer("B", kills: 3, deaths: 0)
                }),
                GenerateMatch(Server1, Day2, scoreboard: new[]
                {
                    GeneratePlayer("A", kills: 4, deaths: 3)
                }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics("A").KillToDeathRatio.Should().Be(1.5);
            PlayerStatisticStorage.GetStatistics("B").KillToDeathRatio.Should().Be(null);
        }
예제 #3
0
        public async Task Top5MapsTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            MatchInfo[] matches =
            {
                GenerateMatch(Server1, new DateTime(2017, 1,  1), "A"),
                GenerateMatch(Server1, new DateTime(2017, 1,  2), "B"),
                GenerateMatch(Server1, new DateTime(2017, 1,  3), "C"),
                GenerateMatch(Server1, new DateTime(2017, 1,  4), "C"),
                GenerateMatch(Server1, new DateTime(2017, 1,  5), "B"),
                GenerateMatch(Server1, new DateTime(2017, 1,  6), "A"),
                GenerateMatch(Server1, new DateTime(2017, 1,  7), "D"),
                GenerateMatch(Server1, new DateTime(2017, 1,  8), "D"),
                GenerateMatch(Server1, new DateTime(2017, 1,  9), "E"),
                GenerateMatch(Server1, new DateTime(2017, 1, 10), "F"),
                GenerateMatch(Server1, new DateTime(2017, 1, 11), "F"),
            };
            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).Top5Maps.ShouldBeEquivalentTo(new[] { "A", "B", "C", "D", "F" });
        }
예제 #4
0
        public async Task UniqueServersTest()
        {
            var server3 = GenerateServer("host-3");
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            await StatisticStorage.UpdateServer(server3.GetIndex(), server3);

            var matches = new[]
            {
                GenerateMatch(Server2, Day1, scoreboard: new[] { Player1, Player2 }),
                GenerateMatch(Server1, Day2, scoreboard: new[] { Player1 }),
                GenerateMatch(Server2, Day3, scoreboard: new[] { Player2, Player1 }),
                GenerateMatch(server3, Day4, scoreboard: new[] { Player2 }),
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(Player1.Name).UniqueServers.Should().Be(2);
            PlayerStatisticStorage.GetStatistics(Player2.Name).UniqueServers.Should().Be(2);
        }
        public async Task ModuleUpdateMatchStatistic()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await Module.ProcessRequest(CreateRequest(
                                            JsonConvert.SerializeObject(Match1),
                                            $"/servers/{Match1.HostServer.Id}/matches/{Match1.EndTime.ToUtcFormat()}",
                                            HttpMethodEnum.Put));

            var response = await Module.ProcessRequest(CreateRequest(
                                                           JsonConvert.SerializeObject(Match2),
                                                           $"/servers/{Match1.HostServer.Id}/matches/{Match1.EndTime.ToUtcFormat()}",
                                                           HttpMethodEnum.Put));

            var combined = Match2;

            combined.HostServer = Match1.HostServer;
            combined.EndTime    = Match1.EndTime;

            response.Response.Should().Be(new HttpResponse(HttpStatusCode.OK));

            var result = await StatisticStorage.GetMatch(Match1.GetIndex());

            result.ShouldBeEquivalentTo(combined,
                                        options => options
                                        .Excluding(info => info.Id)
                                        .Excluding(info => info.Scoreboard));
        }
        public async Task ModuleReturnsServerInfo()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            var response = await Module.ProcessRequest(CreateRequest("", $"/servers/{Server1.Id}/info"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, Server1));
        }
예제 #7
0
        public async Task PopularServers_AfterUpdate()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1);

            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1);
        }
        public async Task ModuleReturnsNotFound_WhenNoMatchesFound()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            var response = await Module.ProcessRequest(CreateRequest("", $"/servers/{Server1.Id}/matches/{DateTime1.ToUtcFormat()}"));

            response.Response.Should().Be(new HttpResponse(HttpStatusCode.NotFound));
        }
예제 #9
0
        public async Task RecentMatches_MinimumCountValue_Is0()
        {
            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1.InitPlayers(Match1.EndTime));

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/recent-matches/-1"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new object[] {}));
        }
        public async Task ModuleReturnsMatchInfo()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1.InitPlayers(Match1.EndTime));

            var response = await Module.ProcessRequest(CreateRequest("", $"/servers/{Match1.HostServer.Id}/matches/{Match1.EndTime.ToUtcFormat()}"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, Match1));
        }
예제 #11
0
        public async Task PopularServers_MinimalCountValue_Is0()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/-1"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new object[] { }));
        }
예제 #12
0
        public async Task BestPlayers_MinimumCountValue_Is0()
        {
            foreach (var match in GenerateMatches(100, i => GenerateMatch(Server1, new DateTime(i), "map",
                                                                          new[] { GeneratePlayer((i / 10).ToString()) })))
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match.InitPlayers(match.EndTime));
            }
            var response = await Module.ProcessRequest(CreateRequest("", "/reports/best-players/-1"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new object[] {}));
        }
        public async Task ModuleSetNewServerInfo()
        {
            var response = await Module.ProcessRequest(
                CreateRequest(JsonConvert.SerializeObject(Server1), $"/servers/{Server1.Id}/info", HttpMethodEnum.Put));

            response.Response.Should().Be(new HttpResponse(HttpStatusCode.OK));

            var result = await StatisticStorage.GetServer(Server1.GetIndex());

            result.Should().Be(Server1);
        }
예제 #14
0
        public async Task BestPlayers_IgnorePlayers_WhoNeverDie()
        {
            foreach (var match in GenerateMatches(10, i => GenerateMatch(Server1, new DateTime(i), "map", new[] { Player2 })))
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match.InitPlayers(match.EndTime));
            }
            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/best-players"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new object[] {}));
        }
예제 #15
0
        public async Task BestPlayers_MaximumCountValue_Is50()
        {
            foreach (var match in GenerateMatches(1000, i => GenerateMatch(Server1, new DateTime(i), "map",
                                                                           new[] { GeneratePlayer((i / 10).ToString()) })))
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match.InitPlayers(match.EndTime));
            }
            var response = await Module.ProcessRequest(CreateRequest("", "/reports/best-players/100"));

            var players = JsonConvert.DeserializeObject <List <object> >(response.Response.Content);

            players.Should().HaveCount(50);
        }
예제 #16
0
        public async Task TotalMatchesPlayedTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            MatchInfo match1 = GenerateMatch(Server1, Day1), match2 = GenerateMatch(Server1, Day3);
            await StatisticStorage.UpdateMatch(match1.GetIndex(), match1);

            await StatisticStorage.UpdateMatch(match2.GetIndex(), match2);

            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).TotalMatchesPlayed.Should().Be(2);
        }
예제 #17
0
        public async Task RecentMatches_DefaultCountValue_Is5()
        {
            foreach (var match in GenerateMatches(10, i => GenerateMatch(Server1, new DateTime(i))))
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match.InitPlayers(match.EndTime));
            }
            await Task.Delay(100);

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/recent-matches"));

            var matches = JsonConvert.DeserializeObject <List <object> >(response.Response.Content);

            matches.Should().HaveCount(5);
        }
예제 #18
0
        public async Task PopularServers_AcceptNonCanonicalRoute()
        {
            foreach (var server in GenerateServers(10, i => GenerateServer(i.ToString())))
            {
                await StatisticStorage.UpdateServer(server.GetIndex(), server);
            }
            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/"));

            var servers = JsonConvert.DeserializeObject <List <object> >(response.Response.Content);

            servers.Should().HaveCount(5);
        }
예제 #19
0
        public async Task RecentMatches_AcceptNonCanonicalRoute()
        {
            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1.InitPlayers(Match1.EndTime));

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/recent-matches/"));

            var expected = new[]
            {
                new { server = Match1.HostServer.Id, timestamp = Match1.EndTime, results = Match1 }
            };

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, expected));
        }
예제 #20
0
        public async Task RecentMatches_ReturnAllMatches_IfLessThanCount()
        {
            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1.InitPlayers(Match1.EndTime));

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/recent-matches/5"));

            var expected = new[]
            {
                new { server = Match1.HostServer.Id, timestamp = Match1.EndTime, results = Match1 },
            }.OrderByDescending(m => m.timestamp).ToArray();

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, expected));
        }
        public async Task ModuleAddNewMatchStatistic()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            var response = await Module.ProcessRequest(CreateRequest(
                                                           JsonConvert.SerializeObject(Match1),
                                                           $"/servers/{Match1.HostServer.Id}/matches/{Match1.EndTime.ToUtcFormat()}",
                                                           HttpMethodEnum.Put));

            response.Response.Should().Be(new HttpResponse(HttpStatusCode.OK));

            var result = await StatisticStorage.GetMatch(Match1.GetIndex());

            result.Should().Be(Match1);
        }
예제 #22
0
        public async Task PopularServers_ReturnAllServers_IfLessThanCount()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/5"));

            var typeDefinition = new { endpoint = "", name = "", averageMatchesPerDay = 0.0 };
            var expected = new[] { Server1, Server2 }.Select(s => new { endpoint = s.Id, name = s.Name, averageMatchesPerDay = 0.0 });
            var servers = JsonConvert.DeserializeObject <List <JObject> >(response.Response.Content)
                          .Select(value => value.ToObject(typeDefinition.GetType()));

            servers.ShouldBeEquivalentTo(expected);
        }
예제 #23
0
        public async Task TotalMatchesPlayedTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            var matches = new[]
            {
                GenerateMatch(Server1, DateTime1, scoreboard: new[] { Player1, Player2 }),
                GenerateMatch(Server1, DateTime2, scoreboard: new[] { Player2 })
            };

            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            PlayerStatisticStorage.GetStatistics(Player1.Name).TotalMatchesPlayed.Should().Be(1);
            PlayerStatisticStorage.GetStatistics(Player2.Name).TotalMatchesPlayed.Should().Be(2);
        }
예제 #24
0
        public async Task MaximumMatchesPerDayTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            MatchInfo[] matches =
            {
                GenerateMatch(Server1, new DateTime(2017, 2, 1, 12, 00, 00)),
                GenerateMatch(Server1, new DateTime(2017, 2, 1, 13, 00, 00)),
                GenerateMatch(Server1, new DateTime(2017, 2, 1, 00, 00, 00)),
                GenerateMatch(Server1, new DateTime(2017, 2, 2, 00, 00, 00)),
                GenerateMatch(Server1, new DateTime(2017, 2, 2, 00, 00, 00)),
            };
            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).MaximumMatchesPerDay.Should().Be(3);
        }
예제 #25
0
        public async Task RecentMatches_ReturnRecentMatches()
        {
            int totalCount = 100, queryCount = 7;
            var random    = new Random(0);
            var generated = GenerateMatches(totalCount, i => GenerateMatch(
                                                Server1, new DateTime(random.Next(100000)), $"map{i + 1}"));

            foreach (var match in generated)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match.InitPlayers(match.EndTime));
            }
            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", $"/reports/recent-matches/{queryCount}"));

            var expected = generated
                           .Select(m => new { server = m.HostServer.Id, timestamp = m.EndTime, results = m })
                           .OrderByDescending(m => m.timestamp).Take(queryCount).ToArray();

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, expected));
        }
예제 #26
0
        public async Task AverageMatchesPerDayTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            MatchInfo[] matches =
            {
                GenerateMatch(Server1, Day2),
                GenerateMatch(Server1, Day3),
                GenerateMatch(Server2, Day1),
                GenerateMatch(Server2, Day4),
            };
            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).AverageMatchesPerDay.Should().Be(0.5);
        }
예제 #27
0
        public async Task BestPlayers_ReturnSinglePlayer()
        {
            foreach (var match in GenerateMatches(10, i => GenerateMatch(Server1, new DateTime(i), "map", new[] { Player1 })))
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match.InitPlayers(match.EndTime));
            }
            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/best-players"));

            var expected = new[]
            {
                new
                {
                    name             = Player1.Name,
                    killToDeathRatio = 1.0 * Player1.Kills / Player1.Deaths
                }
            };

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, expected));
        }
예제 #28
0
        public async Task MaximumPopulationTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            MatchInfo[] matches =
            {
                GenerateMatch(Server1, Day2,  "map", new [] { Player1, Player2             }),
                GenerateMatch(Server1, Day3,  "map", new [] { Player1, Player2, GeneratePlayer("A")}),
                GenerateMatch(Server2, Day1,  "map", new [] { Player1, Player2, GeneratePlayer("A"), GeneratePlayer("B")}),
                GenerateMatch(Server2, Day4),
            };
            foreach (var match in matches)
            {
                await StatisticStorage.UpdateMatch(match.GetIndex(), match);
            }
            await WaitForTasks();

            ServerStatisticStorage.GetStatistics(Server1.Id).MaximumPopulation.Should().Be(3);
            ServerStatisticStorage.GetStatistics(Server2.Id).MaximumPopulation.Should().Be(4);
        }
        public async Task ModuleReturnsAllServerInfos()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            var response = await Module.ProcessRequest(CreateRequest("", "/servers/info"));

            response.Response.ShouldBeEquivalentTo(new JsonHttpResponse(HttpStatusCode.OK, new[]
            {
                new
                {
                    endpoint = Server1.Id,
                    info     = Server1
                },
                new
                {
                    endpoint = Server2.Id,
                    info     = Server2
                }
            }));
        }
예제 #30
0
        public async Task PopularServers_ReturnMostPopularServer()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

            await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2);

            await StatisticStorage.UpdateMatch(Match2.GetIndex(), Match2.InitPlayers(Match2.EndTime));

            await WaitForTasks();

            var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/1"));

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new[]
            {
                new
                {
                    endpoint             = Server2.Id,
                    name                 = Server2.Name,
                    averageMatchesPerDay = 1.0,
                }
            }));
        }