Example #1
0
        public void TestUpdateCompetitors()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "TestUpdateCompetitorsDB")
                          .Options;

            var data = new List <Competitors>()
            {
                new Competitors {
                    Id = 1, FullName = "Competitor1"
                },
                new Competitors {
                    Id = 2, FullName = "Competitor2"
                },
                new Competitors {
                    Id = 3, FullName = "Competitor3"
                },
            }.AsQueryable();

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

                Competitors c = business.GetCompetitorById(2); c.FullName = "Competitor22";
                business.UpdateCompetitor(c);

                Assert.AreEqual("Competitor22", business.GetCompetitorById(2).FullName);
            }
        }
Example #2
0
        /// <summary>
        /// Finds the competitor wished to be updated.
        /// "Calls" method "CreateCompetitor".
        /// Then passes it to CompetitorsBusiness, using the method "UpdateCompetitor".
        /// </summary>
        public void UpdateCompetitor()
        {
            Console.Write("Enter ID to update: ");
            int         id         = int.Parse(Console.ReadLine());
            Competitors competitor = competitorsBusiness.GetCompetitorById(id);

            if (competitor == null)
            {
                Console.WriteLine($"There is no competitor with ID = {id} in the table!");
            }
            else
            {
                //competitor = ;
                competitorsBusiness.UpdateCompetitor(CreateCompetitor(competitor));

                Console.WriteLine("Competitor successfully updated!");
            }
        }