public async Task KickOff_ReturnsMatch() { var mockMatchmakingService = new Mock <IMatchmakingService>(); var sessionId = Guid.NewGuid(); var session = new MatchmakingSession { Id = sessionId, HostPlayerId = Guid.NewGuid(), JoinedPlayerId = Guid.NewGuid() }; mockMatchmakingService.Setup(x => x.GetSession(sessionId)).Returns(session); var stubMatchEngine = new Mock <IMatchEngine>(); stubMatchEngine.Setup(x => x.SimulateReentrant(It.IsAny <ApplicationCore.Models.Match>())) .Returns(new ApplicationCore.Models.Match()); ApplicationCore.Models.Match simulatedMatch = null; var mockBus = new Mock <IBus>(); var squadResponse = new GetSquadResponse { Lineup = new Dictionary <string, Card>() }; mockBus.Setup(x => x.RequestAsync <GetSquadRequest, GetSquadResponse>(It.IsAny <GetSquadRequest>())) .Returns(Task.FromResult(squadResponse)); var mockMatchRepository = new Mock <IMatchRepository>(); mockMatchRepository.Setup(x => x.CreateAsync(It.IsAny <ApplicationCore.Models.Match>())) .Callback <ApplicationCore.Models.Match>(r => simulatedMatch = r); _matchService = new MatchService(mockMatchmakingService.Object, stubMatchEngine.Object, mockMatchRepository.Object, mockBus.Object); //Act await _matchService.KickOff(sessionId); //Assert Assert.NotNull(simulatedMatch); }
private Squad BuildSquad(GetSquadResponse squadResp) { var gk = squadResp.Lineup.Where(x => x.Key == "GK").Select(x => x.Value).ToList(); var def = squadResp.Lineup.Where(x => (new [] { "LB", "LCB", "RCB", "RB" }).Contains(x.Key)).Select(x => x.Value).ToList(); var mid = squadResp.Lineup.Where(x => (new [] { "LM", "LCM", "RCM", "RM" }).Contains(x.Key)).Select(x => x.Value).ToList(); var att = squadResp.Lineup.Where(x => (new [] { "LST", "RST" }).Contains(x.Key)).Select(x => x.Value).ToList(); return(new Squad() { Id = squadResp.Id, Name = squadResp.Name, Lineup = new Dictionary <string, IEnumerable <Card> >() { { "GK", gk }, { "DEF", def }, { "MID", mid }, { "ATT", att } }, Subs = squadResp.Subs }); }