示例#1
0
        public async void CanDeleteMovie()
        {
            DbContextOptions <SpoiltContext> options =
                new DbContextOptionsBuilder <SpoiltContext>()
                .UseInMemoryDatabase("CanDeleteMovie")
                .Options;

            using (SpoiltContext context = new SpoiltContext(options))
            {
                Movie movie = new Movie();
                movie.ID    = "i231231";
                movie.Title = "My Movie";

                context.Movies.Add(movie);

                context.SaveChanges();

                context.Movies.Remove(movie);
                await context.SaveChangesAsync();

                var moviesText = await context.Movies.ToListAsync();

                Assert.DoesNotContain(movie, moviesText);
            }
        }
示例#2
0
        public async void CanUpdateMovie()
        {
            DbContextOptions <SpoiltContext> options =
                new DbContextOptionsBuilder <SpoiltContext>()
                .UseInMemoryDatabase("CanUpdateMovie")
                .Options;

            using (SpoiltContext context = new SpoiltContext(options))
            {
                Movie movie = new Movie();
                movie.ID    = "i231231";
                movie.Title = "My Movie";
                context.Movies.Add(movie);

                context.SaveChanges();

                movie.Title = "NO TITLE";

                context.Movies.Update(movie);
                await context.SaveChangesAsync();

                var movieTitle = await context.Movies.FirstOrDefaultAsync(x => x.ID == movie.ID);

                Assert.Equal("NO TITLE", movieTitle.Title);
            }
        }