public void TestUpdateCoaches() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "TestUpdateCoachesDB") .Options; var data = new List <Coaches>() { new Coaches { Id = 1, Name = "Coach1" }, new Coaches { Id = 2, Name = "Coach2" }, new Coaches { Id = 3, Name = "Coach3" }, }.AsQueryable(); using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { CoachesBusiness business = new CoachesBusiness(context); data.ToList().ForEach(c => business.AddCoach(c)); Coaches c = business.GetCoachById(2); c.Name = "Coach22"; business.UpdateCoach(c); Assert.AreEqual("Coach22", business.GetCoachById(2).Name); } }
/// <summary> /// After the user has inputed id, the program "Calls" method "GetCoachById" from CoachesBusiness. /// Shows the Coach who has this id. /// </summary> public void GetCoachById() { Console.Write("Enter Coach ID to fetch: "); int id = int.Parse(Console.ReadLine()); var coach = coachesBusiness.GetCoachById(id); var sport = sportsBusiness.GetSportById(coach.SportId); if (coach != null) { PrintCoach(coach, sport); } else { Console.WriteLine($"There is no coach with ID = {id} in the table!"); } }
private string GetClubAndCoachNames(Competitors competitor, string name) { if (name == "club") { string clubName = ""; if (competitor.ClubId != null) { clubName = clubsBusiness.GetClubById(competitor.ClubId).Name; } return(clubName); } else { string coachName = ""; if (competitor.CoachId != null) { coachName = coachesBusiness.GetCoachById(competitor.CoachId).Name; } return(coachName); } }
public void GetCoachById() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "GetCoachByIdDB") .Options; using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { CoachesBusiness business = new CoachesBusiness(context); business.AddCoach(new Coaches { Id = 1, Name = "Coach1" }); business.AddCoach(new Coaches { Id = 2, Name = "Coach2" }); business.AddCoach(new Coaches { Id = 3, Name = "Coach3" }); Coaches c = business.GetCoachById(1); Assert.AreEqual(1, c.Id); } }