public void WrongEndpoint() { var timeGetter = new MockTimeGetter(new DateTime(51634312)); var handler = new AdvertiseMatchResult(serversTable, matchesTable, statisticsTable, timeGetter); handler.Process(new MatchParameters { Endpoint = "notExistingEndpoint-1", Timestamp = timeGetter.Time }, new object()); }
public void HandlerCall() { var timeGetter = new MockTimeGetter(new DateTime(51634312)); var handler = new AdvertiseMatchResult(serversTable, matchesTable, statisticsTable, timeGetter); var data = new MockMatchData { ReturnValue = new MatchResults { FragLimit = 20, GameMode = "DM", Map = "dedust", Scoreboard = new List <PlayerScore> { new PlayerScore { Name = "Existing" }, new PlayerScore { Name = "Not+Existing" } }, TimeElapsed = 12.2f, TimeLimit = 10 } }; handler.Process(new MatchParameters { Endpoint = "hostname-6556", Timestamp = timeGetter.Time }, data); // Assert inserted match: Assert.AreEqual(1, matchesTable.InsertCalledTimes); Assert.AreEqual("hostname-6556", matchesTable.InsertElements[0].Server); Assert.AreEqual(timeGetter.Time, matchesTable.InsertElements[0].Timestamp); Assert.AreEqual(data.ReturnValue, matchesTable.InsertElements[0].Results); // Assert updated server: Assert.AreEqual(1, serversTable.UpdateCalledTimes); Assert.AreEqual("hostname-6556", serversTable.UpdateElements[0].Endpoint); Assert.AreEqual(1, serversTable.UpdateElements[0].TotalMatchesPlayed); Assert.AreEqual(2, serversTable.UpdateElements[0].AveragePopulation); // Assert updated/inserted statistics: Assert.AreEqual(1, statisticsTable.UpdateCalledTimes); Assert.AreEqual(1, statisticsTable.InsertCalledTimes); Assert.AreEqual("Not+Existing", statisticsTable.InsertElements[0].DisplayName); Assert.AreEqual("Existing", statisticsTable.UpdateElements[0].DisplayName); }
public void CachingTest() { var timeGetter = new MockTimeGetter(new DateTime(51634312)); var report = new ReportPopularServers(serversTable, timeGetter); var result = ((IEnumerable <PopularServersServer>)report.Process(new CountParameters { Count = 10 }, new object())) .ToArray(); serversTable.Elements.Add(new Server { Endpoint = "another-42", Info = new ServerInfo(), AverageMatchesPerDay = 0 }); var result2 = ((IEnumerable <PopularServersServer>)report.Process(new CountParameters { Count = 10 }, new object())) .ToArray(); serversTable.Elements.Add(new Server { Endpoint = "another-4242", Info = new ServerInfo(), AverageMatchesPerDay = 0 }); timeGetter.Time += new TimeSpan(0, 15, 0); var result3 = ((IEnumerable <PopularServersServer>)report.Process(new CountParameters { Count = 10 }, new object())) .ToArray(); // Should be both 3, as result is cached Assert.AreEqual(3, result.Length); Assert.AreEqual(3, result2.Length); // This should be 5, as we added 2 elements and 15 minutes "passed" Assert.AreEqual(5, result3.Length); }