public QRServer(string serverName, DatabaseDriver databaseDriver, IPAddress address, int port) : base(serverName, address, port) { DB = databaseDriver; //The Time for servers to remain in the serverlist since the last ping in seconds. //This value must be greater than 20 seconds, as that is the ping rate of the server //Suggested value is 30 seconds, this gives the server some time if the master server //is busy and cant refresh the server's TTL right away // Setup timer. Remove servers who havent ping'd since ServerTTL PollTimer = new Timer(5000); PollTimer.Elapsed += (s, e) => ServerListHandler.CheckServers(); PollTimer.Start(); }
public async Task GetServersFromTesonetListTest() { ServerDto[] testList = { new ServerDto { Name = "TestName", Distance = 123 } }; var userToken = "token"; var securityServiceMock = new Mock <ISecurityService>(); securityServiceMock .Setup(x => x.GetTokenAsync()) .ReturnsAsync(userToken); var tesonetClientMock = new Mock <ITesonetClient>(); tesonetClientMock .Setup(x => x.GetServersAsync(userToken)) .ReturnsAsync(testList); var serversRepositoryMock = new Mock <IServersRepository>(); serversRepositoryMock .Setup(x => x.SaveServersAsync(testList)) .ReturnsAsync(testList); var displayServiceMock = new Mock <IDisplayService>(); var handler = new ServerListHandler( securityServiceMock.Object, tesonetClientMock.Object, serversRepositoryMock.Object, displayServiceMock.Object ); await handler.HandleBaseAsync(new ServerListRequest()).ConfigureAwait(false); securityServiceMock.Verify(x => x.GetTokenAsync(), Times.Once); tesonetClientMock.Verify(x => x.GetServersAsync(userToken), Times.Once); serversRepositoryMock.Verify(x => x.SaveServersAsync(testList), Times.Once); serversRepositoryMock.Verify(x => x.GetServersAsync(), Times.Never); displayServiceMock.Verify(x => x.DisplayTable(testList), Times.Once); }