コード例 #1
0
        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);
                }
            });
        }
コード例 #2
0
        private void PopulateData(DbContext context)
        {
            var albums = TestAlbumDataProvider.GetAlbums();

            foreach (var album in albums)
            {
                context.Add(album);
            }

            context.SaveChanges();
        }
コード例 #3
0
 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)));
 }
コード例 #4
0
        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);
                }
            }
        }