public void SetPersonalInformation(TEntity person) { person.FirstName = DataLists.GetFirstName(); person.LastName = DataLists.GetLastName(); person.BirthDate = DateTime.Now.Date.AddYears(-(RandomUtil.GetRandomInt(15, 16))).AddDays(RandomUtil.GetRandomInt(-365, 365)); person.PersonNationality = DataLists.GetCountry(); }
public override void SetPersonAttributes(Player player) { if (player.MainFunction == Position.Goaly) { player.Positions = new List <int> { PlayerPosition.Goaly }; return; } player.Positions = new List <int>(); var nbrOfPositions = player.MainFunction == Position.Forward ? RandomUtil.GetRandomInt(1, 2) : RandomUtil.GetRandomInt(1, 3); for (var i = 1; i <= nbrOfPositions; i++) { switch (player.MainFunction) { case Position.Defence: SetPlayerPositions(player, typeof(PlayerPosition.DefensivePositions)); break; case Position.Midfield: SetPlayerPositions(player, typeof(PlayerPosition.MidfieldPositions)); break; default: SetPlayerPositions(player, typeof(PlayerPosition.ForwardPositions)); break; } } }
static void Main(string[] args) { var factory = new UserFactory(); var candidates = factory.GetPeople(UserType.CANDIDATE, RandomUtil.GetRandomInt(MIN_CANDIDATES_COUNT, MAX_CANDIDATES_COUNT)); var employees = factory.GetPeople(UserType.EMPLOYEE, RandomUtil.GetRandomInt(max: MAX_EMPLOYEES_COUNT)); var printer = new ConsolePrinter(); foreach (var candidate in candidates) { printer.Display(candidate); } Console.WriteLine(); foreach (var employee in employees) { printer.Display(employee); } var employeeGenerator = new EmployeeReportGenerator(); employeeGenerator.Report(employees); Console.WriteLine(); var candidateReportGenerator = new CandidateReportGenerator(); candidateReportGenerator.Report(candidates); }
public void GetRandomInt_Test() { var r = RandomUtil.GetRandomInt(1, 9999); Assert.True(r >= 1); Assert.True(r <= 99999); }
protected internal override Dictionary <int, int> BuildAssembly() { return(new Dictionary <int, int> { { Position.Goaly, RandomUtil.GetRandomInt(2, 3) }, { Position.Defence, RandomUtil.GetRandomInt(5, 7) }, { Position.Midfield, RandomUtil.GetRandomInt(5, 7) }, { Position.Forward, RandomUtil.GetRandomInt(3, 4) }, }); }
public void GenerateStaff_ReturnsListOfStaffContainingAtLeast6StaffMembers() { var generator = new StaffAssemblyGeneratorStrategy(); var staff = generator.GenerateAssembly(ePerson.Staff, RandomUtil.GetRandomInt(1, 5), RandomUtil.GetRandomInt(1, 5), RandomUtil.GetRandomInt(1, 5)); Assert.IsNotEmpty(staff); Assert.GreaterOrEqual(staff.Count, 6); Assert.AreEqual(1, staff.Count(s => s.MainFunction == SpecificStaffFunction.ManagerFunctions.HeadManager)); Assert.AreEqual(1, staff.Count(s => s.MainFunction == SpecificStaffFunction.ManagerFunctions.AssistentManager)); Assert.AreEqual(1, staff.Count(s => s.MainFunction == SpecificStaffFunction.CoachFunctions.GoalKeepingCoach)); }
public List <TEntity> GenerateAssembly(ePerson personType, int countryRating, int?competitionRation = null, int?teamRating = null) { var totalRating = teamRating != null && competitionRation != null ? countryRating * (int)competitionRation * (int)teamRating : countryRating *RandomUtil.GetRandomInt(2, 5) * RandomUtil.GetRandomInt(2, 5); var assembly = BuildAssembly(); CompleteAssembly(assembly); return(CreateAllPersonsInAssembly(assembly, totalRating, personType)); }
public void GenerateSquad_ReturnsListOfPlayersContainingAtLeast20Players() { var squadGenerator = new SquadAssemblyGeneratorStrategy(); var players = squadGenerator.GenerateAssembly(ePerson.Player, RandomUtil.GetRandomInt(1, 5), RandomUtil.GetRandomInt(1, 5), RandomUtil.GetRandomInt(1, 5)); Assert.IsNotEmpty(players); Assert.GreaterOrEqual(players.Count, 20); Assert.GreaterOrEqual(players.Count(p => p.MainFunction == Position.Goaly), 2); Assert.GreaterOrEqual(players.Count(p => p.MainFunction == Position.Defence), 5); Assert.GreaterOrEqual(players.Count(p => p.MainFunction == Position.Midfield), 5); Assert.GreaterOrEqual(players.Count(p => p.MainFunction == Position.Forward), 3); }
protected internal override void AddPersonToAssembly(Dictionary <int, int> assembly) { var allFunctionsWithoutPersons = assembly.Where(a => a.Value == 0).ToDictionary(a => a.Key); if (allFunctionsWithoutPersons.Any()) { assembly[allFunctionsWithoutPersons.ElementAt(RandomUtil.GetRandomInt(0, allFunctionsWithoutPersons.Count() - 1)).Key] += 1; } else { assembly[assembly.Keys.ElementAt(RandomUtil.GetRandomInt(0, (assembly.Count - 1)))] += 1; } }
public void SetPlayerAttributes_SetsAllPlayerAttributes(int mainPosition) { var player = new Player { MainFunction = mainPosition }; var generatorStrategy = new PlayerGeneratorStrategy(); generatorStrategy.SetPersonAttributes(RandomUtil.GetRandomInt(5, 125), player); Assert.IsNotNull(player.PersonAttributes); Assert.AreEqual(28, player.PersonAttributes.Count); var fields = typeof(AttributeName.GoalyAttributes).GetFields(); foreach (var field in fields) { Assert.IsTrue(player.PersonAttributes.Keys.Contains(field.Name)); } }
protected internal override Dictionary <int, int> BuildAssembly() { return(new Dictionary <int, int> { { SpecificStaffFunction.ManagerFunctions.HeadManager, 1 }, { SpecificStaffFunction.ManagerFunctions.AssistentManager, 1 }, { SpecificStaffFunction.ManagerFunctions.YouthManager, RandomUtil.GetRandomInt(0, 1) }, { SpecificStaffFunction.CoachFunctions.AttackingCoach, RandomUtil.GetRandomInt(0, 1) }, { SpecificStaffFunction.CoachFunctions.DefenceCoach, RandomUtil.GetRandomInt(0, 1) }, { SpecificStaffFunction.CoachFunctions.GoalKeepingCoach, 1 }, { SpecificStaffFunction.CoachFunctions.MentalCoach, RandomUtil.GetRandomInt(0, 1) }, { SpecificStaffFunction.CoachFunctions.PhysicalCoach, RandomUtil.GetRandomInt(0, 1) }, { SpecificStaffFunction.CoachFunctions.TechnicalCoach, RandomUtil.GetRandomInt(0, 1) }, { SpecificStaffFunction.ScoutFunctions.FirstTeamScout, RandomUtil.GetRandomInt(1, 2) }, { SpecificStaffFunction.ScoutFunctions.YouthScout, RandomUtil.GetRandomInt(0, 2) }, }); }
public static Dictionary <string, int> AddPlayerAttributesByPlayerType(Type type, int totalRating, bool mainPosition) { var playerAttributes = new Dictionary <string, int>(); var fields = type.GetFields(); foreach (var field in fields) { var ratingOn100 = ((RandomUtil.GetRandomInt(1, totalRating) / 5) * 4); if (ratingOn100 == 0) { ratingOn100++; } if (mainPosition && ratingOn100 < 40 && field.Name != "InjuryProneness") { ratingOn100 = RandomUtil.GetRandomInt(40, 55); } var ratingOn20 = ratingOn100 / 4 != 0 ? ratingOn100 / 4 : 1; playerAttributes.Add(field.Name, ratingOn20); } return(playerAttributes); }
public void CreatePlayer_ReturnsPlayerWithPositionsAndAttributes(int mainPosition) { var player = PersonStrategyFactory <Player> .CreatePerson(ePerson.Player, RandomUtil.GetRandomInt(5, 25), mainPosition); Assert.IsNotNull(player); Assert.IsNotNull(player.MainFunction); Assert.IsNotEmpty(player.Positions); Assert.GreaterOrEqual(player.Positions.Count, 1); Assert.IsNotEmpty(player.PersonAttributes); Assert.AreEqual(28, player.PersonAttributes.Count); }
public static Country GetCountry() { return(Countries[RandomUtil.GetRandomInt(0, Countries.Count - 1)]); }
private static int GetPlayerPositionValue(FieldInfo[] playerPositions) { var index = RandomUtil.GetRandomInt(0, playerPositions.Length); return((int)playerPositions[index].GetValue(playerPositions[index].Name)); }
protected internal override void SetPersonAttributes(int totalRating, Player player) { player.PersonAttributes = new Dictionary <string, int>(); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.GoalyAttributes), totalRating, player.MainFunction == Position.Goaly)); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.FysicalAttributes), totalRating, RandomUtil.GetRandomBoolWithPossiblityToImproveChances(RandomUtil.GetRandomInt(1, 6)))); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.MentalAttributes), totalRating, RandomUtil.GetRandomBoolWithPossiblityToImproveChances(RandomUtil.GetRandomInt(1, 6)))); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.SetPiecesAttributes), totalRating, RandomUtil.GetRandomBoolWithPossiblityToImproveChances(RandomUtil.GetRandomInt(1, 6)))); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.AttackingAttributes), totalRating, (RandomUtil.GetRandomBoolWithPossiblityToImproveChances(player.MainFunction) && player.MainFunction != Position.Goaly))); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.DefensiveAttributes), totalRating, player.MainFunction == Position.Defence)); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.MidfieldAttribues), totalRating, player.MainFunction == Position.Midfield)); player.PersonAttributes.AddRange(PlayerAttributeGenerator.AddPlayerAttributesByPlayerType(typeof(AttributeName.ForwardAttributes), totalRating, player.MainFunction == Position.Forward)); }
public void CreateAllPlayersInAssembly_ReturnsListOfPlayers() { var squadAssembly = new Dictionary <int, int> { { Position.Goaly, 2 }, { Position.Defence, 3 }, { Position.Midfield, 3 }, { Position.Forward, 2 }, }; var players = AssemblyGeneratorBase <Player> .CreateAllPersonsInAssembly(squadAssembly, RandomUtil.GetRandomInt(5, 125), ePerson.Player); Assert.IsNotEmpty(players); Assert.AreEqual(10, players.Count); foreach (var element in squadAssembly) { Assert.AreEqual(element.Value, players.Count(p => p.MainFunction == element.Key)); } }
protected internal virtual void AddPersonToAssembly(Dictionary <int, int> assembly) { assembly[assembly.Keys.ElementAt(RandomUtil.GetRandomInt(0, (assembly.Count - 1)))] += 1; }
public static string GetFirstName() { return(FirstName[RandomUtil.GetRandomInt(0, FirstName.Count - 1)]); }
public static string GetLastName() { return(Lastname[RandomUtil.GetRandomInt(0, Lastname.Count - 1)]); }
public void CreateAllStaffInAssembly_ReturnsListOfStaff() { var assembly = new Dictionary <int, int> { { SpecificStaffFunction.ManagerFunctions.HeadManager, 1 }, { SpecificStaffFunction.ManagerFunctions.AssistentManager, 1 }, { SpecificStaffFunction.ManagerFunctions.YouthManager, 1 }, { SpecificStaffFunction.CoachFunctions.GoalKeepingCoach, 1 }, { SpecificStaffFunction.CoachFunctions.DefenceCoach, 2 }, { SpecificStaffFunction.CoachFunctions.AttackingCoach, 1 }, { SpecificStaffFunction.CoachFunctions.TechnicalCoach, 2 }, { SpecificStaffFunction.CoachFunctions.MentalCoach, 1 }, { SpecificStaffFunction.CoachFunctions.PhysicalCoach, 2 }, { SpecificStaffFunction.ScoutFunctions.FirstTeamScout, 2 }, { SpecificStaffFunction.ScoutFunctions.YouthScout, 1 }, }; var staff = AssemblyGeneratorBase <Staff> .CreateAllPersonsInAssembly(assembly, RandomUtil.GetRandomInt(5, 125), ePerson.Staff); Assert.IsNotEmpty(staff); Assert.AreEqual(15, staff.Count); foreach (var element in assembly) { Assert.AreEqual(element.Value, staff.Count(p => p.MainFunction == element.Key)); } }