public async Task TestGetWithBusinessLayer() { await CreateOrdersDb(); SqLiteBootstrap.Initialize(); await using var connection = new SQLiteConnection(OrdersDbContext.ConnectionString); var repoDbDataLayer = new RepoDbDataLayer(connection); var businessLayer = new BusinessLayer( whereAsync: repoDbDataLayer.WhereAsync, beforeGet: (t, e) => { _customBefore = true; return(Task.FromResult(true)); }, afterGet: (t, result) => { _customAfter = true; return(Task.FromResult(true)); }); WhereAsync whereAsync = businessLayer.WhereAsync; var asyncEnumerable = await whereAsync .GetAsync <OrderRecord>(o => o.Id == _id); var returnValue = await asyncEnumerable.ToListAsync(); Assert.AreEqual(1, returnValue.Count); Assert.IsTrue(_customBefore && _customAfter); }
public static async Task <IAsyncEnumerable <T> > GetAsync <T>(this WhereAsync whereAsync, Expression <Func <T, bool> > predicate) { if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } return((await whereAsync(predicate)).Cast <T>()); }
public async Task TestGet() { //Act WhereAsync whereAsync = _businessLayer.WhereAsync; var people = await whereAsync.GetAsync <Person>(p => true); //Verify get was called _mockGet.Verify(d => d(It.IsAny <Expression <Func <Person, bool> > >()), Times.Once); Assert.IsTrue(_customBefore && _customAfter); //This returns an empty list by default Assert.AreEqual(0, (await people.ToListAsync()).Count); }
public BusinessLayer( SaveAsync saveAsync = null, WhereAsync whereAsync = null, DeleteAsync deleteAsync = null, Deleting deleting = null, Deleted deleted = null, Saving saving = null, Saved saved = null, BeforeGet beforeGet = null, AfterGet afterGet = null ) { _whereAsync = whereAsync; _deleteAsync = deleteAsync; _saveAsync = saveAsync; _deleting = deleting; _deleted = deleted; _saving = saving; _saved = saved; _beforeGet = beforeGet; _afterGet = afterGet; }
public static Expression CreateQueryExpression <T>(this WhereAsync whereAsync, Expression <Func <T, bool> > predicate) { return(predicate); }
public DemoController(WhereAsync whereAsync) { _whereAsync = whereAsync; }