コード例 #1
0
        public async Task DeleteShouldDeleteEntityOfDbSet()
        {
            var options = new DbContextOptionsBuilder <TimeMachineContext>()
                          .UseInMemoryDatabase(databaseName: "Get_Last_Tags_Db")
                          .Options;

            var db = new TimeMachineContext(options);

            var dbRepository = new DbRepository <Tag>(db);

            var tagToDlelete = new Tag();

            await dbRepository.AddAsync(tagToDlelete);

            await dbRepository.AddAsync(new Tag());

            await dbRepository.SaveChangesAsync();

            dbRepository.Delete(tagToDlelete);
            await dbRepository.SaveChangesAsync();

            var entitiesCount = db.Tags.Count();

            Assert.Equal(1, entitiesCount);
        }
コード例 #2
0
        public async Task AddAsyncShouldAddEntityInDb()
        {
            var options = new DbContextOptionsBuilder <TimeMachineContext>()
                          .UseInMemoryDatabase(databaseName: "Save_Tag_Db")
                          .Options;

            var db = new TimeMachineContext(options);

            var dbRepository = new DbRepository <Tag>(db);

            await dbRepository.AddAsync(new Tag());

            await dbRepository.SaveChangesAsync();

            var tagsCount = db.Tags.Count();

            Assert.Equal(1, tagsCount);
        }
コード例 #3
0
        public async Task AllShouldReturnEntitiesCountOfDbSet()
        {
            var options = new DbContextOptionsBuilder <TimeMachineContext>()
                          .UseInMemoryDatabase(databaseName: "Get_All_Tags_Db")
                          .Options;

            var db = new TimeMachineContext(options);

            var dbRepository = new DbRepository <Tag>(db);

            await dbRepository.AddAsync(new Tag());

            await dbRepository.AddAsync(new Tag());

            await dbRepository.AddAsync(new Tag());

            await dbRepository.SaveChangesAsync();

            var tagsCount = dbRepository.All().Count();

            Assert.Equal(3, tagsCount);
        }
コード例 #4
0
        public async Task GetLastShouldReturnLastEntitiesOfDbSet()
        {
            var options = new DbContextOptionsBuilder <TimeMachineContext>()
                          .UseInMemoryDatabase(databaseName: "Get_Last_Tags_Db")
                          .Options;

            var db = new TimeMachineContext(options);

            var dbRepository = new DbRepository <Tag>(db);

            await dbRepository.AddAsync(new Tag());

            await dbRepository.AddAsync(new Tag());

            await dbRepository.AddAsync(new Tag());

            await dbRepository.SaveChangesAsync();

            var lastEntities = dbRepository.GetLast(1);

            var lastEntitiesCount = lastEntities.Count();

            Assert.Equal(1, lastEntitiesCount);
        }
コード例 #5
0
 public DbRepository(TimeMachineContext context)
 {
     this._context = context;
     this.dbSet    = this._context.Set <TEntity>();
 }