public async Task Update_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); var existing = await repository.Get(newEntity.ID); existing.Name = _entityNewName; await repository.Update(existing); var updated = await repository.Get(newEntity.ID); Assert.IsNotNull(updated); }
public async Task GetByName_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); var existing = await repository.Get(x => x.Name == _entityDefaultName); Assert.IsNotNull(existing); }
public async Task DeleteByID_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); await repository.Delete(newEntity.ID); var existing = await repository.Get(newEntity.ID); Assert.IsNull(existing); }
public async Task GetOrdered_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var newEntity = await repository.Insert(new Customer() { Name = _entityNewName }); var defaultEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); var ordered = await repository.Get(orderBy : (x => x.OrderBy(c => c.Name))); Assert.IsNotNull(ordered.First(c => c.Name == _entityDefaultName)); }
public async Task GetWithProperties_Entity() { var context = new InMemoryDataContext(); var repository = new EntityFrameworkCoreRepository <Customer, InMemoryDataContext>(context); var productRepository = new EntityFrameworkCoreRepository <Product, InMemoryDataContext>(context); var newProductEntity = await productRepository.Insert(new Product() { Name = _productName }); var newEntity = await repository.Insert(new Customer() { Name = _entityDefaultName }); newEntity.Products.Add(newProductEntity); var updatedEntity = await repository.Update(newEntity); var existing = await repository.Get(includeProperties : "Products"); Assert.IsNotNull(existing); }