public void DeleteCoach() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "DeleteCoachDB") .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(); //да не забравяш options using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { CoachesBusiness business = new CoachesBusiness(context); data.ToList().ForEach(c => business.AddCoach(c)); business.DeleteCoachById(2); Assert.AreEqual(2, business.GetAllCoaches().Count); } }
public void GetCoachByName() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "GetCoachByNameDB") .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.GetCoachByName("Coach1"); Assert.AreEqual("Coach1", c.Name); } }
public void TestAddCoach() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "TestAddCoachDB") .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(t => business.AddCoach(t)); Assert.AreEqual(data.ToList(), business.GetAllCoaches()); } }
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); } }
/// <summary> /// Makes the user to input data about the coach. /// Passes the information to CoachesBusinessiness, using the method "AddCoach" /// </summary> public void AddCoach() { var coach = new Coaches(); Console.Write("Enter Coach Name: "); coach.Name = Console.ReadLine(); Console.Write("Enter Sport Name: "); string sportName = Console.ReadLine(); coach.SportId = sportsBusiness.GetSportByName(sportName).Id; coachesBusiness.AddCoach(coach); Console.WriteLine($"New coach successfully added!"); }