示例#1
0
        public void DbGetTest()
        {
            var options = new DbContextOptionsBuilder <InvitationsDbContext>()
                          .UseInMemoryDatabase(databaseName: "DbGetTestDatabase")
                          .Options;

            using (var context = new InvitationsDbContext(options))
            {
                context.Invitations.Add(new Invitation {
                    Phone = "79998887766", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887765", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887764", Author = 4
                });
                context.SaveChanges();
            }

            using (var context = new InvitationsDbContext(options))
            {
                var        invitationRepository = new InvitationRepository(context);
                Invitation invitation           = invitationRepository.Get(1);

                Assert.NotNull(invitation);
            }
        }
示例#2
0
        public void DbAddTest()
        {
            var options = new DbContextOptionsBuilder <InvitationsDbContext>()
                          .UseInMemoryDatabase(databaseName: "DbAddTestDatabase")
                          .Options;

            using (var context = new InvitationsDbContext(options))
            {
                context.Invitations.Add(new Invitation {
                    Phone = "79998887766", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887765", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887764", Author = 4
                });
                context.SaveChanges();
            }

            using (var context = new InvitationsDbContext(options))
            {
                var invitationRepository = new InvitationRepository(context);

                var invitation = new Invitation {
                    Phone = "78888888888", Author = 4
                };

                Invitation addedInvitation = invitationRepository.Add(invitation);

                Assert.Equal(4, context.Invitations.Count());
            }
        }
示例#3
0
        public void DbGetAllTest()
        {
            var options = new DbContextOptionsBuilder <InvitationsDbContext>()
                          .UseInMemoryDatabase(databaseName: "DbGetAllTestsDatabase")
                          .Options;

            using (var context = new InvitationsDbContext(options))
            {
                context.Invitations.Add(new Invitation {
                    Phone = "79998887766", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887765", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887764", Author = 4
                });
                context.SaveChanges();
            }

            using (var context = new InvitationsDbContext(options))
            {
                var invitationRepository = new InvitationRepository(context);
                List <Invitation> list   = invitationRepository.GetAll();

                Assert.Equal(3, list.Count);
            }
        }