Example #1
0
        public void DeleteCompetitor()
        {
            var data = new List <Competitors>()
            {
                new Competitors {
                    Id = 1, FullName = "Competitor1"
                },
                new Competitors {
                    Id = 2, FullName = "Competitor2"
                },
                new Competitors {
                    Id = 3, FullName = "Competitor3"
                },
            }.AsQueryable();
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteCompetitorDB")
                          .Options;

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

                business.DeleteCompetitorById(2);

                Assert.AreEqual(2, business.GetAllCompetitors().Count);
            }
        }
Example #2
0
        public void GetCompetitorByName()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetCompetitorByNameDB")
                          .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.GetCompetitorByName("Competitor1");
                Assert.AreEqual("Competitor1", c.FullName);
            }
        }
Example #3
0
        /// <summary>
        /// "Calls" method "CreateCompetitor".
        /// Passes the information to CompetitorsBusiness, using the method "AddCompetitors"
        /// </summary>
        public void AddCompetitor()
        {
            Competitors competitors = new Competitors();

            competitorsBusiness.AddCompetitors(CreateCompetitor(competitors));

            Console.WriteLine($"New competitor successfully added!");
        }
Example #4
0
        public void GetCompetitorById()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetCompetitorByIdDB")
                          .Options;

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                CompetitorsBusiness business = new CompetitorsBusiness(context);
                business.AddCompetitors(new Competitors {
                    Id = 1, FullName = "Competitor1"
                });
                business.AddCompetitors(new Competitors {
                    Id = 2, FullName = "Competitor2"
                });
                business.AddCompetitors(new Competitors {
                    Id = 3, FullName = "Competitor3"
                });

                Competitors c = business.GetCompetitorById(1);
                Assert.AreEqual(1, c.Id);
            }
        }