public async Task GetAllShouldGetAllServersFromGivenGuild() { Server[] servers = new Server[] { new Server(0, 11u, "127.0.0.1", 123, "test"), new Server(0, 11u, "24.1.2.1", 123, "test2"), new Server(0, 11u, "17.1.0.1", 22, "test3"), new Server(0, 11u, "12.0.2.1", 33, "wara4"), new Server(0, 11u, "12.0.2.1", 11, "wara"), }; IServerRepository repo = new ServerRepository(GetMysql()); foreach (var s in servers) { await repo.AddServer(s.GuildId, s.ServerIp, s.ServerPort, s.ServerName); } await repo.AddServer(12u, "10.0.0.1", 123, "different guild"); await repo.AddServer(13u, "10.0.0.1", 123, "different guild"); var response = await repo.GetAll(11u); foreach (var s in servers) { Assert.NotNull(response.Single(x => x.ServerIp == s.ServerIp && x.ServerName == s.ServerName && x.ServerPort == s.ServerPort)); } }
public void LoadServers() { IEnumerable <Server> servers = ServerRepository.GetAll(); _serverComboBox.Items.Clear(); foreach (Server server in servers) { _serverComboBox.Items.Add(server); } }
public IEnumerable <ServerInfo> GetPopular(int count) { var matches = _matchRepository.GetAll().ToList(); if (matches == null || !matches.Any()) { return(new ServerInfo[0]); } var serversDict = _serverRepository.GetAll() .ToDictionary(server => server.ServerId, server => new ServerInfo() { AverageMatchesPerDay = 0, Name = server.Name, EndPoint = server.EndPoint }); var serverMinDateDict = new Dictionary <int, DateTime>(serversDict.Count); var serversTotalMatchesDict = new Dictionary <int, int>(serversDict.Count); var maxDate = _utilRepository.GetMaxDate(); foreach (var match in matches) { var serverId = match.ServerId; if (serverMinDateDict.ContainsKey(match.ServerId)) { serverMinDateDict[serverId] = match.Date.Date.Max(serverMinDateDict[serverId]); } else { serverMinDateDict[serverId] = match.Date.Date; } maxDate = maxDate.Max(match.Date.Date); serversTotalMatchesDict.Increment(serverId); } foreach (var serverMinDate in serverMinDateDict) { var serverId = serverMinDate.Key; serversDict[serverId].AverageMatchesPerDay = (double)serversTotalMatchesDict[serverId] / (maxDate.Subtract(serverMinDate.Value).Days + 1); } return(serversDict.Values.Take(count)); }