예제 #1
0
        public void DeleteTown()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteTownDB")
                          .Options;

            var data = new List <Towns>()
            {
                new Towns {
                    Id = 1, Name = "Town1"
                },
                new Towns {
                    Id = 2, Name = "Town2"
                },
                new Towns {
                    Id = 3, Name = "Town3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                data.ToList().ForEach(town => business.AddTown(town));

                business.DeleteTownById(2);

                Assert.AreEqual(2, business.GetAllTowns().Count);
            }
        }
예제 #2
0
        public void GetTownByName()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetTownByNameDB")
                          .Options;

            var data = new List <Towns>()
            {
                new Towns {
                    Id = 1, Name = "Town1"
                },
                new Towns {
                    Id = 2, Name = "Town2"
                },
                new Towns {
                    Id = 3, Name = "Town3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                data.ToList().ForEach(t => business.AddTown(t));

                Towns t = business.GetTownByName("Town1");
                Assert.AreEqual("Town1", t.Name);
            }
        }
예제 #3
0
        public void GetsAllTownsFromDatabase()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetsAllCompetitorsFromDatabaseDB")
                          .Options;

            var data = new List <Towns>()
            {
                new Towns {
                    Id = 1, Name = "Town1"
                },
                new Towns {
                    Id = 2, Name = "Town2"
                },
                new Towns {
                    Id = 3, Name = "Town3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                data.ToList().ForEach(c => business.AddTown(c));

                Assert.AreEqual(data.ToList(), business.GetAllTowns());
            }
        }
예제 #4
0
        public void TestUpdateTowns()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "TestUpdateTownsDB")
                          .Options;

            var data = new List <Towns>()
            {
                new Towns {
                    Id = 1, Name = "Town1"
                },
                new Towns {
                    Id = 2, Name = "Town2"
                },
                new Towns {
                    Id = 3, Name = "Town3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                data.ToList().ForEach(c => business.AddTown(c));

                Towns c = business.GetTownById(2); c.Name = "Town22";
                business.UpdateTown(c);

                Assert.AreEqual("Town22", business.GetTownById(2).Name);
            }
        }
예제 #5
0
        public void GetTownById()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetTownByIdDB")
                          .Options;

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                business.AddTown(new Towns {
                    Id = 1, Name = "Town1"
                });
                business.AddTown(new Towns {
                    Id = 2, Name = "Town2"
                });
                business.AddTown(new Towns {
                    Id = 3, Name = "Town3"
                });

                Towns c = business.GetTownById(1);
                Assert.AreEqual(1, c.Id);
            }
        }
예제 #6
0
        /// <summary>
        /// Makes the user to input data about the town.
        /// Passes the information to TownsBusiness, using the method "AddTown"
        /// </summary>
        public void AddTown()
        {
            Towns town = new Towns();

            Console.Write("Enter name: ");
            town.Name = Console.ReadLine();
            Console.Write("Enter Country Name: ");
            string countryName = Console.ReadLine();

            town.CountryId = countriesBusiness.GetCountryByName(countryName).Id;
            townsBusiness.AddTown(town);

            Console.WriteLine($"New town successfully added!");
        }