Ejemplo n.º 1
0
        public void ShouldGetAllMembers()
        {
            var members = new List <Member>
            {
                new Member
                {
                    Id           = 1,
                    FirstName    = "Ronaldinho",
                    LastName     = "Gaucho",
                    MemberSports = new List <MemberSport>
                    {
                        new MemberSport
                        {
                            MemberId = 1,
                            SportId  = 1
                        }
                    }
                },
                new Member
                {
                    Id           = 2,
                    FirstName    = "Ronaldinho",
                    LastName     = "Gaucho",
                    MemberSports = new List <MemberSport>
                    {
                        new MemberSport
                        {
                            MemberId = 1,
                            SportId  = 1
                        }
                    }
                }
            };
            var options = new DbContextOptionsBuilder <ASMembershipContext>()
                          .UseInMemoryDatabase("ShouldGetAllMembers")
                          .Options;

            using (var context = new ASMembershipContext(options))
            {
                context.Sports.AddRange(GetTestSports());
                context.SaveChanges();
                var memberRepository = new MemberRepository(context);
                foreach (var member in members)
                {
                    memberRepository.Add(member);
                }
            }

            using (var context = new ASMembershipContext(options))
            {
                var memberRepository = new MemberRepository(context);

                var result = memberRepository.GetAll();

                Assert.Equal(2, result.Count);
            }
        }
Ejemplo n.º 2
0
        private static void EnsureDatabaseExists()
        {
            var options = new DbContextOptionsBuilder <ASMembershipContext>()
                          .UseInMemoryDatabase("ASMembershipSystem")
                          .Options;
            var context = new ASMembershipContext(options);

            context.Database.EnsureCreated();
        }
Ejemplo n.º 3
0
        public void ShouldUpdateMember()
        {
            var member = new Member
            {
                Id           = 1,
                FirstName    = "Ronaldinho",
                LastName     = "Gaucho",
                MemberSports = new List <MemberSport>
                {
                    new MemberSport
                    {
                        MemberId = 1,
                        SportId  = 1
                    }
                }
            };

            var options = new DbContextOptionsBuilder <ASMembershipContext>()
                          .UseInMemoryDatabase("ShouldUpdateMember")
                          .Options;

            using (var context = new ASMembershipContext(options))
            {
                context.Sports.AddRange(GetTestSports());
                context.SaveChanges();
                var memberRepository = new MemberRepository(context);
                memberRepository.Add(member);
            }

            using (var context = new ASMembershipContext(options))
            {
                var memberRepository = new MemberRepository(context);
                member.FirstName = "Mo";
                member.LastName  = "Salah";
                member.MemberSports.First().SportId = 2;

                memberRepository.Update(member);
                var result = memberRepository.GetById(member.Id);

                Assert.Equal("Mo", result.FirstName);
                Assert.Equal("Salah", result.LastName);
                Assert.Equal("Tennis", result.MemberSports.First().Sport.Name);
            }
        }
Ejemplo n.º 4
0
        public void ShouldGetAllSports()
        {
            var options = new DbContextOptionsBuilder <ASMembershipContext>()
                          .UseInMemoryDatabase("ShouldGetAllSports")
                          .Options;

            var sports = GetTestSports();

            using (var context = new ASMembershipContext(options))
            {
                context.Sports.AddRange(sports);
                context.SaveChanges();
            }

            using (var context = new ASMembershipContext(options))
            {
                var sportRepository = new SportRepository(context);
                var result          = sportRepository.GetAll();

                Assert.Equal(sports.Count, result.Count);
            }
        }
Ejemplo n.º 5
0
 public MemberRepository(ASMembershipContext context)
 {
     _context = context;
 }