public async Task Get_Cooperator_Players_Strategies() { var strategyRepository = new StrategyRepository(connection); var strategyService = new StrategyService(strategyRepository); var simulationRepository = new SimulationRepository(connection); var gameService = new GameService(strategyService, gameSettingsProvider); var populationService = new PopulationService(gameService); //TODO: simplify /\ var simulationServce = new SimulationService(simulationRepository, populationService, strategyService, new SimulationSettingsProvider()); Strategy cooperator = await strategyRepository .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name); var players = new List <Player>(); for (int i = 0; i < 10; i++) { players.Add(new Player() { StrategyId = cooperator.Id }); } players = simulationServce.GetPlayersStrategies(players); bool badPlayers = players.Where(p => p.StrategyId != cooperator.Id).Any(); Assert.IsFalse(badPlayers); }
public async Task Get_Players_Strategies() { var players = new List <Player>(); var strategies = new List <Strategy>(); for (int i = 0; i < 10; i++) { string id = Guid.NewGuid().ToString(); players.Add(new Player() { StrategyId = id }); strategies.Add(GetCoopStrategy(id)); } var simulationRepositoryMock = new Mock <ISimulationRepository>(); var strategyServiceMock = new Mock <IStrategyService>(); var populationServiceMock = new Mock <IPopulationService>(); var settingsProviderMock = new Mock <ISimulationSettingsProvider>(); populationServiceMock.Setup(x => x.IsPopulationConsistent(It.IsAny <Population>())) .Returns(Task.FromResult(true)); strategyServiceMock.Setup(x => x.GetStrategiesById(It.IsAny <List <string> >())) .Returns(strategies); settingsProviderMock.Setup(x => x.GetSimulationSettings()) .Returns(new SimulationSettings() { PoplationsLimit = 10 }); SimulationService simulationService = new SimulationService(simulationRepositoryMock.Object, populationServiceMock.Object, strategyServiceMock.Object, settingsProviderMock.Object); List <Player> newPlayers = simulationService.GetPlayersStrategies(players); strategyServiceMock.Verify(x => x.GetStrategiesById(It.IsAny <List <string> >()), Times.Exactly(1)); //no assert required since Verify throws exception if fails }