Пример #1
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);
        }
        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));
        }
Пример #3
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);
        }
Пример #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);
        }
Пример #5
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" });
        }
        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));
        }
        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));
        }
Пример #8
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 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));
        }
Пример #10
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[] { }));
        }
Пример #11
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);
        }
Пример #12
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);
        }
        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);
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
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
                }
            }));
        }
Пример #20
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,
                }
            }));
        }
Пример #21
0
        public async Task FavoriteServerTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

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

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

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

            PlayerStatisticStorage.GetStatistics(Player1.Name).FavoriteServer.Should().Be(Server2.Id);
            PlayerStatisticStorage.GetStatistics(Player2.Name).FavoriteServer.Should().Be(Server1.Id);
        }
Пример #22
0
        public async Task AverageMatchesPerDayTest()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

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

            var matches = new[]
            {
                GenerateMatch(Server2, new DateTime(2017, 1, 1, 12, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player1, Player2 }),
                GenerateMatch(Server1, new DateTime(2017, 1, 8, 13, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player1 }),
                GenerateMatch(Server2, new DateTime(2017, 1, 2, 14, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player2, Player1 }),
                GenerateMatch(Server2, new DateTime(2017, 1, 1, 15, 00, 00, DateTimeKind.Utc), scoreboard: new[] { Player1, Player2 }),
            };

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

            PlayerStatisticStorage.GetStatistics(Player1.Name).AverageMatchesPerDay.Should().Be(0.5);
            PlayerStatisticStorage.GetStatistics(Player2.Name).AverageMatchesPerDay.Should().Be(1.5);
        }
Пример #23
0
        public async Task PopularServers_CalculateAverageMatchesPerDay()
        {
            foreach (var server in GenerateServers(100, i => GenerateServer(i.ToString())))
            {
                await StatisticStorage.UpdateServer(server.GetIndex(), server);
            }
            var match1 = GenerateMatch(GenerateServer("1"), DateTime.Today);
            var match2 = GenerateMatch(GenerateServer("1"), DateTime.Today.Subtract(TimeSpan.FromDays(1)));
            var match3 = GenerateMatch(GenerateServer("2"), DateTime.Today.Add(TimeSpan.FromDays(2)));
            await StatisticStorage.UpdateMatch(match1.GetIndex(), match1.InitPlayers(match1.EndTime));

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

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

            await WaitForTasks();

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

            var expected = new[]
            {
                new
                {
                    endpoint             = match1.HostServer.Id,
                    name                 = match1.HostServer.Name,
                    averageMatchesPerDay = 0.5
                },
                new
                {
                    endpoint             = match3.HostServer.Id,
                    name                 = match3.HostServer.Name,
                    averageMatchesPerDay = 0.25
                },
            };

            response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, expected));
        }
Пример #24
0
        protected override async Task PutInitialiData()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

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