public void getAthletesTest() { var mockAthletes = new List <AthleteDA> { new AthleteDA { AthleteID = 1, AthleteName = "Niall Martin", DateOfBirth = new DateTime(2006, 06, 10), GroupID = 1, GroupName = "Under 10s", AgeGroup = new GroupDA(), IsDeleted = true, Results = new List <ResultDA>() }, new AthleteDA { AthleteID = 2, AthleteName = "Shane O'Rourke", DateOfBirth = new DateTime(2006, 10, 12), GroupID = 1, GroupName = "Under 10s", AgeGroup = new GroupDA(), IsDeleted = false, Results = new List <ResultDA>() }, new AthleteDA { AthleteID = 3, AthleteName = "Sean Collum", DateOfBirth = new DateTime(2004, 08, 21), GroupID = 1, GroupName = "Under 10s", AgeGroup = new GroupDA(), IsDeleted = false, Results = new List <ResultDA>() } }.AsQueryable(); var mockAthleteSet = new Mock <DbSet <AthleteDA> >(); mockAthleteSet.As <IQueryable <AthleteDA> >().Setup(m => m.Provider).Returns(mockAthletes.Provider); mockAthleteSet.As <IQueryable <AthleteDA> >().Setup(m => m.Expression).Returns(mockAthletes.Expression); mockAthleteSet.As <IQueryable <AthleteDA> >().Setup(m => m.ElementType).Returns(mockAthletes.ElementType); mockAthleteSet.As <IQueryable <AthleteDA> >().Setup(m => m.GetEnumerator()).Returns(mockAthletes.GetEnumerator()); var mockContext = new Mock <SportsAppContext>(); mockContext.Setup(c => c.Athletes).Returns(mockAthleteSet.Object); var service = new AthleteService(mockContext.Object); var allAthletes = service.GetAthletes(1, true); Assert.AreEqual(3, allAthletes.Count); var athletesActiveOnly = service.GetAthletes(1, false); Assert.AreEqual(2, athletesActiveOnly.Count); }
public HomeController(ILogger <HomeController> logger) { _logger = logger; _fitnessScore = new FitnessScoreService(); _athletes = new AthleteService(); _homeViewModel = new HomeViewModel(); }
private static string ProcessInitialData(string pdfText, SACServiceContext db) { string[] lines = pdfText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); using (TeamService teamService = new TeamService(db)) using (AthleteService athleteService = new AthleteService(db)) using (AgeRankService ageRankService = new AgeRankService(db)) { foreach (var line in lines) { int bibNumber; string firstName; string lastName; string teamName; string fullName; string ageRank; string[] fields = line.Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries); if (fields.Length < 5) { continue; } if (!Int32.TryParse(fields[0], out bibNumber)) { continue; } firstName = fields[1]; lastName = fields[2]; teamName = fields[3]; ageRank = fields[4]; int teamId = teamService.TeamExists(teamName); if (teamId == -1) { teamId = teamService.AddTeam(teamName).Id; } int ageRankId = ageRankService.AgeRankExists(AgeRankMappings.GetAgeRankNameByCode(ageRank)); if (ageRankId == -1) { ageRankId = ageRankService.AddAgeRank(AgeRankMappings.GetAgeRankNameByCode(ageRank)).Id; } fullName = firstName.Trim() + " " + lastName.Trim(); Athlete athlete; int athleteId = athleteService.AthleteExists(fullName); if (athleteId == -1) { athlete = athleteService.AddAthlete(fullName, bibNumber, ageRankId, teamId); } } } return(""); }
public AthleteServiceTests() { _fixture = new Fixture(); _fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => _fixture.Behaviors.Remove(b)); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _athleteRepository = Substitute.For <IAthleteRepository>(); _userRepository = Substitute.For <IUserRepository>(); _mapper = AutoMapperConfig.Initialize(); _loggerManager = Substitute.For <ILoggerManager>(); _sut = new AthleteService(_athleteRepository, _userRepository, _mapper, _loggerManager); }
public AthletesController(AthleteService athleteService) { _athleteService = athleteService; }
private static string ProcessText(string pdfText, DateTime?raceDate, SACServiceContext db) { string[] lines = pdfText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int currentAgeRankId = -1; using (RaceService raceService = new RaceService(db)) using (AgeRankService ageRankService = new AgeRankService(db)) using (TeamService teamService = new TeamService(db)) using (AthleteService athleteService = new AthleteService(db)) using (RaceResultService raceResultService = new RaceResultService(db)) { int raceId = -1; for (int i = 0; i < lines.Length; i++) { if (i < 2) { continue; } if (string.IsNullOrEmpty(lines[i])) { continue; } if (i == 2) { if ((raceId = raceService.RaceExists(lines[i])) != -1) { return("A Race with this name already exists!"); } raceId = raceService.AddRace(lines[i], raceDate).Id; continue; } if (lines[i].StartsWith("Class.")) { string currentAgeRank = lines[i - 1]; if (currentAgeRank.ToLower().Contains("(cont.)")) { continue; } if ((currentAgeRankId = ageRankService.AgeRankExists(currentAgeRank)) == -1) { currentAgeRankId = ageRankService.AddAgeRank(SAC.Models.AgeRankMappings.GetAgeRankNameByCode(currentAgeRank)).Id; } continue; } string[] result = lines[i].Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries); if (result.Length < 5) { continue; } int test; int position; int bibNumber; string athleteName; string teamName; int points; if (int.TryParse(result[1].Trim(), out test)) { position = Convert.ToInt16(result[0].Replace("º", "").Trim()); bibNumber = Convert.ToInt16(result[1].Trim()); athleteName = result[2]; teamName = result[3]; points = 0; Int32.TryParse(result[4].Trim(), out points); } else { position = Convert.ToInt16(result[0].Replace("º", "").Trim()); bibNumber = Convert.ToInt16(result[2].Trim()); athleteName = result[1]; teamName = result[3]; points = 0; Int32.TryParse(result[4].Trim(), out points); } int athleteId; if ((athleteId = athleteService.AthleteExists(bibNumber)) == -1) { int teamId; if ((teamId = teamService.TeamExists(teamName)) == -1) { teamId = teamService.AddTeam(teamName).Id; } athleteId = athleteService.AddAthlete(athleteName, bibNumber, currentAgeRankId, teamId).Id; } else { Athlete athlete = athleteService.GetAthlete(athleteId); if (athlete.AgeRankId != currentAgeRankId) { athleteService.UpdateAthlete(athleteId, currentAgeRankId); } } if (raceId != -1) { raceResultService.AddRaceResult(position, points, athleteId, currentAgeRankId, raceId); } } } return(string.Empty); }
public AthleteServiceTests() { service = new AthleteService(); service.Initialise(); }
public AthleteController(WorkoutRoutineRepository workoutRoutineRepo, AthleteRepository athleteRepo, AthleteService athleteSvc) { athleteRepository = athleteRepo; workoutRoutineRepository = workoutRoutineRepo; athleteService = athleteSvc; }
public Athlete Get() { AthleteService athleteService = new AthleteService(); return athleteService.Get(); }
public AthleteServiceTests() { mockAthleteRepository = new Mock <IAthleteRepository>(); athleteService = new AthleteService(mockAthleteRepository.Object); }
public UtilitiesController(ApiTokenService apiTokenService, StravaApiService stravaApiService, AthleteService athleteService) { _stravaApiService = stravaApiService; _apiTokenService = apiTokenService; _athleteService = athleteService; }