public void AddEntityCreatesEntityInDb() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <CashAccount> repo = new BaseDataService <CashAccount>(db); repo.Add(Cashact); var collection = db.ChangeTracker.Entries(); Assert.Contains(collection, x => x.Entity.GetType() == typeof(CashAccount)); db.SaveChanges(); } }
public void GetByReturnEntityBasedOnPredicate() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <CashAccount> repo = new BaseDataService <CashAccount>(db); repo.Add(Cashact); db.SaveChanges(); var condition = new QueryCondition <CashAccount>(); condition.QueryPredicates.Add(c => c.IsActivated); var result = repo.GetBy(condition); Assert.NotNull(result); Assert.IsType <CashAccount>(result); } }
public void UpdateEntityChangesEntityStateToModified() { using (var db = new ItsomContext(CtxOpt)) { db.Database.EnsureCreated(); IDataService <CashAccount> repo = new BaseDataService <CashAccount>(db); repo.Add(Cashact); db.SaveChanges(); var acct = db.CashAccounts.First(); acct.AccountBalance = 10m; repo.Update(acct); var collection = db.ChangeTracker.Entries(); Assert.Contains(collection, x => x.Entity.GetType() == typeof(CashAccount)); var one = collection.Where(c => c.State == EntityState.Modified).SingleOrDefault(); Assert.NotNull(one); //Assert.Equal(acct.AccountBalance, 10m); } }