Exemplo n.º 1
0
        public void CanInsertAuthorIntoDb()
        {
            using var context = new ApplicationDbContextMock();

            var author = new Author {
                Name = "Peter F. Hamilton"
            };

            context.Authors.Add(author);

            context.SaveChanges();

            author.Id.ShouldNotBe(0);
        }
Exemplo n.º 2
0
        public void CanInsertAuthorIntoDb()
        {
            var builder = new DbContextOptionsBuilder();

            builder.UseInMemoryDatabase("MemDb");
            using var context = new ApplicationDbContextMock(builder.Options);

            var author = new Author {
                Name = "Peter F. Hamilton"
            };

            context.Authors.Add(author);

            context.Entry(author).State.ShouldBe(EntityState.Added);
        }
Exemplo n.º 3
0
 public DatabaseTests()
 {
     using var context = new ApplicationDbContextMock();
     context.Database.EnsureCreated();
 }