public async Task SearchForPlayerAndOpponent_FilterBySeason(int season, string playerTwo) { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = 0; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "wolf#456"; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "peter#123"; matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123", null, season : season); var count = await matchRepository.CountFor("peter#123", null, season : season); Assert.AreEqual(1, count); Assert.AreEqual("peter#123", matches.Single().Teams.First().Players.Single().BattleTag); Assert.AreEqual(playerTwo, matches.Single().Teams.Last().Players.Single().BattleTag); }
public async Task HandleAsync(SeasonStarted domainEvent) { var matchCreatedEvents = new List <IDomainEvent>(); foreach (var gameDay in domainEvent.GameDays) { foreach (var matchup in gameDay.Matchups) { var guestTeam = await _readModelRepository.LoadAsync <TeamReadModel>(matchup.TeamAsGuest); var homeTeam = await _readModelRepository.LoadAsync <TeamReadModel>(matchup.TeamAtHome); var domainEvents = Matchup.Create( matchup.MatchId, homeTeam.Value, guestTeam.Value) .DomainEvents; matchCreatedEvents.Add(domainEvents.Single()); } } foreach (var createdEvent in matchCreatedEvents) { var result = await _eventStore.AppendAsync(createdEvent, 0); result.Check(); } }
public async Task SearchForPlayerAndOpponent_2v2_SameTeam() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var matchFinishedEvent1 = TestDtoHelper.CreateFake2v2AtEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "wolf#456"; matchFinishedEvent1.match.players[2].battleTag = "LostTeam1#456"; matchFinishedEvent1.match.players[3].battleTag = "LostTeam2#456"; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "peter#123"; matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123@10", "wolf#456"); var count = await matchRepository.CountFor("peter#123@10", "wolf#456"); Assert.AreEqual(0, count); }
public async Task SearchForPlayerAndOppoRace() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent3 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.players[0].race = Race.UD; matchFinishedEvent1.match.players[1].race = Race.HU; matchFinishedEvent2.match.players[0].race = Race.UD; matchFinishedEvent2.match.players[1].race = Race.NE; matchFinishedEvent3.match.players[0].race = Race.OC; matchFinishedEvent3.match.players[1].race = Race.HU; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123", null, GateWay.Europe, GameMode.GM_1v1, Race.UD, Race.HU, 100, 0, 0); var count = await matchRepository.CountFor("peter#123", null, GateWay.Europe, GameMode.GM_1v1, Race.UD, Race.HU, 0); Assert.AreEqual(1, count); Assert.AreEqual(Matchup.Create(matchFinishedEvent1).ToString(), matches.Single().ToString()); }
public async Task SearchForPlayerAndOpponent_2v2And1V1() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFake2v2AtEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[0].team = 0; matchFinishedEvent1.match.players[1].battleTag = "LostTeam1#456"; matchFinishedEvent1.match.players[1].team = 0; matchFinishedEvent1.match.players[2].battleTag = "wolf#456"; matchFinishedEvent1.match.players[2].team = 1; matchFinishedEvent1.match.players[3].battleTag = "LostTeam2#456"; matchFinishedEvent1.match.players[3].team = 1; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "peter#123"; matchFinishedEvent2.match.players[1].battleTag = "wolf#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123", "wolf#456"); var count = await matchRepository.CountFor("peter#123", "wolf#456"); Assert.AreEqual(2, count); Assert.AreEqual("peter#123", matches[0].Teams[0].Players[0].BattleTag); Assert.AreEqual("peter#123", matches[1].Teams[0].Players[0].BattleTag); }
public async Task LoadDetails_RandomRaceNotSetForNonRandomSelection() { var matchFinishedEvent = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent.match.id = "nmhcCLaRc7"; matchFinishedEvent.Id = ObjectId.GenerateNewId(); // Set race to non-random. matchFinishedEvent.match.players[0].race = Race.HU; matchFinishedEvent.match.players[0].rndRace = null; matchFinishedEvent.result.players[0].raceId = (int)RaceId.HU; matchFinishedEvent.match.players.Find(p => p.battleTag == matchFinishedEvent.result.players[0].battleTag).race = Race.HU; await InsertMatchEvent(matchFinishedEvent); var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent)); var result = await matchRepository.LoadDetails(matchFinishedEvent.Id); Assert.AreEqual("nmhcCLaRc7", result.Match.MatchId); Assert.AreEqual(Race.HU, result.Match.Teams[0].Players[0].Race); Assert.AreEqual(null, result.Match.Teams[0].Players[0].RndRace); }
public async Task LoadDetails_RandomRaceSetToRandomWhenNullResult() { var matchFinishedEvent = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent.match.id = "nmhcCLaRc7"; matchFinishedEvent.Id = ObjectId.GenerateNewId(); matchFinishedEvent.result = null; var player = matchFinishedEvent.match.players[0]; // Set race to random. matchFinishedEvent.match.players[0].race = Race.RnD; await InsertMatchEvent(matchFinishedEvent); var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent)); var result = await matchRepository.LoadDetails(matchFinishedEvent.Id); Assert.AreEqual("nmhcCLaRc7", result.Match.MatchId); Assert.AreEqual(Race.RnD, result.Match.Teams[0].Players.Find(p => p.BattleTag == player.battleTag).Race); Assert.AreEqual(Race.RnD, result.Match.Teams[0].Players.Find(p => p.BattleTag == player.battleTag).RndRace); }
public async Task SearchForPlayerAndOpponent_FilterByGateway() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.gateway = GateWay.America; matchFinishedEvent2.match.gateway = GateWay.Europe; matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "wolf#456"; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "peter#123"; matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123", null, GateWay.America); var count = await matchRepository.CountFor("peter#123", null, GateWay.America); Assert.AreEqual(1, count); Assert.AreEqual("peter#123", matches.Single().Teams.First().Players.Single().BattleTag); }
public async Task CountFor() { for (int i = 0; i < 100; i++) { Console.WriteLine($"https://www.test.w3champions.com:{i}/login"); } var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent3 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "wolf#456"; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "wolf#456"; matchFinishedEvent2.match.players[1].battleTag = "peter#123"; matchFinishedEvent3.match.season = 1; matchFinishedEvent3.match.players[0].battleTag = "notFound"; matchFinishedEvent3.match.players[1].battleTag = "notFound2"; var matchup = Matchup.Create(matchFinishedEvent1); await matchRepository.Insert(matchup); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var count = await matchRepository.CountFor(matchup.Teams[0].Players[0].BattleTag); Assert.AreEqual(2, count); }
public void MapMatch_Map_Shorter() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); fakeEvent.match.map = "Maps/frozenthrone/(2)terenasstand_lv.w3x"; var matchup = Matchup.Create(fakeEvent); Assert.AreEqual("terenasstand", matchup.Map); }
public void MapMatch_Map() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); fakeEvent.match.map = "Maps/frozenthrone/community/(2)amazonia.w3x"; var matchup = Matchup.Create(fakeEvent); Assert.AreEqual("amazonia", matchup.Map); }
public void MapMatch_GameMode() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); fakeEvent.match.gameMode = GameMode.GM_1v1; var matchup = Matchup.Create(fakeEvent); Assert.AreEqual(GameMode.GM_1v1, matchup.GameMode); }
public void MapMatch_StartTime() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); var matchup = Matchup.Create(fakeEvent); fakeEvent.match.startTime = 1585692028740; fakeEvent.match.endTime = 1585692047363; Assert.IsNotNull(matchup.StartTime); Assert.IsNotNull(matchup.EndTime); }
public async Task <string> CreateMatch(CreateMatchCommand command) { var homeTeam = (await _readModelRepository.LoadAsync <TeamReadModel>(command.HomeTeam)).Value; var guestTeam = (await _readModelRepository.LoadAsync <TeamReadModel>(command.GuestTeam)).Value; var domainResult = Matchup.Create(homeTeam, guestTeam); var storeResult = await _eventStore.AppendAsync(domainResult.DomainEvents, 0); storeResult.Check(); return(domainResult.DomainEvents.Single().EntityId); }
public void MapMatch_TimeSpan() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); fakeEvent.match.startTime = 1585692028740; fakeEvent.match.endTime = 1585692047363; var matchup = Matchup.Create(fakeEvent); Assert.AreEqual(0, matchup.Duration.Minutes); Assert.AreEqual(18, matchup.Duration.Seconds); Assert.AreEqual(623, matchup.Duration.Milliseconds); }
public async Task SearchForGameMode2v2_LoadDefault() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.gameMode = GameMode.GM_2v2_AT; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); var matches = await matchRepository.Load(); Assert.AreEqual(1, matches.Count); }
public async Task SearchForGameMode2v2_NotFound() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.gameMode = GameMode.GM_1v1; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); var matches = await matchRepository.Load(GateWay.Undefined, GameMode.GM_2v2_AT); Assert.AreEqual(0, matches.Count); }
public async Task Upsert() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent = TestDtoHelper.CreateFakeEvent(); await matchRepository.Insert(Matchup.Create(matchFinishedEvent)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent)); var matches = await matchRepository.Load(); Assert.AreEqual(1, matches.Count); }
public async Task LoadDetails_NotDetailsAvailable() { var matchFinishedEvent = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent.match.id = "nmhcCLaRc7"; matchFinishedEvent.Id = ObjectId.GenerateNewId(); var matchRepository = new MatchRepository(MongoClient); await matchRepository.Insert(Matchup.Create(matchFinishedEvent)); var result = await matchRepository.LoadDetails(matchFinishedEvent.Id); Assert.AreEqual("nmhcCLaRc7", result.Match.MatchId); }
public async Task LoadAndSave() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.Load(); Assert.AreEqual(2, matches.Count); }
public async Task SearchForPlayerAndOpponent_FilterBySeason_NoResults(int season) { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = season ^ 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "ANDERER#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); var matches = await matchRepository.LoadFor("peter#123", null, season : season); var count = await matchRepository.CountFor("peter#123", null, season : season); Assert.AreEqual(0, count); }
public async Task LoadAndSearch_InvalidString() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[1].battleTag = "peter#123"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("asd#123"); Assert.AreEqual(0, matches.Count); }
public void MapMatch_MMr() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); fakeEvent.match.players[0].won = true; fakeEvent.match.players[0].mmr.rating = 1437.0358093886573; fakeEvent.match.players[0].updatedMmr.rating = 1453.5974731933813; fakeEvent.match.players[1].won = false; fakeEvent.match.players[1].mmr.rating = 1453.5974731933813; fakeEvent.match.players[1].updatedMmr.rating = 1437.0358093886573; var matchup = Matchup.Create(fakeEvent); Assert.AreEqual(16, matchup.Teams[0].Players[0].MmrGain); Assert.AreEqual(1453, matchup.Teams[0].Players[0].CurrentMmr); Assert.AreEqual(1437, matchup.Teams[0].Players[0].OldMmr); Assert.AreEqual(-16, matchup.Teams[1].Players[0].MmrGain); Assert.AreEqual(1437, matchup.Teams[1].Players[0].CurrentMmr); Assert.AreEqual(1453, matchup.Teams[1].Players[0].OldMmr); }
public async Task LoadDetails() { var matchFinishedEvent = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent.match.id = "nmhcCLaRc7"; matchFinishedEvent.Id = ObjectId.GenerateNewId(); matchFinishedEvent.result.players[0].heroes[0].icon = "Archmage"; matchFinishedEvent.result.players[1].heroes[0].icon = "Warden"; await InsertMatchEvent(matchFinishedEvent); var matchRepository = new MatchRepository(MongoClient); await matchRepository.Insert(Matchup.Create(matchFinishedEvent)); var result = await matchRepository.LoadDetails(matchFinishedEvent.Id); Assert.AreEqual("nmhcCLaRc7", result.Match.MatchId); Assert.AreEqual("Archmage", result.PlayerScores[0].Heroes[0].icon); Assert.AreEqual("Warden", result.PlayerScores[1].Heroes[0].icon); }
public void MapMatch_Players() { var fakeEvent = TestDtoHelper.CreateFakeEvent(); var name1 = "peter#123"; var name2 = "wolf#456"; fakeEvent.match.players.First().battleTag = name1; fakeEvent.match.players.First().won = false; fakeEvent.match.players.Last().battleTag = name2; fakeEvent.match.players.Last().won = true; var matchup = Matchup.Create(fakeEvent); Assert.AreEqual("wolf#456", matchup.Teams.First().Players.First().BattleTag); Assert.AreEqual("wolf#456", matchup.Team1Players); Assert.AreEqual("wolf", matchup.Teams.First().Players.First().Name); Assert.AreEqual("peter#123", matchup.Teams.Last().Players.First().BattleTag); Assert.AreEqual("peter#123", matchup.Team2Players); Assert.AreEqual("peter", matchup.Teams.Last().Players.First().Name); }
public async Task ReforgedIconGetsReplaced() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.result.players[0].battleTag = "peter#123"; matchFinishedEvent1.result.players[0].heroes = new List <Hero> { new Hero { icon = "jainasea" } }; await InsertMatchEvent(matchFinishedEvent1); await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); var result = await matchRepository.LoadDetails(matchFinishedEvent1.Id); Assert.AreEqual("archmage", result.PlayerScores[0].Heroes[0].icon); }
public async Task Player_UpdateMmrTimeline() { var playerRepository = new PlayerRepository(MongoClient); var matchRepository = new MatchRepository(MongoClient); await matchRepository.EnsureIndices(); var handler = new PlayerMmrTimelineHandler(playerRepository, matchRepository); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.endTime = 1585701559200; matchFinishedEvent1.match.players[0].race = Race.OC; matchFinishedEvent1.match.players[1].race = Race.NE; matchFinishedEvent2.match.endTime = 1585692047363; matchFinishedEvent2.match.players[0].won = false; matchFinishedEvent2.match.players[0].race = Race.OC; matchFinishedEvent2.match.players[1].won = true; matchFinishedEvent2.match.players[1].race = Race.NE; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var ev = TestDtoHelper.CreateFakeEvent(); ev.match.endTime = 1604612998269; ev.match.players[0].race = Race.OC; ev.match.players[1].race = Race.NE; await handler.Update(ev); var playerMmrTimeline = await playerRepository.LoadPlayerMmrTimeline("peter#123", Race.OC, GateWay.Europe, 0); // Todo: add some more content based asserts for the timeline Assert.IsNotNull(playerMmrTimeline); }
public async Task LoadAndSearch() { var matchRepository = new MatchRepository(MongoClient); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.players[1].battleTag = "KOMISCHER#123"; matchFinishedEvent1.match.players[1].won = true; matchFinishedEvent1.match.players[0].won = false; matchFinishedEvent1.match.gateway = GateWay.America; matchFinishedEvent1.match.season = 1; matchFinishedEvent2.match.gateway = GateWay.America; matchFinishedEvent2.match.season = 1; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("KOMISCHER#123"); Assert.AreEqual(1, matches.Count); Assert.AreEqual("KOMISCHER#123", matches[0].Teams[0].Players[0].BattleTag); }
private static Matchup CreateDefaultMatchup(Guid?team1 = null, Guid?team2 = null) { var matchup = Matchup.Create(team1 ?? Guid.NewGuid(), team2 ?? Guid.NewGuid()); return(matchup); }