示例#1
0
        public void GetsAllCoachesFromDatabase()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetsAllCoachesFromDatabaseDB")
                          .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));

                Assert.AreEqual(data.ToList(), business.GetAllCoaches());
            }
        }
示例#2
0
        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);
            }
        }
        /// <summary>
        /// "Calls" method "GetAllCoaches" from CoachesBusiness.
        /// Then it shows all coaches in table Coaches.
        /// </summary>
        public void GetAllCoaches()
        {
            Console.WriteLine("Coaches: ");
            List <Coaches> coaches = coachesBusiness.GetAllCoaches();

            if (coaches.Count == 0)
            {
                Console.WriteLine("There are no coaches in the table!");
            }
            else
            {
                Console.WriteLine("Id" + new string(' ', 4) + "Name" + new string(' ', 25) + "Sport Name");
                Console.WriteLine(new string('-', 56));
                foreach (var coach in coaches)
                {
                    var    sport  = sportsBusiness.GetSportById(coach.SportId);
                    string output = $"{coach.Id}" + new string(' ', 6 - coach.Id.ToString().Length)
                                    + $"{coach.Name}" + new string(' ', 29 - coach.Name.Length)
                                    + $"{sport.Name}" + new string(' ', 21 - sport.Name.Length);
                    Console.WriteLine(output);
                }
                Console.WriteLine(new string('-', 56));
            }
        }