Пример #1
0
        public void GetsAllSportsFromDatabase()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetsAllSportsFromDatabaseDB")
                          .Options;

            var data = new List <Sports>()
            {
                new Sports {
                    Id = 1, Name = "Sport1"
                },
                new Sports {
                    Id = 2, Name = "Sport2"
                },
                new Sports {
                    Id = 3, Name = "Sport3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                SportsBusiness business = new SportsBusiness(context);
                data.ToList().ForEach(t => context.Sports.Add(t));
                context.SaveChanges();

                Assert.AreEqual(data.ToList(), business.GetAllSports());
            }
        }
Пример #2
0
        /// <summary>
        /// "Calls" method "GetAllSports" from SportsBusiness.
        /// Then it shows all sports in table Sports.
        /// </summary>
        public void GetAllSports()
        {
            Console.WriteLine("Sports: ");
            List <Sports> sports = sportsBusiness.GetAllSports();

            if (sports.Count == 0)
            {
                Console.WriteLine("There are no sports in the table!");
            }
            else
            {
                Console.WriteLine("Id" + new string(' ', 6) + "Name");
                Console.WriteLine(new string('-', 27));

                foreach (var sport in sports)
                {
                    string output = $"{sport.Id}" + new string(' ', 6 - sport.Id.ToString().Length)
                                    + $"{sport.Name}" + new string(' ', 21 - sport.Name.Length);
                    Console.WriteLine(output);
                }

                Console.WriteLine(new string('-', 27));
            }
        }