public virtual async Task Index_GetsSixTopAlbums() { using var context = CreateContext(); await context.Database.CreateExecutionStrategy().ExecuteAsync( async() => { using (Fixture.BeginTransaction(context)) { var controller = new HomeController(); var albums = TestAlbumDataProvider.GetAlbums(); foreach (var album in albums) { context.Add(album); } context.SaveChanges(); var result = await controller.Index(context); Assert.Equal(6, result.Count); } }); }
private void PopulateData(DbContext context) { var albums = TestAlbumDataProvider.GetAlbums(); foreach (var album in albums) { context.Add(album); } context.SaveChanges(); }
public void IndexShouldReturnTopSellingAlbumsAndSaveThenIntoCache() { MyMvc .Controller <HomeController>() .WithOptions(options => options .For <AppSettings>(settings => settings.CacheDbResults = true)) .WithData(data => data .WithSet <Album>(albums => albums .AddRange(TestAlbumDataProvider.GetAlbums()))) .Calling(c => c.Index( From.Services <MusicStoreContext>(), From.Services <IMemoryCache>())) .ShouldHave() .MemoryCache(cache => cache .ContainingEntryOfType <List <Album> >("topselling")) .AndAlso() .ShouldReturn() .View(view => view .WithModelOfType <List <Album> >() .Passing(albums => Assert.Equal(6, albums.Count))); }
public async Task Index_GetsSixTopAlbums() { using (var context = CreateContext()) { using (Fixture.BeginTransaction(context)) { var controller = new HomeController(); var albums = TestAlbumDataProvider.GetAlbums(); foreach (var album in albums) { context.Add(album); } context.SaveChanges(); var result = await controller.Index(context); Assert.Equal(6, result.Count); } } }