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); }
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); }
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); }
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); }
public DbRepository(TimeMachineContext context) { this._context = context; this.dbSet = this._context.Set <TEntity>(); }