public async Task Cache_ByPlayerId() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var storedEvent = TestDtoHelper.CreateFakeStartedEvent(); await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(storedEvent)); await Task.Delay(100); var result = await matchRepository.TryLoadOnGoingMatchForPlayer(storedEvent.match.players[0].battleTag); Assert.IsNotNull(result); Assert.AreEqual(storedEvent.match.id, result.MatchId); var notCachedEvent = TestDtoHelper.CreateFakeStartedEvent(); await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(notCachedEvent)); await Task.Delay(100); var result2 = await matchRepository.TryLoadOnGoingMatchForPlayer(storedEvent.match.players[0].battleTag); Assert.IsNotNull(result2); Assert.AreEqual(storedEvent.match.id, result.MatchId); Assert.AreEqual(notCachedEvent.match.id, result2.MatchId); }
public async Task Cache_AllOngoingMatches() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var storedEvent = TestDtoHelper.CreateFakeStartedEvent(); await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(storedEvent)); await Task.Delay(100); var result = await matchRepository.LoadOnGoingMatches( storedEvent.match.gameMode, storedEvent.match.gateway); Assert.AreEqual(1, result.Count); Assert.AreEqual(storedEvent.match.id, result[0].MatchId); var notCachedEvent = TestDtoHelper.CreateFakeStartedEvent(); await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(notCachedEvent)); await Task.Delay(100); var result2 = await matchRepository.LoadOnGoingMatches( notCachedEvent.match.gameMode, notCachedEvent.match.gateway); Assert.AreEqual(2, result2.Count); Assert.AreEqual(storedEvent.match.id, result[0].MatchId); }
public async Task LoadStartedIgnoresEventThatAreYoungerThan20Seconds() { var startEvent1 = TestDtoHelper.CreateFakeStartedEvent(); var startEvent2 = TestDtoHelper.CreateFakeStartedEvent(); startEvent1.Id = ObjectId.GenerateNewId(DateTime.Now.AddDays(-1)); startEvent1.match.id = "test"; startEvent2.Id = ObjectId.GenerateNewId(DateTime.Now); await InsertMatchStartedEvent(startEvent1); await InsertMatchStartedEvent(startEvent2); var matchEventRepository = new MatchEventRepository(MongoClient); var events = await matchEventRepository.LoadStartedMatches(); Assert.AreEqual(1, events.Count); Assert.AreEqual(startEvent1.match.id, events[0].match.id); }