Esempio n. 1
0
        public async Task AllWithNulllId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);
            var service = new GalleryService(new EfDeletableEntityRepository <Pic>(dbContext));

            for (int i = 1; i < 6; i++)
            {
                await service.AddAsync(
                    "http://wwww.test.img" + i,
                    "1");
            }

            int page        = 1;
            int itemPerPage = 3;
            var pics        = service.All <GuestViewModel>(null, itemPerPage, (page - 1) * itemPerPage);
            int count       = 0;

            foreach (var pic in pics)
            {
                count++;
            }

            Assert.Equal(0, count);
        }
 protected async Task ValidSubmit()
 {
     if (Model.Id == 0)
     {
         var result = await _galleryService.AddAsync(Model);
         await SaveAsync();
     }
     else
     {
         var result = await _galleryService.UpdateAsync(Model);
         await SaveAsync();
     }
 }
Esempio n. 3
0
        public async Task GetGalleryCountWithNoexistingName()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);
            var repository = new EfDeletableEntityRepository <Pic>(dbContext);
            var service    = new GalleryService(repository);
            await service.AddAsync(
                "http://www.test.com",
                "1");

            Assert.Equal(0, service.GetGalleryCount("11"));
            dbContext.Database.EnsureDeleted();
        }
Esempio n. 4
0
        public async Task AddAsyncWithValidlId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);
            var service = new GalleryService(new EfDeletableEntityRepository <Pic>(dbContext));
            await service.AddAsync(
                "http://wwww.test.img",
                "1");

            var pic = await dbContext.Pics.FirstOrDefaultAsync();

            Assert.Equal("http://wwww.test.img", pic.Url);
            Assert.Equal("1", pic.GamingHallId);
            dbContext.Database.EnsureDeleted();
        }
Esempio n. 5
0
        public async Task DeleteAsyncWithValidId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);
            var service = new GalleryService(new EfDeletableEntityRepository <Pic>(dbContext));
            await service.AddAsync(
                "http://www.test.com",
                "1");

            var pic = await dbContext.Pics.FirstOrDefaultAsync();

            await service.DeleteAsync(pic.Id);

            var result = await dbContext.Pics.Where(x => x.Id == pic.Id).FirstOrDefaultAsync();

            Assert.True(result == null);
            dbContext.Database.EnsureDeleted();
        }