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));
        }
Exemplo n.º 2
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" });
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     Server1.Stop();
     Server1.Dispose();
     Server2.Stop();
     Server2.Dispose();
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public FederatedEndpointFixture()
        {
            Server1 = FluentMockServer.Start();
            Server2 = FluentMockServer.Start();

            Server1.Given(Request.Create()
                    .WithPath("/query")
                    .UsingGet()
                    .WithParam("query", MatchBehaviour.AcceptOnMatch))
                .RespondWith(Response.Create()
                    .WithBody(Server1ResultsXml, encoding: Encoding.UTF8)
                    .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0])
                    .WithStatusCode(HttpStatusCode.OK));
            Server1.Given(Request.Create().WithPath("/query2").UsingGet().WithParam("query"))
                .RespondWith(Response.Create().WithBody(Server1ConstructResults, encoding: Encoding.UTF8)
                    .WithHeader("Content-Type", "application/n-triples").WithStatusCode(HttpStatusCode.OK));

            Server2
                .Given(Request.Create().WithPath("/query").UsingGet().WithParam("query"))
                .RespondWith(Response.Create().WithBody(Server2ResultsXml, encoding: Encoding.UTF8)
                    .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0]).WithStatusCode(HttpStatusCode.OK));
            Server2.Given(Request.Create().WithPath("/query2").UsingGet().WithParam("query"))
                .RespondWith(Response.Create().WithBody(Server2ConstructResults, encoding: Encoding.UTF8)
                    .WithHeader("Content-Type", "application/n-triples").WithStatusCode(HttpStatusCode.OK));
            Server2.Given(Request.Create().WithPath("/fail"))
                .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Forbidden));
            Server2.Given(Request.Create().WithPath("/timeout"))
                .RespondWith(Response.Create().WithDelay(4000).WithBody(Server2ResultsXml, encoding: Encoding.UTF8)
                    .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0]).WithStatusCode(HttpStatusCode.OK));

        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
    private static void Test()
    {
        Console.WriteLine("Instantiating Server1...");
        Server1 s = new Server1();

        Console.WriteLine("Calling Server1.trivial...");
        s.trivial();
    }
Exemplo n.º 9
0
        public async Task PopularServers_AfterUpdate()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

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

            await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1);
        }
Exemplo n.º 10
0
 public override void WriteToConsole(DateTime?clockTime = null)
 {
     Queueing1.WriteToConsole(clockTime);
     Server1.WriteToConsole(clockTime);
     //Console.WriteLine("Total NComplete: {0}", TotalNCompleted);
     Queueing2.WriteToConsole(clockTime);
     Server2.WriteToConsole(clockTime);
 }
        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));
        }
Exemplo n.º 13
0
        // IDisposable Members

        public void Dispose()
        {
            Server1.Dispose();
            Server2.Dispose();
            foreach (var dispo in _disposables)
            {
                dispo.Dispose();
            }
        }
Exemplo n.º 14
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[] { }));
        }
        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));
        }
        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);
        }
Exemplo n.º 17
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);
        }
        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);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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
                }
            }));
        }
Exemplo n.º 25
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,
                }
            }));
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        protected override async Task PutInitialiData()
        {
            await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1);

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