Esempio n. 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finds the town wished to be deleted.
        /// Passes the information to TownsBusiness, using the method "DeleteTownById".
        /// </summary>
        public void DeleteTownById()
        {
            Console.Write("Enter id: ");
            int id = int.Parse(Console.ReadLine());

            if (townsBusiness.GetTownById(id) == null)
            {
                Console.WriteLine($"There is no town with ID = {id} in the table!");
            }
            else
            {
                townsBusiness.DeleteTownById(id);
                Console.WriteLine("Done!");
            }
        }